1 filter.test FilterUnitTestCase::testImageAlignCaption()

Tests the Image caption filter (data-caption).

File

core/modules/filter/tests/filter.test, line 1832
Tests for filter.module.

Class

FilterUnitTestCase
Unit tests for core filters.

Code

function testImageAlignCaption() {
  // Set up dummy filter object.
  $filter = new stdClass();
  $filter->callback = '_filter_image_caption';

  $input = <<<EOF
<img data-caption="Simple caption" src="foo.png" />
<img data-caption="The caption with a &lt;a href=&quot;/foo&quot;&gt; link&lt;/a&gt;.&lt;strong&gt; Bold tag.&lt;/strong&gt;" src="foo.png" />
<img data-caption="The caption with a &lt;div&gt;not allowed tag&lt;/div&gt;." src="foo.png" />
EOF;

  $tests = array(
    $input => array(
      '<figure class="caption caption-img"><img src="foo.png" /><figcaption>Simple caption</figcaption></figure>' => TRUE,
      '<figure class="caption caption-img"><img src="foo.png" /><figcaption>The caption with a <a href="/foo"> link</a>.<strong> Bold tag.</strong></figcaption></figure>' => TRUE,
      '<figure class="caption caption-img"><img src="foo.png" /><figcaption>The caption with a not allowed tag.</figcaption></figure>' => TRUE,
      '<figure class="caption caption-img"><img src="foo.png" /><figcaption>The caption with a <div>not allowed tag</div>.</figcaption></figure>' => FALSE,
      // Ensure the temporarily wrapped body tag is stripped before output.
      '<body>' => FALSE,
    ),
  );
  $this->assertFilteredString($filter, $tests);
}