From 3df2a1668edbd61797c520ee6b4d20c39f3596b8 Mon Sep 17 00:00:00 2001 From: catch <6915-catch@users.noreply.drupalcode.org> Date: Wed, 1 Jan 2025 07:53:27 +0000 Subject: [PATCH] Issue #3477586 by spokje, catch, godotislate, berdir, dww, nicxvan: [random test failure] LayoutBuilderBlocksTest::testBlockPlaceholder failing --- .../src/Plugin/Block/TestCacheBlock.php | 2 +- .../src/Plugin/Block/TestHtmlBlock.php | 4 ++-- .../tests/src/Functional/BlockCacheTest.php | 22 +++++++++---------- .../tests/src/Functional/BlockHtmlTest.php | 4 ++-- .../tests/src/Functional/BlockXssTest.php | 2 +- .../tests/src/Kernel/BlockViewBuilderTest.php | 8 +++---- ...yMetadataConfigOverrideIntegrationTest.php | 2 +- .../Functional/LayoutBuilderBlocksTest.php | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php index da9657a5aa98..37ccefa36b3a 100644 --- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php +++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestCacheBlock.php @@ -21,7 +21,7 @@ class TestCacheBlock extends BlockBase { * {@inheritdoc} */ public function build() { - $content = \Drupal::state()->get('block_test.content'); + $content = \Drupal::keyValue('block_test')->get('content'); $build = []; if (!empty($content)) { diff --git a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestHtmlBlock.php b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestHtmlBlock.php index c5e1c4e444c0..5d1f1fe2c0b3 100644 --- a/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestHtmlBlock.php +++ b/core/modules/block/tests/modules/block_test/src/Plugin/Block/TestHtmlBlock.php @@ -22,8 +22,8 @@ class TestHtmlBlock extends BlockBase { */ public function build() { return [ - '#attributes' => \Drupal::state()->get('block_test.attributes'), - '#children' => \Drupal::state()->get('block_test.content'), + '#attributes' => \Drupal::keyvalue('block_test')->get('attributes'), + '#children' => \Drupal::keyValue('block_test')->get('content'), ]; } diff --git a/core/modules/block/tests/src/Functional/BlockCacheTest.php b/core/modules/block/tests/src/Functional/BlockCacheTest.php index 6cc840d1df9e..9b58c10e3af0 100644 --- a/core/modules/block/tests/src/Functional/BlockCacheTest.php +++ b/core/modules/block/tests/src/Functional/BlockCacheTest.php @@ -85,7 +85,7 @@ public function testCachePerRole(): void { // Enable our test block. Set some content for it to display. $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalLogin($this->normalUser); $this->drupalGet(''); $this->assertSession()->pageTextContains($current_content); @@ -93,7 +93,7 @@ public function testCachePerRole(): void { // Change the content, but the cached copy should still be served. $old_content = $current_content; $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalGet(''); $this->assertSession()->pageTextContains($old_content); @@ -107,7 +107,7 @@ public function testCachePerRole(): void { // Test whether the cached data is served for the correct users. $old_content = $current_content; $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalLogout(); $this->drupalGet(''); // Anonymous user does not see content cached per-role for normal user. @@ -138,14 +138,14 @@ public function testCachePermissions(): void { \Drupal::state()->set('block_test.cache_contexts', []); $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalGet(''); $this->assertSession()->pageTextContains($current_content); $old_content = $current_content; $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); // Block content served from cache. $this->drupalGet('user'); @@ -164,7 +164,7 @@ public function testNoCache(): void { \Drupal::state()->set('block_test.cache_max_age', 0); $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); // If max_age = 0 has no effect, the next request would be cached. $this->drupalGet(''); @@ -172,7 +172,7 @@ public function testNoCache(): void { // A cached copy should not be served. $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalGet(''); // Maximum age of zero prevents blocks from being cached. $this->assertSession()->pageTextContains($current_content); @@ -185,7 +185,7 @@ public function testCachePerUser(): void { \Drupal::state()->set('block_test.cache_contexts', ['user']); $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalLogin($this->normalUser); $this->drupalGet(''); @@ -193,7 +193,7 @@ public function testCachePerUser(): void { $old_content = $current_content; $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); // Block is served from per-user cache. $this->drupalGet(''); @@ -217,14 +217,14 @@ public function testCachePerPage(): void { \Drupal::state()->set('block_test.cache_contexts', ['url']); $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalGet('test-page'); $this->assertSession()->pageTextContains($current_content); $old_content = $current_content; $current_content = $this->randomMachineName(); - \Drupal::state()->set('block_test.content', $current_content); + \Drupal::keyValue('block_test')->set('content', $current_content); $this->drupalGet('user'); $this->assertSession()->statusCodeEquals(200); diff --git a/core/modules/block/tests/src/Functional/BlockHtmlTest.php b/core/modules/block/tests/src/Functional/BlockHtmlTest.php index 67d0d7303a8b..2c2cb85f07c7 100644 --- a/core/modules/block/tests/src/Functional/BlockHtmlTest.php +++ b/core/modules/block/tests/src/Functional/BlockHtmlTest.php @@ -35,8 +35,8 @@ protected function setUp(): void { ])); // Enable the test_html block, to test HTML ID and attributes. - \Drupal::state()->set('block_test.attributes', ['data-custom-attribute' => 'foo']); - \Drupal::state()->set('block_test.content', $this->randomMachineName()); + \Drupal::keyValue('block_test')->set('attributes', ['data-custom-attribute' => 'foo']); + \Drupal::keyValue('block_test')->set('content', $this->randomMachineName()); $this->drupalPlaceBlock('test_html', ['id' => 'test_html_block']); // Enable a menu block, to test more complicated HTML. diff --git a/core/modules/block/tests/src/Functional/BlockXssTest.php b/core/modules/block/tests/src/Functional/BlockXssTest.php index 1548cc4a85dd..1bd50dfa3736 100644 --- a/core/modules/block/tests/src/Functional/BlockXssTest.php +++ b/core/modules/block/tests/src/Functional/BlockXssTest.php @@ -48,7 +48,7 @@ public function testXssInTitle(): void { $this->container->get('module_installer')->install(['block_test']); $this->drupalPlaceBlock('test_xss_title', ['label' => '<script>alert("XSS label");</script>']); - \Drupal::state()->set('block_test.content', $this->randomMachineName()); + \Drupal::keyValue('block_test')->set('content', $this->randomMachineName()); $this->drupalGet(''); // Check that the block title was properly sanitized when rendered. $this->assertSession()->responseNotContains('<script>alert("XSS label");</script>'); diff --git a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php index 6866119b0d8d..8b2d518b12b1 100644 --- a/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php +++ b/core/modules/block/tests/src/Kernel/BlockViewBuilderTest.php @@ -54,7 +54,7 @@ protected function setUp(): void { ->get('entity_type.manager') ->getStorage('block'); - \Drupal::state()->set('block_test.content', 'Llamas > unicorns!'); + \Drupal::keyValue('block_test')->set('content', 'Llamas > unicorns!'); // Create a block with only required values. $this->block = $this->controller->create([ @@ -73,7 +73,7 @@ protected function setUp(): void { * Tests the rendering of blocks. */ public function testBasicRendering(): void { - \Drupal::state()->set('block_test.content', ''); + \Drupal::keyValue('block_test')->set('content', ''); $entity = $this->controller->create([ 'id' => 'test_block1', @@ -136,7 +136,7 @@ public function testBlockViewBuilderCache(): void { 'plugin' => 'test_cache', ]); $this->block->save(); - \Drupal::state()->set('block_test.content', NULL); + \Drupal::keyValue('block_test')->set('content', NULL); // Verify cache handling for an empty block. $this->verifyRenderCacheHandling(); @@ -203,7 +203,7 @@ public function testBlockViewBuilderViewAlter(): void { $this->assertSame('Llamas > unicorns!', trim((string) $this->cssSelect('[foo=bar]')[0])); \Drupal::state()->set('block_test_view_alter_suffix', FALSE); - \Drupal::state()->set('block_test.content', NULL); + \Drupal::keyValue('block_test')->set('content', NULL); Cache::invalidateTags($this->block->getCacheTagsToInvalidate()); // Advanced: cached block, but an alter hook adds a #pre_render callback to diff --git a/core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php b/core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php index bd619cec8372..8b468f319f31 100644 --- a/core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php +++ b/core/modules/config/tests/src/Functional/CacheabilityMetadataConfigOverrideIntegrationTest.php @@ -38,7 +38,7 @@ protected function setUp(): void { // @todo If our block does not contain any content then the cache context // is not bubbling up and the test fails. Remove this line once the cache // contexts are properly set. See https://www.drupal.org/node/2529980. - \Drupal::state()->set('block_test.content', 'Needs to have some content'); + \Drupal::keyValue('block_test')->set('content', 'Needs to have some content'); $this->drupalLogin($this->drupalCreateUser()); } diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php index be7825d46e22..7747317dbbc1 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderBlocksTest.php @@ -212,7 +212,7 @@ public function testBlockPlaceholder(): void { $assert_session->pageTextNotContains($block_content); // Set block content and reload the page. - \Drupal::state()->set('block_test.content', $block_content); + \Drupal::keyValue('block_test')->set('content', $block_content); $this->getSession()->reload(); // The block placeholder is no longer displayed and the content is visible. -- GitLab