Prepended constants with C_ to avoid reserved words as per https://www.php.net/manual...
[htmlpurifier/darkodev.git] / tests / HTMLPurifier / ChildDef / CustomTest.php
blob0094323d572a5cab1f02d68d9284a7297e506883
1 <?php
3 class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
6 public function setUp()
8 parent::setUp();
11 public function test()
13 $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
15 $this->assertEqual($this->obj->elements, array('a' => true,
16 'b' => true, 'c' => true, 'd' => true));
18 $this->assertResult('', false);
19 $this->assertResult('<a /><a />', false);
21 $this->assertResult('<a /><b /><c /><d /><a /><b />');
22 $this->assertResult('<a /><d>Dob</d><a /><b>foo</b>'.
23 '<a href="moo" /><b>foo</b>');
27 public function testNesting()
29 $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
30 $this->assertEqual($this->obj->elements, array('a' => true,
31 'b' => true, 'c' => true, 'd' => true));
32 $this->assertResult('', false);
33 $this->assertResult('<a /><b /><c /><a /><b /><d />');
34 $this->assertResult('<a /><b /><c /><d />', false);
37 public function testNestedEitherOr()
39 $this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
40 $this->assertEqual($this->obj->elements, array('a' => true,
41 'b' => true, 'c' => true, 'd' => true));
42 $this->assertResult('', false);
43 $this->assertResult('<b /><a /><c /><d />');
44 $this->assertResult('<b /><d /><a /><a />');
45 $this->assertResult('<b /><a />');
46 $this->assertResult('<acd />', false);
49 public function testNestedQuantifier()
51 $this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
52 $this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
53 $this->assertResult('');
54 $this->assertResult('<b /><c />');
55 $this->assertResult('<b /><c /><c /><c />');
56 $this->assertResult('<b /><c /><b /><c />');
57 $this->assertResult('<b /><c /><b />', false);
60 public function testEitherOr()
62 $this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
63 $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
64 $this->assertResult('', false);
65 $this->assertResult('<a />');
66 $this->assertResult('<b />');
67 $this->assertResult('<a /><b />', false);
71 public function testCommafication()
73 $this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
74 $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
75 $this->assertResult('<a /><b />');
76 $this->assertResult('<ab />', false);
80 public function testPcdata()
82 $this->obj = new HTMLPurifier_ChildDef_Custom('#PCDATA,a');
83 $this->assertEqual($this->obj->elements, array('#PCDATA' => true, 'a' => true));
84 $this->assertResult('foo<a />');
85 $this->assertResult('<a />', false);
88 public function testWhitespace()
90 $this->obj = new HTMLPurifier_ChildDef_Custom('a');
91 $this->assertEqual($this->obj->elements, array('a' => true));
92 $this->assertResult('foo<a />', false);
93 $this->assertResult('<a />');
94 $this->assertResult(' <a />');
99 // vim: et sw=4 sts=4