diff --git a/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/layout_builder_overrides_test.module b/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/layout_builder_overrides_test.module deleted file mode 100644 index 5ba98591c9..0000000000 --- a/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/layout_builder_overrides_test.module +++ /dev/null @@ -1,20 +0,0 @@ -setClass(TestOverridesSectionStorage::class); - $storages['overrides']->set('weight', -100); - - $storages['overrides_heavy'] = clone $storages['overrides']; - $storages['overrides_heavy']->set('weight', -50); -} diff --git a/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/src/Plugin/SectionStorage/TestOverridesSectionStorage.php b/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/src/Plugin/SectionStorage/TestOverridesSectionStorage.php index d1ad54689a..9320b0162f 100644 --- a/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/src/Plugin/SectionStorage/TestOverridesSectionStorage.php +++ b/core/modules/layout_builder/tests/modules/layout_builder_overrides_test/src/Plugin/SectionStorage/TestOverridesSectionStorage.php @@ -2,30 +2,96 @@ namespace Drupal\layout_builder_overrides_test\Plugin\SectionStorage; -use Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage; +use Drupal\Core\Session\AccountInterface; +use Drupal\layout_builder\Plugin\SectionStorage\SectionStorageBase; +use Drupal\layout_builder\Section; +use Drupal\layout_builder\SectionComponent; +use Symfony\Component\Routing\RouteCollection; /** * Provides a test override of section storage. + * + * @SectionStorage( + * id = "layout_builder_overrides_test", + * weight = -100, + * ) */ -class TestOverridesSectionStorage extends OverridesSectionStorage { +class TestOverridesSectionStorage extends SectionStorageBase { /** * {@inheritdoc} */ - protected function getSectionList() { - \Drupal::state()->set('layout_builder_test_storage', [ - static::class, - $this->getPluginDefinition()->get('weight'), - $this->getContextValue('view_mode'), - ]); - return parent::getSectionList(); + public function getSections() { + // Return a custom section. + $section = new Section('layout_onecol'); + $section->appendComponent(new SectionComponent('fake-uuid', 'content', [ + 'id' => 'system_powered_by_block', + 'label' => 'Test block title', + 'label_display' => 'visible', + ])); + return [$section]; } /** * {@inheritdoc} */ public function isApplicable() { - return TRUE; + return \Drupal::state()->get('layout_builder_overrides_test', FALSE); } + /** + * {@inheritdoc} + */ + public function access($operation, AccountInterface $account = NULL, $return_as_object = FALSE) {} + + /** + * {@inheritdoc} + */ + protected function getSectionList() {} + + /** + * {@inheritdoc} + */ + public function getStorageId() {} + + /** + * {@inheritdoc} + */ + public function getSectionListFromId($id) {} + + /** + * {@inheritdoc} + */ + public function buildRoutes(RouteCollection $collection) {} + + /** + * {@inheritdoc} + */ + public function getRedirectUrl() {} + + /** + * {@inheritdoc} + */ + public function getLayoutBuilderUrl($rel = 'view') {} + + /** + * {@inheritdoc} + */ + public function extractIdFromRoute($value, $definition, $name, array $defaults) {} + + /** + * {@inheritdoc} + */ + public function deriveContextsFromRoute($value, $definition, $name, array $defaults) {} + + /** + * {@inheritdoc} + */ + public function label() {} + + /** + * {@inheritdoc} + */ + public function save() {} + } diff --git a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderSectionStorageTest.php b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderSectionStorageTest.php index 3e517c2aee..07f0ea0162 100644 --- a/core/modules/layout_builder/tests/src/Functional/LayoutBuilderSectionStorageTest.php +++ b/core/modules/layout_builder/tests/src/Functional/LayoutBuilderSectionStorageTest.php @@ -2,7 +2,6 @@ namespace Drupal\Tests\layout_builder\Functional; -use Drupal\layout_builder_overrides_test\Plugin\SectionStorage\TestOverridesSectionStorage; use Drupal\Tests\BrowserTestBase; /** @@ -47,33 +46,44 @@ protected function setUp() { /** * Tests that section loading is delegated to plugins during rendering. + * + * @see \Drupal\layout_builder_overrides_test\Plugin\SectionStorage\TestOverridesSectionStorage */ public function testRenderByContextAwarePluginDelegate() { + $assert_session = $this->assertSession(); + $page = $this->getSession()->getPage(); + $this->drupalLogin($this->drupalCreateUser([ 'configure any layout', 'administer node display', ])); - $state_key = 'layout_builder_test_storage'; - /** @var \Drupal\Core\State\StateInterface $state */ - $state = $this->container->get('state'); - + // No blocks exist on the node by default. $this->drupalGet('node/1'); - $this->assertEmpty($state->get($state_key)); + $assert_session->pageTextNotContains('Defaults block title'); + $assert_session->pageTextNotContains('Test block title'); + + // Enable Layout Builder. + $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save'); - $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default'); - $this->drupalPostForm(NULL, ['layout[enabled]' => TRUE], 'Save'); - $this->drupalPostForm(NULL, ['layout[allow_custom]' => TRUE], 'Save'); + // Add a block to the defaults. + $page->clickLink('Manage layout'); + $page->clickLink('Add Block'); + $page->clickLink('Powered by Drupal'); + $page->fillField('settings[label]', 'Defaults block title'); + $page->checkField('settings[label_display]'); + $page->pressButton('Add Block'); + $page->clickLink('Save Layout'); + + $this->drupalGet('node/1'); + $assert_session->pageTextContains('Defaults block title'); + $assert_session->pageTextNotContains('Test block title'); + // Enable the test section storage. + $this->container->get('state')->set('layout_builder_overrides_test', TRUE); $this->drupalGet('node/1'); - // During layout rendering, the storage plugin used for testing will set the - // state key to an array containing the plugin class, weight, and view mode, - // which proves that the plugin matched the appropriate contexts and was - // actually used to render the layout. - list ($class, $weight, $view_mode) = $state->get($state_key); - $this->assertSame(TestOverridesSectionStorage::class, $class); - $this->assertSame(-100, $weight); - $this->assertSame('default', $view_mode); + $assert_session->pageTextNotContains('Defaults block title'); + $assert_session->pageTextContains('Test block title'); } }