function FilterKernelTest::testLineBreakFilterTwigDebug

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

File

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

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',
    ];
    include_once $this->root . '/core/themes/engines/twig/twig.engine';
    $render = (string) twig_render_template('container.html.twig', $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);
    $result = _filter_autop($render);
    // 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);
}

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