RequiredTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. class HTMLPurifier_ChildDef_RequiredTest extends HTMLPurifier_ChildDefHarness
  3. {
  4. function testPrepareString() {
  5. $def = new HTMLPurifier_ChildDef_Required('foobar | bang |gizmo');
  6. $this->assertIdentical($def->elements,
  7. array(
  8. 'foobar' => true
  9. ,'bang' => true
  10. ,'gizmo' => true
  11. ));
  12. }
  13. function testPrepareArray() {
  14. $def = new HTMLPurifier_ChildDef_Required(array('href', 'src'));
  15. $this->assertIdentical($def->elements,
  16. array(
  17. 'href' => true
  18. ,'src' => true
  19. ));
  20. }
  21. function setUp() {
  22. parent::setUp();
  23. $this->obj = new HTMLPurifier_ChildDef_Required('dt | dd');
  24. }
  25. function testEmptyInput() {
  26. $this->assertResult('', false);
  27. }
  28. function testRemoveIllegalTagsAndElements() {
  29. $this->assertResult(
  30. '<dt>Term</dt>Text in an illegal location'.
  31. '<dd>Definition</dd><b>Illegal tag</b>',
  32. '<dt>Term</dt><dd>Definition</dd>');
  33. $this->assertResult('How do you do!', false);
  34. }
  35. function testIgnoreWhitespace() {
  36. // whitespace shouldn't trigger it
  37. $this->assertResult("\n<dd>Definition</dd> ");
  38. }
  39. function testPreserveWhitespaceAfterRemoval() {
  40. $this->assertResult(
  41. '<dd>Definition</dd> <b></b> ',
  42. '<dd>Definition</dd> '
  43. );
  44. }
  45. function testDeleteNodeIfOnlyWhitespace() {
  46. $this->assertResult("\t ", false);
  47. }
  48. function testPCDATAAllowed() {
  49. $this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
  50. $this->assertResult('Out <b>Bold text</b><img />', 'Out <b>Bold text</b>');
  51. }
  52. function testPCDATAAllowedWithEscaping() {
  53. $this->obj = new HTMLPurifier_ChildDef_Required('#PCDATA | b');
  54. $this->config->set('Core.EscapeInvalidChildren', true);
  55. $this->assertResult(
  56. 'Out <b>Bold text</b><img />',
  57. 'Out <b>Bold text</b>&lt;img /&gt;'
  58. );
  59. }
  60. }
  61. // vim: et sw=4 sts=4