CustomTest.php 3.0 KB

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