function FilterCaptionTwigDebugTest::testCaptionFilter
Same name in other branches
- 9 core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php \Drupal\Tests\filter\Kernel\FilterCaptionTwigDebugTest::testCaptionFilter()
- 8.9.x core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php \Drupal\Tests\filter\Kernel\FilterCaptionTwigDebugTest::testCaptionFilter()
- 10 core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php \Drupal\Tests\filter\Kernel\FilterCaptionTwigDebugTest::testCaptionFilter()
Tests the caption filter with Twig debugging on.
File
-
core/
modules/ filter/ tests/ src/ Kernel/ FilterCaptionTwigDebugTest.php, line 38
Class
- FilterCaptionTwigDebugTest
- Tests the caption filter with Twig debugging on.
Namespace
Drupal\Tests\filter\KernelCode
public function testCaptionFilter() : void {
$manager = $this->container
->get('plugin.manager.filter');
$bag = new FilterPluginCollection($manager, []);
$filter = $bag->get('filter_caption');
$renderer = $this->container
->get('renderer');
$test = function ($input) use ($filter, $renderer) {
return $renderer->executeInRenderContext(new RenderContext(), function () use ($input, $filter) {
return $filter->process($input, 'und');
});
};
// No data-caption attribute.
$input = '<img src="llama.jpg" />';
$expected = $input;
$this->assertEquals($expected, $test($input)->getProcessedText());
// Data-caption attribute.
$input = '<img src="llama.jpg" data-caption="Loquacious llama!" />';
$expected = '<img src="llama.jpg">' . "\n" . '<figcaption>Loquacious llama!</figcaption>';
$output = $test($input)->getProcessedText();
$this->assertStringContainsString($expected, $output);
$this->assertStringContainsString("<!-- THEME HOOK: 'filter_caption' -->", $output);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.