class RendererDebugTest

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

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

Hierarchy

Expanded class hierarchy of RendererDebugTest

File

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

Namespace

Drupal\Tests\Core\Render
View source
class RendererDebugTest extends RendererTestBase {
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        $this->rendererConfig['debug'] = TRUE;
        parent::setUp();
    }
    
    /**
     * Test render debug output.
     */
    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());
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RendererDebugTest::setUp protected function Overrides RendererTestBase::setUp
RendererDebugTest::testDebugOutput public function Test render debug output.
RendererTestBase::$cacheContextsManager protected property
RendererTestBase::$cacheFactory protected property
RendererTestBase::$callableResolver protected property The mocked controller resolver.
RendererTestBase::$currentUserRole protected property The simulated &quot;current&quot; user role, for use in tests with cache contexts.
RendererTestBase::$datetimeTime protected property System time service.
RendererTestBase::$elementInfo protected property The mocked element info.
RendererTestBase::$memoryCache protected property
RendererTestBase::$placeholderGenerator protected property The tested placeholder generator. 1
RendererTestBase::$renderCache protected property The tested render cache.
RendererTestBase::$renderer protected property The tested renderer.
RendererTestBase::$rendererConfig protected property The mocked renderer configuration.
RendererTestBase::$requestStack protected property
RendererTestBase::$themeManager protected property The mocked theme manager.
RendererTestBase::assertRenderCacheItem protected function Asserts a render cache item.
RendererTestBase::randomContextValue protected static function Generates a random context value for the placeholder tests.
RendererTestBase::setUpMemoryCache protected function Sets up a memory-based render cache back-end.
RendererTestBase::setUpRequest protected function Sets up a request object on the request stack.
RendererTestBase::setUpUnusedCache protected function Sets up a render cache back-end that is asserted to be never used.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function

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