function BubbleableMetadataTest::testMergeAttachmentsPageRegionMergingWithRecursiveRenderArrays
Same name and namespace in other branches
- main core/tests/Drupal/Tests/Core/Render/BubbleableMetadataTest.php \Drupal\Tests\Core\Render\BubbleableMetadataTest::testMergeAttachmentsPageRegionMergingWithRecursiveRenderArrays()
Tests page region attachment merging with recursive render arrays.
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ BubbleableMetadataTest.php, line 495
Class
Namespace
Drupal\Tests\Core\RenderCode
public function testMergeAttachmentsPageRegionMergingWithRecursiveRenderArrays() : void {
$a = [
'library' => [
'core/drupal',
],
];
$b = [
'library' => [
'core/jquery',
],
];
foreach ([
'page_top',
'page_bottom',
] as $page_region) {
$a[$page_region]['node_preview'] = [
'#markup' => 'Preview from a',
];
$a[$page_region]['node_preview']['#attached'][$page_region]['node_preview'] =& $a[$page_region]['node_preview'];
$b[$page_region]['node_preview'] = [
'#markup' => 'Preview from b',
];
$b[$page_region]['node_preview']['#attached'][$page_region]['node_preview'] =& $b[$page_region]['node_preview'];
}
$merged = BubbleableMetadata::mergeAttachments($a, $b);
$this->assertSame([
'core/drupal',
'core/jquery',
], $merged['library']);
$this->assertSame('Preview from b', $merged['page_top']['node_preview']['#markup']);
$this->assertSame('Preview from b', $merged['page_bottom']['node_preview']['#markup']);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.