TargetNoopenerTest.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. class HTMLPurifier_HTMLModule_TargetNoopenerTest extends HTMLPurifier_HTMLModuleHarness
  3. {
  4. public function setUp()
  5. {
  6. parent::setUp();
  7. $this->config->set('HTML.TargetNoreferrer', false);
  8. $this->config->set('HTML.TargetNoopener', true);
  9. $this->config->set('Attr.AllowedFrameTargets', '_blank');
  10. }
  11. public function testNoreferrer()
  12. {
  13. $this->assertResult(
  14. '<a href="http://google.com" target="_blank">x</a>',
  15. '<a href="http://google.com" target="_blank" rel="noopener">x</a>'
  16. );
  17. }
  18. public function testNoreferrerNoDupe()
  19. {
  20. $this->config->set('Attr.AllowedRel', 'noopener');
  21. $this->assertResult(
  22. '<a href="http://google.com" target="_blank" rel="noopener">x</a>',
  23. '<a href="http://google.com" target="_blank" rel="noopener">x</a>'
  24. );
  25. }
  26. public function testTargetBlankNoreferrer()
  27. {
  28. $this->config->set('HTML.TargetBlank', true);
  29. $this->assertResult(
  30. '<a href="http://google.com">x</a>',
  31. '<a href="http://google.com" target="_blank" rel="noopener">x</a>'
  32. );
  33. }
  34. public function testNoTarget()
  35. {
  36. $this->assertResult(
  37. '<a href="http://google.com">x</a>',
  38. '<a href="http://google.com">x</a>'
  39. );
  40. }
  41. }
  42. // vim: et sw=4 sts=4