function FilterKernelTest::testLineBreakFilterTwigDebug

Same name and namespace in other branches
  1. 10 core/modules/filter/tests/src/Kernel/FilterKernelTest.php \Drupal\Tests\filter\Kernel\FilterKernelTest::testLineBreakFilterTwigDebug()
  2. main core/modules/filter/tests/src/Kernel/FilterKernelTest.php \Drupal\Tests\filter\Kernel\FilterKernelTest::testLineBreakFilterTwigDebug()

Tests that the line break filter does not apply to twig debug.

File

core/modules/filter/tests/src/Kernel/FilterKernelTest.php, line 513

Class

FilterKernelTest
Tests Filter module filters individually.

Namespace

Drupal\Tests\filter\Kernel

Code

public function testLineBreakFilterTwigDebug() : void {
  // Enable twig theme debug to ensure that any
  // changes to theme debugging format force checking
  // that the auto paragraph filter continues to be applied
  // correctly.
  $twig = \Drupal::service('twig');
  $twig->enableDebug();
  // Manually render a template in its simplest form.
  $variables = [
    'theme_hook_original' => 'container',
    'directory' => '',
    'children' => 'Test two',
  ];
  $render = (string) \Drupal::service(TwigThemeEngine::class)->renderTemplate('container', $variables);
  $render = trim($render);
  // Render text before applying the auto paragraph filter.
  $this->assertSame("<!-- THEME DEBUG -->\n<!-- THEME HOOK: 'container' -->\n<!-- 💡 BEGIN CUSTOM TEMPLATE OUTPUT from 'container.html.twig' -->\n<div>Test two</div>\n\n<!-- END CUSTOM TEMPLATE OUTPUT from 'container.html.twig' -->", $render);
  $plugin = \Drupal::service('plugin.manager.filter')->createInstance('filter_autop');
  assert($plugin instanceof FilterAutoP);
  $result = $plugin->process($render, 'en');
  // After auto-p is applied, the theme debug should no longer have
  // line breaks but the true line breaks should still.
  $this->assertSame("<!-- THEME DEBUG --><!-- THEME HOOK: 'container' --><!-- 💡 BEGIN CUSTOM TEMPLATE OUTPUT from 'container.html.twig' --><div>Test two</div>\n\n<!-- END CUSTOM TEMPLATE OUTPUT from 'container.html.twig' -->", $result->getProcessedText());
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.