diff --git a/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php b/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php deleted file mode 100644 index f5423e7dd7140373f30c36b66b0bb66bd7372f20..0000000000000000000000000000000000000000 --- a/core/modules/filter/tests/src/Functional/FilterCaptionTwigDebugTest.php +++ /dev/null @@ -1,104 +0,0 @@ -<?php - -namespace Drupal\Tests\filter\Functional; - -use Drupal\Core\Render\RenderContext; -use Drupal\Tests\BrowserTestBase; -use Drupal\filter\FilterPluginCollection; - -/** - * Tests the caption filter with Twig debugging on. - * - * @group filter - */ -class FilterCaptionTwigDebugTest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['system', 'filter']; - - /** - * @var \Drupal\filter\Plugin\FilterInterface[] - */ - protected $filters; - - /** - * Enables Twig debugging. - */ - protected function debugOn() { - // Enable debug, rebuild the service container, and clear all caches. - $parameters = $this->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 = '<img src="llama.jpg" />'; - $expected = $input; - $this->assertIdentical($expected, $test($input)->getProcessedText()); - - // Data-caption attribute. - $input = '<img src="llama.jpg" data-caption="Loquacious llama!" />'; - $expected = '<img src="llama.jpg" /><figcaption>Loquacious llama!</figcaption>'; - $output = $test($input); - $output = $output->getProcessedText(); - $this->assertTrue(strpos($output, $expected) !== FALSE, "\"$output\" contains \"$expected\""); - $this->assertTrue(strpos($output, '<!-- THEME HOOK: \'filter_caption\' -->') !== FALSE, 'filter_caption theme hook debug comment is present.'); - } - -} diff --git a/core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php b/core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php new file mode 100644 index 0000000000000000000000000000000000000000..495ba4d0ecae1bde1496dcbcbe5219f926dfcdc3 --- /dev/null +++ b/core/modules/filter/tests/src/Kernel/FilterCaptionTwigDebugTest.php @@ -0,0 +1,62 @@ +<?php + +namespace Drupal\Tests\filter\Kernel; + +use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\Render\RenderContext; +use Drupal\filter\FilterPluginCollection; +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests the caption filter with Twig debugging on. + * + * @group filter + */ +class FilterCaptionTwigDebugTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = ['filter']; + + /** + * {@inheritdoc} + */ + public function register(ContainerBuilder $container) { + parent::register($container); + // Enable Twig debugging. + $parameters = $container->getParameter('twig.config'); + $parameters['debug'] = TRUE; + $container->setParameter('twig.config', $parameters); + } + + /** + * Test the caption filter with Twig debugging on. + */ + public function testCaptionFilter() { + $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" /><figcaption>Loquacious llama!</figcaption>'; + $output = $test($input)->getProcessedText(); + $this->assertContains($expected, $output); + $this->assertContains("<!-- THEME HOOK: 'filter_caption' -->", $output); + } + +}