X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=web%2Fcore%2Fmodules%2Ffilter%2Ftests%2Fsrc%2FFunctional%2FFilterCaptionTwigDebugTest.php;fp=web%2Fcore%2Fmodules%2Ffilter%2Ftests%2Fsrc%2FFunctional%2FFilterCaptionTwigDebugTest.php;h=f5423e7dd7140373f30c36b66b0bb66bd7372f20;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hp=0000000000000000000000000000000000000000;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad;p=yaffs-website diff --git a/web/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php b/web/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php new file mode 100644 index 000000000..f5423e7dd --- /dev/null +++ b/web/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php @@ -0,0 +1,104 @@ +container->getParameter('twig.config'); + if (!$parameters['debug']) { + $parameters['debug'] = TRUE; + $this->setContainerParameter('twig.config', $parameters); + $this->rebuildContainer(); + $this->resetAll(); + } + } + + /** + * Disables Twig debugging. + */ + protected function debugOff() { + // Disable debug, rebuild the service container, and clear all caches. + $parameters = $this->container->getParameter('twig.config'); + if ($parameters['debug']) { + $parameters['debug'] = FALSE; + $this->setContainerParameter('twig.config', $parameters); + $this->rebuildContainer(); + $this->resetAll(); + } + } + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + + $this->debugOn(); + + $manager = $this->container->get('plugin.manager.filter'); + $bag = new FilterPluginCollection($manager, []); + $this->filters = $bag->getAll(); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() { + $this->debugOff(); + } + + /** + * Test the caption filter with Twig debugging on. + */ + public function testCaptionFilter() { + /** @var \Drupal\Core\Render\RendererInterface $renderer */ + $renderer = \Drupal::service('renderer'); + $filter = $this->filters['filter_caption']; + + $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 = ''; + $expected = $input; + $this->assertIdentical($expected, $test($input)->getProcessedText()); + + // Data-caption attribute. + $input = ''; + $expected = '
Loquacious llama!
'; + $output = $test($input); + $output = $output->getProcessedText(); + $this->assertTrue(strpos($output, $expected) !== FALSE, "\"$output\" contains \"$expected\""); + $this->assertTrue(strpos($output, '') !== FALSE, 'filter_caption theme hook debug comment is present.'); + } + +}