function RendererDebugTest::testDebugOutput

Same name in other branches
  1. 9 core/tests/Drupal/Tests/Core/Render/RendererDebugTest.php \Drupal\Tests\Core\Render\RendererDebugTest::testDebugOutput()
  2. 10 core/tests/Drupal/Tests/Core/Render/RendererDebugTest.php \Drupal\Tests\Core\Render\RendererDebugTest::testDebugOutput()

Test render debug output.

File

core/tests/Drupal/Tests/Core/Render/RendererDebugTest.php, line 27

Class

RendererDebugTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render

Namespace

Drupal\Tests\Core\Render

Code

public function testDebugOutput() : void {
    $this->setUpRequest();
    $this->setUpMemoryCache();
    $element = [
        '#cache' => [
            'keys' => [
                'render_cache_test_key',
            ],
            'tags' => [
                'render_cache_test_tag',
                'render_cache_test_tag1',
            ],
            'max-age' => 10,
        ],
        '#markup' => 'Test 1',
    ];
    $markup = $this->renderer
        ->renderRoot($element);
    $expected = <<<EOF
<!-- START RENDERER -->
<!-- CACHE-HIT: No -->
<!-- CACHE TAGS:
   * render_cache_test_tag
   * render_cache_test_tag1
-->
<!-- CACHE CONTEXTS:
   * languages:language_interface
   * theme
-->
<!-- CACHE KEYS:
   * render_cache_test_key
-->
<!-- CACHE MAX-AGE: 10 -->
<!-- PRE-BUBBLING CACHE TAGS:
   * render_cache_test_tag
   * render_cache_test_tag1
-->
<!-- PRE-BUBBLING CACHE CONTEXTS:
   * languages:language_interface
   * theme
-->
<!-- PRE-BUBBLING CACHE KEYS:
   * render_cache_test_key
-->
<!-- PRE-BUBBLING CACHE MAX-AGE: 10 -->
<!-- RENDERING TIME: 0.123456789 -->
Test 1
<!-- END RENDERER -->
EOF;
    $this->assertSame($expected, preg_replace('/RENDERING TIME: \\d{1}.\\d{9}/', 'RENDERING TIME: 0.123456789', $markup->__toString()));
    $element = [
        '#cache' => [
            'keys' => [
                'render_cache_test_key',
            ],
            'tags' => [
                'render_cache_test_tag',
                'render_cache_test_tag1',
            ],
            'max-age' => 10,
        ],
        '#markup' => 'Test 1',
    ];
    $markup = $this->renderer
        ->renderRoot($element);
    $this->assertStringContainsString('CACHE-HIT: Yes', $markup->__toString());
}

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