ImgRequiredTest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class HTMLPurifier_AttrTransform_ImgRequiredTest extends HTMLPurifier_AttrTransformHarness
  3. {
  4. function setUp() {
  5. parent::setUp();
  6. $this->obj = new HTMLPurifier_AttrTransform_ImgRequired();
  7. }
  8. function testAddMissingAttr() {
  9. $this->config->set('Core.RemoveInvalidImg', false);
  10. $this->assertResult(
  11. array(),
  12. array('src' => '', 'alt' => 'Invalid image')
  13. );
  14. }
  15. function testAlternateDefaults() {
  16. $this->config->set('Attr.DefaultInvalidImage', 'blank.png');
  17. $this->config->set('Attr.DefaultInvalidImageAlt', 'Pawned!');
  18. $this->config->set('Attr.DefaultImageAlt', 'not pawned');
  19. $this->config->set('Core.RemoveInvalidImg', false);
  20. $this->assertResult(
  21. array(),
  22. array('src' => 'blank.png', 'alt' => 'Pawned!')
  23. );
  24. }
  25. function testGenerateAlt() {
  26. $this->assertResult(
  27. array('src' => '/path/to/foobar.png'),
  28. array('src' => '/path/to/foobar.png', 'alt' => 'foobar.png')
  29. );
  30. }
  31. function testAddDefaultSrc() {
  32. $this->config->set('Core.RemoveInvalidImg', false);
  33. $this->assertResult(
  34. array('alt' => 'intrigue'),
  35. array('alt' => 'intrigue', 'src' => '')
  36. );
  37. }
  38. function testAddDefaultAlt() {
  39. $this->config->set('Attr.DefaultImageAlt', 'default');
  40. $this->assertResult(
  41. array('src' => ''),
  42. array('src' => '', 'alt' => 'default')
  43. );
  44. }
  45. }
  46. // vim: et sw=4 sts=4