function RendererBubblingTest::testBubblingWithoutPreRender
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testBubblingWithoutPreRender()
- 8.9.x core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testBubblingWithoutPreRender()
- 10 core/tests/Drupal/Tests/Core/Render/RendererBubblingTest.php \Drupal\Tests\Core\Render\RendererBubblingTest::testBubblingWithoutPreRender()
Tests bubbling of assets when NOT using #pre_render callbacks.
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ RendererBubblingTest.php, line 38
Class
- RendererBubblingTest
- @coversDefaultClass \Drupal\Core\Render\Renderer @group Render
Namespace
Drupal\Tests\Core\RenderCode
public function testBubblingWithoutPreRender() : void {
$this->setUpRequest();
$this->setUpMemoryCache();
$this->cacheContextsManager
->expects($this->any())
->method('convertTokensToKeys')
->willReturnArgument(0);
// Create an element with a child and subchild. Each element loads a
// different library using #attached.
$element = [
'#type' => 'container',
'#cache' => [
'keys' => [
'test',
'renderer',
'children_attached',
],
],
'#attached' => [
'library' => [
'test/parent',
],
],
'#title' => 'Parent',
];
$element['child'] = [
'#type' => 'container',
'#attached' => [
'library' => [
'test/child',
],
],
'#title' => 'Child',
];
$element['child']['subchild'] = [
'#attached' => [
'library' => [
'test/subchild',
],
],
'#markup' => 'Subchild',
];
// Render the element and verify the presence of #attached JavaScript.
$this->renderer
->renderRoot($element);
$expected_libraries = [
'test/parent',
'test/child',
'test/subchild',
];
$this->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
// Load the element from cache and verify the presence of the #attached
// JavaScript.
$element = [
'#cache' => [
'keys' => [
'test',
'renderer',
'children_attached',
],
],
];
// Verify that the element was retrieved from the cache.
$this->assertNotEmpty($this->renderer
->renderRoot($element));
$this->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.