Security update for Core, with self-updated composer
[yaffs-website] / web / core / tests / Drupal / Tests / Core / Render / RendererBubblingTest.php
index 3e1ee407ecb7d6290731ce94a75936fc7de43223..f55e34832e088ec1e922b3f2289ae7843404b6cc 100644 (file)
@@ -46,7 +46,7 @@ class RendererBubblingTest extends RendererTestBase {
     $element = [
       '#type' => 'container',
       '#cache' => [
-        'keys' => ['simpletest', 'drupal_render', 'children_attached'],
+        'keys' => ['simpletest', 'renderer', 'children_attached'],
       ],
       '#attached' => ['library' => ['test/parent']],
       '#title' => 'Parent',
@@ -68,7 +68,7 @@ class RendererBubblingTest extends RendererTestBase {
 
     // Load the element from cache and verify the presence of the #attached
     // JavaScript.
-    $element = ['#cache' => ['keys' => ['simpletest', 'drupal_render', 'children_attached']]];
+    $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.');
   }
@@ -86,7 +86,7 @@ class RendererBubblingTest extends RendererTestBase {
     $this->cacheFactory->expects($this->atLeastOnce())
       ->method('get')
       ->with($bin)
-      ->willReturnCallback(function($requested_bin) use ($bin, $custom_cache) {
+      ->willReturnCallback(function ($requested_bin) use ($bin, $custom_cache) {
         if ($requested_bin === $bin) {
           return $custom_cache;
         }
@@ -291,6 +291,42 @@ class RendererBubblingTest extends RendererTestBase {
     ];
     $data[] = [$test_element, ['bar', 'foo'], $expected_cache_items];
 
+    // Ensure that bubbleable metadata has been collected from children and set
+    // correctly to the main level of the render array. That ensures that correct
+    // bubbleable metadata exists if render array gets rendered multiple times.
+    $test_element = [
+      '#cache' => [
+        'keys' => ['parent'],
+        'tags' => ['yar', 'har']
+      ],
+      '#markup' => 'parent',
+      'child' => [
+        '#render_children' => TRUE,
+        'subchild' => [
+          '#cache' => [
+            'contexts' => ['foo'],
+            'tags' => ['fiddle', 'dee'],
+          ],
+          '#attached' => [
+            'library' => ['foo/bar']
+          ],
+          '#markup' => '',
+        ]
+      ],
+    ];
+    $expected_cache_items = [
+      'parent:foo' => [
+        '#attached' => ['library' => ['foo/bar']],
+        '#cache' => [
+          'contexts' => ['foo'],
+          'tags' => ['dee', 'fiddle', 'har', 'yar'],
+          'max-age' => Cache::PERMANENT,
+        ],
+        '#markup' => 'parent',
+      ],
+    ];
+    $data[] = [$test_element, ['foo'], $expected_cache_items];
+
     return $data;
   }
 
@@ -315,7 +351,7 @@ class RendererBubblingTest extends RendererTestBase {
           'tags' => ['b'],
         ],
         'grandchild' => [
-          '#access_callback' => function() use (&$current_user_role) {
+          '#access_callback' => function () use (&$current_user_role) {
             // Only role A cannot access this subtree.
             return $current_user_role !== 'A';
           },
@@ -554,17 +590,23 @@ class RendererBubblingTest extends RendererTestBase {
     $data = [];
 
     // Test element without theme.
-    $data[] = [[
-      'foo' => [
-        '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
-      ]]];
+    $data[] = [
+      [
+        'foo' => [
+          '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
+        ],
+      ],
+    ];
 
     // Test element with theme.
-    $data[] = [[
-      '#theme' => 'common_test_render_element',
-      'foo' => [
-        '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
-      ]]];
+    $data[] = [
+      [
+        '#theme' => 'common_test_render_element',
+        'foo' => [
+          '#pre_render' => [__NAMESPACE__ . '\\BubblingTest::bubblingPreRender'],
+        ],
+      ],
+    ];
 
     return $data;
   }