You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
3.2KB

  1. <?php
  2. class HTMLPurifier_ChildDef_CustomTest extends HTMLPurifier_ChildDefHarness
  3. {
  4. public function setUp()
  5. {
  6. parent::setUp();
  7. }
  8. public function test()
  9. {
  10. $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b?,c*,d+,(a,b)*)');
  11. $this->assertEqual($this->obj->elements, array('a' => true,
  12. 'b' => true, 'c' => true, 'd' => true));
  13. $this->assertResult('', false);
  14. $this->assertResult('<a /><a />', false);
  15. $this->assertResult('<a /><b /><c /><d /><a /><b />');
  16. $this->assertResult('<a /><d>Dob</d><a /><b>foo</b>'.
  17. '<a href="moo" /><b>foo</b>');
  18. }
  19. public function testNesting()
  20. {
  21. $this->obj = new HTMLPurifier_ChildDef_Custom('(a,b,(c|d))+');
  22. $this->assertEqual($this->obj->elements, array('a' => true,
  23. 'b' => true, 'c' => true, 'd' => true));
  24. $this->assertResult('', false);
  25. $this->assertResult('<a /><b /><c /><a /><b /><d />');
  26. $this->assertResult('<a /><b /><c /><d />', false);
  27. }
  28. public function testNestedEitherOr()
  29. {
  30. $this->obj = new HTMLPurifier_ChildDef_Custom('b,(a|(c|d))+');
  31. $this->assertEqual($this->obj->elements, array('a' => true,
  32. 'b' => true, 'c' => true, 'd' => true));
  33. $this->assertResult('', false);
  34. $this->assertResult('<b /><a /><c /><d />');
  35. $this->assertResult('<b /><d /><a /><a />');
  36. $this->assertResult('<b /><a />');
  37. $this->assertResult('<acd />', false);
  38. }
  39. public function testNestedQuantifier()
  40. {
  41. $this->obj = new HTMLPurifier_ChildDef_Custom('(b,c+)*');
  42. $this->assertEqual($this->obj->elements, array('b' => true, 'c' => true));
  43. $this->assertResult('');
  44. $this->assertResult('<b /><c />');
  45. $this->assertResult('<b /><c /><c /><c />');
  46. $this->assertResult('<b /><c /><b /><c />');
  47. $this->assertResult('<b /><c /><b />', false);
  48. }
  49. public function testEitherOr()
  50. {
  51. $this->obj = new HTMLPurifier_ChildDef_Custom('a|b');
  52. $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
  53. $this->assertResult('', false);
  54. $this->assertResult('<a />');
  55. $this->assertResult('<b />');
  56. $this->assertResult('<a /><b />', false);
  57. }
  58. public function testCommafication()
  59. {
  60. $this->obj = new HTMLPurifier_ChildDef_Custom('a,b');
  61. $this->assertEqual($this->obj->elements, array('a' => true, 'b' => true));
  62. $this->assertResult('<a /><b />');
  63. $this->assertResult('<ab />', false);
  64. }
  65. public function testPcdata()
  66. {
  67. $this->obj = new HTMLPurifier_ChildDef_Custom('#PCDATA,a');
  68. $this->assertEqual($this->obj->elements, array('#PCDATA' => true, 'a' => true));
  69. $this->assertResult('foo<a />');
  70. $this->assertResult('<a />', false);
  71. }
  72. public function testWhitespace()
  73. {
  74. $this->obj = new HTMLPurifier_ChildDef_Custom('a');
  75. $this->assertEqual($this->obj->elements, array('a' => true));
  76. $this->assertResult('foo<a />', false);
  77. $this->assertResult('<a />');
  78. $this->assertResult(' <a />');
  79. }
  80. }
  81. // vim: et sw=4 sts=4