選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

134 行
3.5KB

  1. <?php
  2. class HTMLPurifier_Strategy_RemoveForeignElementsTest extends HTMLPurifier_StrategyHarness
  3. {
  4. public function setUp()
  5. {
  6. parent::setUp();
  7. $this->obj = new HTMLPurifier_Strategy_RemoveForeignElements();
  8. }
  9. public function testBlankInput()
  10. {
  11. $this->assertResult('');
  12. }
  13. public function testPreserveRecognizedElements()
  14. {
  15. $this->assertResult('This is <b>bold text</b>.');
  16. }
  17. public function testRemoveForeignElements()
  18. {
  19. $this->assertResult(
  20. '<asdf>Bling</asdf><d href="bang">Bong</d><foobar />',
  21. 'BlingBong'
  22. );
  23. }
  24. public function testRemoveScriptAndContents()
  25. {
  26. $this->assertResult(
  27. '<script>alert();</script>',
  28. ''
  29. );
  30. }
  31. public function testRemoveStyleAndContents()
  32. {
  33. $this->assertResult(
  34. '<style>.foo {blink;}</style>',
  35. ''
  36. );
  37. }
  38. public function testRemoveOnlyScriptTagsLegacy()
  39. {
  40. $this->config->set('Core.RemoveScriptContents', false);
  41. $this->assertResult(
  42. '<script>alert();</script>',
  43. 'alert();'
  44. );
  45. }
  46. public function testRemoveOnlyScriptTags()
  47. {
  48. $this->config->set('Core.HiddenElements', array());
  49. $this->assertResult(
  50. '<script>alert();</script>',
  51. 'alert();'
  52. );
  53. }
  54. public function testRemoveInvalidImg()
  55. {
  56. $this->assertResult('<img />', '');
  57. }
  58. public function testPreserveValidImg()
  59. {
  60. $this->assertResult('<img src="foobar.gif" alt="foobar.gif" />');
  61. }
  62. public function testPreserveInvalidImgWhenRemovalIsDisabled()
  63. {
  64. $this->config->set('Core.RemoveInvalidImg', false);
  65. $this->assertResult('<img />');
  66. }
  67. public function testTextifyCommentedScriptContents()
  68. {
  69. $this->config->set('HTML.Trusted', true);
  70. $this->config->set('Output.CommentScriptContents', false); // simplify output
  71. $this->assertResult(
  72. '<script type="text/javascript"><!--
  73. alert(<b>bold</b>);
  74. // --></script>',
  75. '<script type="text/javascript">
  76. alert(&lt;b&gt;bold&lt;/b&gt;);
  77. // </script>'
  78. );
  79. }
  80. public function testRequiredAttributesTestNotPerformedOnEndTag()
  81. {
  82. $def = $this->config->getHTMLDefinition(true);
  83. $def->addElement('f', 'Block', 'Optional: #PCDATA', false, array('req*' => 'Text'));
  84. $this->assertResult('<f req="text">Foo</f> Bar');
  85. }
  86. public function testPreserveCommentsWithHTMLTrusted()
  87. {
  88. $this->config->set('HTML.Trusted', true);
  89. $this->assertResult('<!-- foo -->');
  90. }
  91. public function testRemoveTrailingHyphensInComment()
  92. {
  93. $this->config->set('HTML.Trusted', true);
  94. $this->assertResult('<!-- foo ----->', '<!-- foo -->');
  95. }
  96. public function testCollapseDoubleHyphensInComment()
  97. {
  98. $this->config->set('HTML.Trusted', true);
  99. $this->assertResult('<!-- bo --- asdf--as -->', '<!-- bo - asdf-as -->');
  100. }
  101. public function testPreserveCommentsWithLookup()
  102. {
  103. $this->config->set('HTML.AllowedComments', array('allowed'));
  104. $this->assertResult('<!-- allowed --><!-- not allowed -->', '<!-- allowed -->');
  105. }
  106. public function testPreserveCommentsWithRegexp()
  107. {
  108. $this->config->set('HTML.AllowedCommentsRegexp', '/^allowed[1-9]$/');
  109. $this->assertResult('<!-- allowed1 --><!-- not allowed -->', '<!-- allowed1 -->');
  110. }
  111. }
  112. // vim: et sw=4 sts=4