3 class HTMLPurifier_ChildDef_CustomTest
extends HTMLPurifier_ChildDefHarness
8 $this->obj
= new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
10 $this->assertEqual($this->obj
->elements
, array('a' => true,
11 'b' => true, 'c' => true, 'd' => true));
13 $this->assertResult('', false);
14 $this->assertResult('<a /><a />', false);
16 $this->assertResult('<a /><b /><c /><d /><a /><b />');
17 $this->assertResult('<a /><d>Dob</d><a /><b>foo</b>'.
18 '<a href="moo" /><b>foo</b>');
22 function testNesting() {
23 $this->obj
= new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
24 $this->assertEqual($this->obj
->elements
, array('a' => true,
25 'b' => true, 'c' => true, 'd' => true));
26 $this->assertResult('', false);
27 $this->assertResult('<a /><b /><c /><a /><b /><d />');
28 $this->assertResult('<a /><b /><c /><d />', false);
31 function testNestedEitherOr() {
32 $this->obj
= new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
33 $this->assertEqual($this->obj
->elements
, array('a' => true,
34 'b' => true, 'c' => true, 'd' => true));
35 $this->assertResult('', false);
36 $this->assertResult('<b /><a /><c /><d />');
37 $this->assertResult('<b /><d /><a /><a />');
38 $this->assertResult('<b /><a />');
39 $this->assertResult('<acd />', false);
42 function testNestedQuantifier() {
43 $this->obj
= new HTMLPurifier_ChildDef_Custom('(b,c+)*');
44 $this->assertEqual($this->obj
->elements
, array('b' => true, 'c' => true));
45 $this->assertResult('');
46 $this->assertResult('<b /><c />');
47 $this->assertResult('<b /><c /><c /><c />');
48 $this->assertResult('<b /><c /><b /><c />');
49 $this->assertResult('<b /><c /><b />', false);
52 function testEitherOr() {
54 $this->obj
= new HTMLPurifier_ChildDef_Custom('a|b');
55 $this->assertEqual($this->obj
->elements
, array('a' => true, 'b' => true));
56 $this->assertResult('', false);
57 $this->assertResult('<a />');
58 $this->assertResult('<b />');
59 $this->assertResult('<a /><b />', false);
63 function testCommafication() {
65 $this->obj
= new HTMLPurifier_ChildDef_Custom('a,b');
66 $this->assertEqual($this->obj
->elements
, array('a' => true, 'b' => true));
67 $this->assertResult('<a /><b />');
68 $this->assertResult('<ab />', false);
72 function testPcdata() {
73 $this->obj
= new HTMLPurifier_ChildDef_Custom('#PCDATA,a');
74 $this->assertEqual($this->obj
->elements
, array('#PCDATA' => true, 'a' => true));
75 $this->assertResult('foo<a />');
76 $this->assertResult('<a />', false);
79 function testWhitespace() {
80 $this->obj
= new HTMLPurifier_ChildDef_Custom('a');
81 $this->assertEqual($this->obj
->elements
, array('a' => true));
82 $this->assertResult('foo<a />', false);
83 $this->assertResult('<a />');
84 $this->assertResult(' <a />');