+ /**
+ * Tests the interaction between full and default view modes.
+ *
+ * @see \Drupal\layout_builder\Plugin\SectionStorage\OverridesSectionStorage::getDefaultSectionStorage()
+ */
+ public function testLayoutBuilderUiFullViewMode() {
+ $assert_session = $this->assertSession();
+ $page = $this->getSession()->getPage();
+
+ $this->drupalLogin($this->drupalCreateUser([
+ 'configure any layout',
+ 'administer node display',
+ 'administer node fields',
+ ]));
+
+ $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
+ // Allow overrides for the layout.
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enabled]' => TRUE], 'Save');
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save');
+
+ // Customize the default view mode.
+ $this->drupalGet("$field_ui_prefix/display-layout/default");
+ $this->clickLink('Add Block');
+ $this->clickLink('Powered by Drupal');
+ $page->fillField('settings[label]', 'This is the default view mode');
+ $page->checkField('settings[label_display]');
+ $page->pressButton('Add Block');
+ $assert_session->pageTextContains('This is the default view mode');
+ $this->clickLink('Save Layout');
+
+ // The default view mode is used for both the node display and layout UI.
+ $this->drupalGet('node/1');
+ $assert_session->pageTextContains('This is the default view mode');
+ $this->drupalGet('node/1/layout');
+ $assert_session->pageTextContains('This is the default view mode');
+ $this->clickLink('Cancel Layout');
+
+ // Enable the full view mode and customize it.
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['display_modes_custom[full]' => TRUE], 'Save');
+ $this->drupalPostForm("$field_ui_prefix/display/full", ['layout[enabled]' => TRUE], 'Save');
+ $this->drupalGet("$field_ui_prefix/display-layout/full");
+ $this->clickLink('Add Block');
+ $this->clickLink('Powered by Drupal');
+ $page->fillField('settings[label]', 'This is the full view mode');
+ $page->checkField('settings[label_display]');
+ $page->pressButton('Add Block');
+ $assert_session->pageTextContains('This is the full view mode');
+ $this->clickLink('Save Layout');
+
+ // The full view mode is now used for both the node display and layout UI.
+ $this->drupalGet('node/1');
+ $assert_session->pageTextContains('This is the full view mode');
+ $this->drupalGet('node/1/layout');
+ $assert_session->pageTextContains('This is the full view mode');
+ $this->clickLink('Cancel Layout');
+
+ // Disable the full view mode, the default should be used again.
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['display_modes_custom[full]' => FALSE], 'Save');
+ $this->drupalGet('node/1');
+ $assert_session->pageTextContains('This is the default view mode');
+ $this->drupalGet('node/1/layout');
+ $assert_session->pageTextContains('This is the default view mode');
+ $this->clickLink('Cancel Layout');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function testLayoutBuilderChooseBlocksAlter() {
+ // See layout_builder_test_plugin_filter_block__layout_builder_alter().
+ $assert_session = $this->assertSession();
+
+ $this->drupalLogin($this->drupalCreateUser([
+ 'configure any layout',
+ 'administer node display',
+ 'administer node fields',
+ ]));
+
+ // From the manage display page, go to manage the layout.
+ $this->drupalPostForm('admin/structure/types/manage/bundle_with_section_field/display/default', ['layout[enabled]' => TRUE], 'Save');
+ $assert_session->linkExists('Manage layout');
+ $this->clickLink('Manage layout');
+
+ // Add a new block.
+ $this->clickLink('Add Block');
+
+ // Verify that blocks not modified are present.
+ $assert_session->linkExists('Powered by Drupal');
+ $assert_session->linkExists('Default revision');
+
+ // Verify that blocks explicitly removed are not present.
+ $assert_session->linkNotExists('Help');
+ $assert_session->linkNotExists('Sticky at top of lists');
+
+ // Verify that Changed block is not present on first section.
+ $assert_session->linkNotExists('Changed');
+
+ // Go back to Manage layout.
+ $this->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
+ $this->clickLink('Manage layout');
+
+ // Add a new section.
+ $this->clickLink('Add Section', 1);
+ $assert_session->linkExists('Two column');
+ $this->clickLink('Two column');
+
+ // Add a new block to second section.
+ $this->clickLink('Add Block', 1);
+
+ // Verify that Changed block is present on second section.
+ $assert_session->linkExists('Changed');
+ }
+
+ /**
+ * Tests that deleting a View block used in Layout Builder works.
+ */
+ public function testDeletedView() {
+ $assert_session = $this->assertSession();
+ $page = $this->getSession()->getPage();
+
+ $this->drupalLogin($this->drupalCreateUser([
+ 'configure any layout',
+ 'administer node display',
+ ]));
+
+ $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
+ // Enable overrides.
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[enabled]' => TRUE], 'Save');
+ $this->drupalPostForm("$field_ui_prefix/display/default", ['layout[allow_custom]' => TRUE], 'Save');
+ $this->drupalGet('node/1');
+
+ $assert_session->linkExists('Layout');
+ $this->clickLink('Layout');
+ $this->clickLink('Add Block');
+ $this->clickLink('Test Block View');
+ $page->pressButton('Add Block');
+
+ $assert_session->pageTextContains('Test Block View');
+ $assert_session->elementExists('css', '.block-views-blocktest-block-view-block-1');
+ $this->clickLink('Save Layout');
+ $assert_session->pageTextContains('Test Block View');
+ $assert_session->elementExists('css', '.block-views-blocktest-block-view-block-1');
+
+ View::load('test_block_view')->delete();
+ $this->drupalGet('node/1');
+ // Node can be loaded after deleting the View.
+ $assert_session->pageTextContains(Node::load(1)->getTitle());
+ $assert_session->pageTextNotContains('Test Block View');
+ }
+
+ /**
+ * Asserts that a text string only appears once on the page.
+ *
+ * @param string $needle
+ * The string to look for.
+ */
+ protected function assertTextAppearsOnce($needle) {
+ $this->assertEquals(1, substr_count($this->getSession()->getPage()->getContent(), $needle), "'$needle' only appears once on the page.");
+ }
+