public function RendererBubblingTest::testBubblingWithoutPreRender in Drupal 8
Same name and namespace in other branches
- 9 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 36 - Contains \Drupal\Tests\Core\Render\RendererBubblingTest.
Class
- RendererBubblingTest
- @coversDefaultClass \Drupal\Core\Render\Renderer @group Render
Namespace
Drupal\Tests\Core\RenderCode
public function testBubblingWithoutPreRender() {
$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' => [
'simpletest',
'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' => [
'simpletest',
'renderer',
'children_attached',
],
],
];
$this
->assertTrue(strlen($this->renderer
->renderRoot($element)) > 0, 'The element was retrieved from cache.');
$this
->assertEquals($element['#attached']['library'], $expected_libraries, 'The element, child and subchild #attached libraries are included.');
}