You are here

class LayoutBuilderTest in Drupal 9

Same name in this branch
  1. 9 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest
  2. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/LayoutBuilderTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\LayoutBuilderTest
Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php \Drupal\Tests\layout_builder\Functional\LayoutBuilderTest

Tests the Layout Builder UI.

@group layout_builder

Hierarchy

Expanded class hierarchy of LayoutBuilderTest

File

core/modules/layout_builder/tests/src/Functional/LayoutBuilderTest.php, line 16

Namespace

Drupal\Tests\layout_builder\Functional
View source
class LayoutBuilderTest extends BrowserTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'views',
    'layout_builder',
    'layout_builder_views_test',
    'layout_test',
    'block',
    'block_test',
    'node',
    'layout_builder_test',
  ];

  /**
   * {@inheritdoc}
   */
  protected $defaultTheme = 'classy';

  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this
      ->drupalPlaceBlock('local_tasks_block');

    // Create two nodes.
    $this
      ->createContentType([
      'type' => 'bundle_with_section_field',
      'name' => 'Bundle with section field',
    ]);
    $this
      ->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The first node title',
      'body' => [
        [
          'value' => 'The first node body',
        ],
      ],
    ]);
    $this
      ->createNode([
      'type' => 'bundle_with_section_field',
      'title' => 'The second node title',
      'body' => [
        [
          'value' => 'The second node body',
        ],
      ],
    ]);
  }

  /**
   * Tests deleting a field in-use by an overridden layout.
   */
  public function testDeleteField() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node fields',
    ]));

    // Enable layout builder overrides.
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();

    // Ensure there is a layout override.
    $this
      ->drupalGet('node/1/layout');
    $page
      ->pressButton('Save layout');

    // Delete one of the fields in use.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/fields/node.bundle_with_section_field.body/delete');
    $page
      ->pressButton('Delete');

    // The node should still be accessible.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->statusCodeEquals(200);
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->statusCodeEquals(200);
  }

  /**
   * Tests Layout Builder overrides without access to edit the default layout.
   */
  public function testOverridesWithoutDefaultsAccess() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
    ]));
    LayoutBuilderEntityViewDisplay::load('node.bundle_with_section_field.default')
      ->enableLayoutBuilder()
      ->setOverridable()
      ->save();
    $this
      ->drupalGet('node/1');
    $page
      ->clickLink('Layout');
    $assert_session
      ->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item.');
    $assert_session
      ->linkNotExists('Edit the template for all Bundle with section field content items instead.');
  }

  /**
   * Tests functionality of Layout Builder for overrides.
   */
  public function testOverrides() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // From the manage display page, go to manage the layout.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');

    // @todo This should not be necessary.
    $this->container
      ->get('entity_field.manager')
      ->clearCachedFieldDefinitions();

    // Add a block with a custom label.
    $this
      ->drupalGet('node/1');
    $page
      ->clickLink('Layout');

    // The layout form should not contain fields for the title of the node by
    // default.
    $assert_session
      ->fieldNotExists('title[0][value]');
    $assert_session
      ->elementTextContains('css', '.layout-builder__message.layout-builder__message--overrides', 'You are editing the layout for this Bundle with section field content item. Edit the template for all Bundle with section field content items instead.');
    $assert_session
      ->linkExists('Edit the template for all Bundle with section field content items instead.');
    $page
      ->clickLink('Add block');
    $page
      ->clickLink('Powered by Drupal');
    $page
      ->fillField('settings[label]', 'This is an override');
    $page
      ->checkField('settings[label_display]');
    $page
      ->pressButton('Add block');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextContains('This is an override');

    // Get the UUID of the component.
    $components = Node::load(1)
      ->get('layout_builder__layout')
      ->getSection(0)
      ->getComponents();
    end($components);
    $uuid = key($components);
    $this
      ->drupalGet('layout_builder/update/block/overrides/node.1/0/content/' . $uuid);
    $page
      ->uncheckField('settings[label_display]');
    $page
      ->pressButton('Update');
    $assert_session
      ->pageTextNotContains('This is an override');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextNotContains('This is an override');
  }

  /**
   * Tests the Layout Builder UI for an entity type without a bundle.
   */
  public function testNonBundleEntityType() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();

    // Log in as a user that can edit layout templates.
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer user display',
    ]));
    $this
      ->drupalGet('admin/config/people/accounts/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $page
      ->clickLink('Manage layout');
    $assert_session
      ->pageTextContains('You are editing the layout template for all users.');
    $this
      ->drupalGet('user');
    $page
      ->clickLink('Layout');
    $assert_session
      ->pageTextContains('You are editing the layout for this user. Edit the template for all users instead.');

    // Log in as a user that cannot edit layout templates.
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
    ]));
    $this
      ->drupalGet('user');
    $page
      ->clickLink('Layout');
    $assert_session
      ->pageTextContains('You are editing the layout for this user.');
    $assert_session
      ->pageTextNotContains('Edit the template for all users instead.');
  }

  /**
   * Tests that the Layout Builder preserves entity values.
   */
  public function testPreserverEntityValues() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // From the manage display page, go to manage the layout.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');

    // @todo This should not be necessary.
    $this->container
      ->get('entity_field.manager')
      ->clearCachedFieldDefinitions();
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('The first node body');

    // Create a layout override which will store the current node in the
    // tempstore.
    $page
      ->clickLink('Layout');
    $page
      ->clickLink('Add block');
    $page
      ->clickLink('Powered by Drupal');
    $page
      ->pressButton('Add block');

    // Update the node to make a change that is not in the tempstore version.
    $node = Node::load(1);
    $node
      ->set('body', 'updated body');
    $node
      ->save();
    $page
      ->clickLink('View');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextContains('updated body');
    $page
      ->clickLink('Layout');
    $page
      ->pressButton('Save layout');

    // Ensure that saving the layout does not revert other field values.
    $assert_session
      ->addressEquals('node/1');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextContains('updated body');
  }

  /**
   * {@inheritdoc}
   */
  public function testLayoutBuilderUi() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'administer node fields',
    ]));
    $this
      ->drupalGet('node/1');
    $assert_session
      ->elementNotExists('css', '.layout-builder-block');
    $assert_session
      ->pageTextContains('The first node body');
    $assert_session
      ->pageTextNotContains('Powered by Drupal');
    $assert_session
      ->linkNotExists('Layout');
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

    // From the manage display page, go to manage the layout.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $assert_session
      ->linkNotExists('Manage layout');
    $assert_session
      ->fieldDisabled('layout[allow_custom]');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $assert_session
      ->linkExists('Manage layout');
    $this
      ->clickLink('Manage layout');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/default/layout");
    $assert_session
      ->elementTextContains('css', '.layout-builder__message.layout-builder__message--defaults', 'You are editing the layout template for all Bundle with section field content items.');

    // The body field is only present once.
    $assert_session
      ->elementsCount('css', '.field--name-body', 1);

    // The extra field is only present once.
    $assert_session
      ->pageTextContainsOnce('Placeholder for the "Extra label" field');

    // Blocks have layout builder specific block class.
    $assert_session
      ->elementExists('css', '.layout-builder-block');

    // Save the defaults.
    $page
      ->pressButton('Save layout');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/default");

    // Load the default layouts again after saving to confirm fields are only
    // added on new layouts.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $assert_session
      ->linkExists('Manage layout');
    $this
      ->clickLink('Manage layout');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/default/layout");

    // The body field is only present once.
    $assert_session
      ->elementsCount('css', '.field--name-body', 1);

    // The extra field is only present once.
    $assert_session
      ->pageTextContainsOnce('Placeholder for the "Extra label" field');

    // Add a new block.
    $assert_session
      ->linkExists('Add block');
    $this
      ->clickLink('Add block');
    $assert_session
      ->linkExists('Powered by Drupal');
    $this
      ->clickLink('Powered by Drupal');
    $page
      ->fillField('settings[label]', 'This is the label');
    $page
      ->checkField('settings[label_display]');
    $page
      ->pressButton('Add block');
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextContains('This is the label');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/default/layout");

    // Save the defaults.
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextContains('The layout has been saved.');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/default");

    // The node uses the defaults, no overrides available.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('The first node body');
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextContains('Extra, Extra read all about it.');
    $assert_session
      ->pageTextNotContains('Placeholder for the "Extra label" field');
    $assert_session
      ->linkNotExists('Layout');

    // Enable overrides.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet('node/1');

    // Remove the section from the defaults.
    $assert_session
      ->linkExists('Layout');
    $this
      ->clickLink('Layout');
    $assert_session
      ->pageTextContains('Placeholder for the "Extra label" field');
    $assert_session
      ->linkExists('Remove Section 1');
    $this
      ->clickLink('Remove Section 1');
    $page
      ->pressButton('Remove');

    // Add a new section.
    $this
      ->clickLink('Add section');
    $this
      ->assertCorrectLayouts();
    $assert_session
      ->linkExists('Two column');
    $this
      ->clickLink('Two column');
    $assert_session
      ->buttonExists('Add section');
    $page
      ->pressButton('Add section');
    $page
      ->pressButton('Save');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextNotContains('Powered by Drupal');
    $assert_session
      ->pageTextNotContains('Extra, Extra read all about it.');
    $assert_session
      ->pageTextNotContains('Placeholder for the "Extra label" field');

    // Assert that overrides cannot be turned off while overrides exist.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $assert_session
      ->checkboxChecked('layout[allow_custom]');
    $assert_session
      ->fieldDisabled('layout[allow_custom]');

    // Alter the defaults.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $assert_session
      ->linkExists('Add block');
    $this
      ->clickLink('Add block');
    $assert_session
      ->linkExists('Title');
    $this
      ->clickLink('Title');
    $page
      ->pressButton('Add block');

    // The title field is present.
    $assert_session
      ->elementExists('css', '.field--name-title');
    $page
      ->pressButton('Save layout');

    // View the other node, which is still using the defaults.
    $this
      ->drupalGet('node/2');
    $assert_session
      ->pageTextContains('The second node title');
    $assert_session
      ->pageTextContains('The second node body');
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextContains('Extra, Extra read all about it.');
    $assert_session
      ->pageTextNotContains('Placeholder for the "Extra label" field');

    // The overridden node does not pick up the changes to defaults.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->elementNotExists('css', '.field--name-title');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextNotContains('Powered by Drupal');
    $assert_session
      ->pageTextNotContains('Extra, Extra read all about it.');
    $assert_session
      ->pageTextNotContains('Placeholder for the "Extra label" field');
    $assert_session
      ->linkExists('Layout');

    // Reverting the override returns it to the defaults.
    $this
      ->clickLink('Layout');
    $assert_session
      ->linkExists('Add block');
    $this
      ->clickLink('Add block');
    $assert_session
      ->linkExists('ID');
    $this
      ->clickLink('ID');
    $page
      ->pressButton('Add block');

    // The title field is present.
    $assert_session
      ->elementExists('css', '.field--name-nid');
    $assert_session
      ->pageTextContains('ID');
    $assert_session
      ->pageTextContains('1');
    $page
      ->pressButton('Revert to defaults');
    $page
      ->pressButton('Revert');
    $assert_session
      ->addressEquals('node/1');
    $assert_session
      ->pageTextContains('The layout has been reverted back to defaults.');
    $assert_session
      ->elementExists('css', '.field--name-title');
    $assert_session
      ->elementNotExists('css', '.field--name-nid');
    $assert_session
      ->pageTextContains('The first node body');
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextContains('Extra, Extra read all about it.');

    // Assert that overrides can be turned off now that all overrides are gone.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => FALSE,
    ], 'Save');
    $this
      ->drupalGet('node/1');
    $assert_session
      ->linkNotExists('Layout');

    // Add a new field.
    $edit = [
      'new_storage_type' => 'string',
      'label' => 'My text field',
      'field_name' => 'my_text',
    ];
    $this
      ->drupalGet("{$field_ui_prefix}/fields/add-field");
    $this
      ->submitForm($edit, 'Save and continue');
    $page
      ->pressButton('Save field settings');
    $page
      ->pressButton('Save settings');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $assert_session
      ->pageTextContains('My text field');
    $assert_session
      ->elementExists('css', '.field--name-field-my-text');

    // Delete the field.
    $this
      ->drupalGet("{$field_ui_prefix}/fields/node.bundle_with_section_field.field_my_text/delete");
    $this
      ->submitForm([], 'Delete');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $assert_session
      ->pageTextNotContains('My text field');
    $assert_session
      ->elementNotExists('css', '.field--name-field-my-text');
    $this
      ->clickLink('Add section');
    $this
      ->clickLink('One column');
    $page
      ->fillField('layout_settings[label]', 'My Cool Section');
    $page
      ->pressButton('Add section');
    $expected_labels = [
      'My Cool Section',
      'Content region in My Cool Section',
      'Section 2',
      'Content region in Section 2',
    ];
    $labels = [];
    foreach ($page
      ->findAll('css', '[role="group"]') as $element) {
      $labels[] = $element
        ->getAttribute('aria-label');
    }
    $this
      ->assertSame($expected_labels, $labels);
  }

  /**
   * Test decorating controller.entity_form while layout_builder is installed.
   */
  public function testHtmlEntityFormControllerDecoration() {
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // Install module that decorates controller.entity_form.
    \Drupal::service('module_installer')
      ->install([
      'layout_builder_decoration_test',
    ]);
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $assert_session
      ->pageTextContains('Manage Display');
  }

  /**
   * Tests that layout builder checks entity view access.
   */
  public function testAccess() {
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

    // Allow overrides for the layout.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
    ]));
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('The first node body');
    $assert_session
      ->pageTextNotContains('Powered by Drupal');
    $node = Node::load(1);
    $node
      ->setUnpublished();
    $node
      ->save();
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextContains('Access denied');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextNotContains('The first node body');
    $assert_session
      ->pageTextContains('Access denied');
  }

  /**
   * Tests that a non-default view mode works as expected.
   */
  public function testNonDefaultViewMode() {
    $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';

    // Allow overrides for the layout.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $page
      ->checkField('layout[allow_custom]');
    $page
      ->pressButton('Save');
    $this
      ->clickLink('Manage layout');

    // Confirm the body field only is shown once.
    $assert_session
      ->elementsCount('css', '.field--name-body', 1);
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');
    $this
      ->clickLink('Teaser');

    // Enabling Layout Builder for the default mode does not affect the teaser.
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/teaser");
    $assert_session
      ->elementNotExists('css', '#layout-builder__layout');
    $assert_session
      ->checkboxNotChecked('layout[enabled]');
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $assert_session
      ->linkExists('Manage layout');
    $page
      ->clickLink('Manage layout');

    // Confirm the body field only is shown once.
    $assert_session
      ->elementsCount('css', '.field--name-body', 1);

    // Enable a disabled view mode.
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/teaser");
    $page
      ->clickLink('Default');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display");
    $assert_session
      ->linkNotExists('Full content');
    $page
      ->checkField('display_modes_custom[full]');
    $page
      ->pressButton('Save');
    $assert_session
      ->linkExists('Full content');
    $page
      ->clickLink('Full content');
    $assert_session
      ->addressEquals("{$field_ui_prefix}/display/full");
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $assert_session
      ->linkExists('Manage layout');
    $page
      ->clickLink('Manage layout');

    // Confirm the body field only is shown once.
    $assert_session
      ->elementsCount('css', '.field--name-body', 1);
  }

  /**
   * Tests that component's dependencies are respected during removal.
   */
  public function testPluginDependencies() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this->container
      ->get('module_installer')
      ->install([
      'menu_ui',
    ]);
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'administer menu',
    ]));

    // Create a new menu.
    $this
      ->drupalGet('admin/structure/menu/add');
    $page
      ->fillField('label', 'My Menu');
    $page
      ->fillField('id', 'my-menu');
    $page
      ->pressButton('Save');
    $this
      ->drupalGet('admin/structure/menu/add');
    $page
      ->fillField('label', 'My Menu');
    $page
      ->fillField('id', 'my-other-menu');
    $page
      ->pressButton('Save');
    $page
      ->clickLink('Add link');
    $page
      ->fillField('title[0][value]', 'My link');
    $page
      ->fillField('link[0][uri]', '/');
    $page
      ->pressButton('Save');
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $assert_session
      ->linkExists('Manage layout');
    $this
      ->clickLink('Manage layout');
    $assert_session
      ->linkExists('Add section');
    $this
      ->clickLink('Add section');
    $assert_session
      ->linkExists('Layout plugin (with dependencies)');
    $this
      ->clickLink('Layout plugin (with dependencies)');
    $page
      ->pressButton('Add section');
    $assert_session
      ->elementExists('css', '.layout--layout-test-dependencies-plugin');
    $assert_session
      ->elementExists('css', '.field--name-body');
    $page
      ->pressButton('Save layout');
    $this
      ->drupalGet('admin/structure/menu/manage/my-other-menu/delete');
    $this
      ->submitForm([], 'Delete');
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
    $assert_session
      ->elementNotExists('css', '.layout--layout-test-dependencies-plugin');
    $assert_session
      ->elementExists('css', '.field--name-body');

    // Add a menu block.
    $assert_session
      ->linkExists('Add block');
    $this
      ->clickLink('Add block');
    $assert_session
      ->linkExists('My Menu');
    $this
      ->clickLink('My Menu');
    $page
      ->pressButton('Add block');

    // Add another block alongside the menu.
    $assert_session
      ->linkExists('Add block');
    $this
      ->clickLink('Add block');
    $assert_session
      ->linkExists('Powered by Drupal');
    $this
      ->clickLink('Powered by Drupal');
    $page
      ->pressButton('Add block');

    // Assert that the blocks are visible, and save the layout.
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextContains('My Menu');
    $assert_session
      ->elementExists('css', '.block.menu--my-menu');
    $page
      ->pressButton('Save layout');

    // Delete the menu.
    $this
      ->drupalGet('admin/structure/menu/manage/my-menu/delete');
    $this
      ->submitForm([], 'Delete');

    // Ensure that the menu block is gone, but that the other block remains.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
    $assert_session
      ->pageTextContains('Powered by Drupal');
    $assert_session
      ->pageTextNotContains('My Menu');
    $assert_session
      ->elementNotExists('css', '.block.menu--my-menu');
  }

  /**
   * 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';

    // For the purposes of this test, turn the full view mode on and off to
    // prevent copying from the customized default view mode.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => FALSE,
    ], 'Save');

    // Allow overrides for the layout.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');

    // Customize the default view mode.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $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');
    $page
      ->pressButton('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');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the default view mode');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');

    // Enable the full view mode and customize it.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/full");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/full");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/full/layout");
    $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');
    $page
      ->pressButton('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');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');

    // Disable the full view mode, the default should be used again.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => FALSE,
    ], 'Save');
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('This is the default view mode');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the default view mode');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');

    // Re-enabling the full view mode restores the layout changes.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');

    // Create an override of the full view mode.
    $this
      ->clickLink('Add block');
    $this
      ->clickLink('Powered by Drupal');
    $page
      ->fillField('settings[label]', 'This is an override of the full view mode');
    $page
      ->checkField('settings[label_display]');
    $page
      ->pressButton('Add block');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $page
      ->pressButton('Save layout');
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');

    // The override does not affect the full view mode.
    $this
      ->drupalGet("{$field_ui_prefix}/display/full/layout");
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');

    // Reverting the override restores back to the full view mode.
    $this
      ->drupalGet('node/1/layout');
    $page
      ->pressButton('Revert to default');
    $page
      ->pressButton('Revert');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextNotContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');

    // Recreate an override of the full view mode.
    $this
      ->clickLink('Add block');
    $this
      ->clickLink('Powered by Drupal');
    $page
      ->fillField('settings[label]', 'This is an override of the full view mode');
    $page
      ->checkField('settings[label_display]');
    $page
      ->pressButton('Add block');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');

    // Disable the full view mode.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'display_modes_custom[full]' => FALSE,
    ], 'Save');

    // The override of the full view mode is still available.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('This is the full view mode');
    $assert_session
      ->pageTextContains('This is an override of the full view mode');
    $assert_session
      ->pageTextNotContains('This is the default view mode');

    // Reverting the override restores back to the default view mode.
    $this
      ->drupalGet('node/1/layout');
    $page
      ->pressButton('Revert to default');
    $page
      ->pressButton('Revert');
    $assert_session
      ->pageTextContains('This is the default view mode');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $this
      ->drupalGet('node/1/layout');
    $assert_session
      ->pageTextContains('This is the default view mode');
    $assert_session
      ->pageTextNotContains('This is the full view mode');
    $page
      ->pressButton('Discard changes');
    $page
      ->pressButton('Confirm');
  }

  /**
   * Ensures that one bundle doesn't interfere with another bundle.
   */
  public function testFullViewModeMultipleBundles() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // Create one bundle with the full view mode enabled.
    $this
      ->createContentType([
      'type' => 'full_bundle',
    ]);
    $this
      ->drupalGet('admin/structure/types/manage/full_bundle/display/default');
    $page
      ->checkField('display_modes_custom[full]');
    $page
      ->pressButton('Save');

    // Create another bundle without the full view mode enabled.
    $this
      ->createContentType([
      'type' => 'default_bundle',
    ]);
    $this
      ->drupalGet('admin/structure/types/manage/default_bundle/display/default');

    // Enable Layout Builder for defaults and overrides.
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $page
      ->checkField('layout[allow_custom]');
    $page
      ->pressButton('Save');
    $assert_session
      ->checkboxChecked('layout[allow_custom]');
  }

  /**
   * {@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
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      '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');
    $assert_session
      ->linkNotExists('Main page content');
    $assert_session
      ->linkNotExists('Page title');

    // 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');
    $assert_session
      ->buttonExists('Add section');
    $this
      ->getSession()
      ->getPage()
      ->pressButton('Add section');

    // 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 extra fields work before and after enabling Layout Builder.
   */
  public function testExtraFields() {
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));
    $this
      ->drupalGet('node');
    $assert_session
      ->linkExists('Read more');
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');

    // Extra fields display under "Content fields".
    $this
      ->drupalGet("admin/structure/types/manage/bundle_with_section_field/display/default/layout");
    $this
      ->clickLink('Add block');
    $assert_session
      ->elementTextContains('xpath', '//details/summary[contains(text(),"Content fields")]/parent::details', 'Extra label');
    $this
      ->drupalGet('node');
    $assert_session
      ->linkExists('Read more');

    // Consider an extra field hidden by default. Make sure it's not displayed.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextNotContains('Extra Field 2 is hidden by default.');

    // View the layout and add the extra field that is not visible by default.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default/layout');
    $assert_session
      ->pageTextNotContains('Extra Field 2');
    $page = $this
      ->getSession()
      ->getPage();
    $page
      ->clickLink('Add block');
    $page
      ->clickLink('Extra Field 2');
    $page
      ->pressButton('Add block');
    $assert_session
      ->pageTextContains('Extra Field 2');
    $page
      ->pressButton('Save layout');

    // Confirm that the newly added extra field is visible.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('Extra Field 2 is hidden by default.');
  }

  /**
   * Tests loading a pending revision in the Layout Builder UI.
   */
  public function testPendingRevision() {
    $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
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $storage = $this->container
      ->get('entity_type.manager')
      ->getStorage('node');
    $node = $storage
      ->load(1);

    // Create a pending revision.
    $pending_revision = $storage
      ->createRevision($node, FALSE);
    $pending_revision
      ->set('title', 'The pending title of the first node');
    $pending_revision
      ->save();

    // The original node title is available when viewing the node, but the
    // pending title is visible within the Layout Builder UI.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->pageTextContains('The first node title');
    $page
      ->clickLink('Layout');
    $assert_session
      ->pageTextNotContains('The first node title');
    $assert_session
      ->pageTextContains('The pending title of the first node');
  }

  /**
   * 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
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      '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');
    $page
      ->pressButton('Save');
    $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');
  }

  /**
   * Tests that hook_form_alter() has access to the Layout Builder info.
   */
  public function testFormAlter() {
    $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';
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $page
      ->clickLink('Manage layout');
    $page
      ->clickLink('Add block');
    $page
      ->clickLink('Powered by Drupal');
    $assert_session
      ->pageTextContains('Layout Builder Storage: node.bundle_with_section_field.default');
    $assert_session
      ->pageTextContains('Layout Builder Section: layout_onecol');
    $assert_session
      ->pageTextContains('Layout Builder Component: system_powered_by_block');
  }

  /**
   * Tests the functionality of custom section labels.
   */
  public function testSectionLabels() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $page
      ->checkField('layout[enabled]');
    $page
      ->pressButton('Save');
    $page
      ->checkField('layout[allow_custom]');
    $page
      ->pressButton('Save');
    $this
      ->drupalGet('node/1/layout');
    $page
      ->clickLink('Add section');
    $page
      ->clickLink('One column');
    $page
      ->fillField('layout_settings[label]', 'My Cool Section');
    $page
      ->pressButton('Add section');
    $assert_session
      ->pageTextContains('My Cool Section');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextNotContains('My Cool Section');
  }

  /**
   * Tests that layouts can be context-aware.
   */
  public function testContextAwareLayouts() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $account = $this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]);
    $this
      ->drupalLogin($account);
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $page
      ->clickLink('Manage layout');
    $page
      ->clickLink('Add section');
    $page
      ->clickLink('Layout Builder Test: Context Aware');
    $page
      ->pressButton('Add section');

    // See \Drupal\layout_builder_test\Plugin\Layout\TestContextAwareLayout::build().
    $assert_session
      ->elementExists('css', '.user--' . $account
      ->getAccountName());
    $page
      ->clickLink('Configure Section 1');
    $page
      ->fillField('layout_settings[label]', 'My section');
    $page
      ->pressButton('Update');
    $assert_session
      ->linkExists('Configure My section');
    $page
      ->clickLink('Add block');
    $page
      ->clickLink('Powered by Drupal');
    $page
      ->pressButton('Add block');
    $page
      ->pressButton('Save layout');
    $this
      ->drupalGet('node/1');

    // See \Drupal\layout_builder_test\Plugin\Layout\TestContextAwareLayout::build().
    $assert_session
      ->elementExists('css', '.user--' . $account
      ->getAccountName());
  }

  /**
   * Tests that sections can provide custom attributes.
   */
  public function testCustomSectionAttributes() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $page
      ->clickLink('Manage layout');
    $page
      ->clickLink('Add section');
    $page
      ->clickLink('Layout Builder Test Plugin');
    $page
      ->pressButton('Add section');

    // See \Drupal\layout_builder_test\Plugin\Layout\LayoutBuilderTestPlugin::build().
    $assert_session
      ->elementExists('css', '.go-birds');
  }

  /**
   * Tests the usage of placeholders for empty blocks.
   *
   * @see \Drupal\Core\Block\BlockPluginInterface::getPlaceholderString()
   * @see \Drupal\layout_builder\EventSubscriber\BlockComponentRenderArray::onBuildRender()
   */
  public function testBlockPlaceholder() {
    $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';
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');

    // Customize the default view mode.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");

    // Add a block whose content is controlled by state and is empty by default.
    $this
      ->clickLink('Add block');
    $this
      ->clickLink('Test block caching');
    $page
      ->fillField('settings[label]', 'The block label');
    $page
      ->pressButton('Add block');
    $block_content = 'I am content';
    $placeholder_content = 'Placeholder for the "The block label" block';

    // The block placeholder is displayed and there is no content.
    $assert_session
      ->pageTextContains($placeholder_content);
    $assert_session
      ->pageTextNotContains($block_content);

    // Set block content and reload the page.
    \Drupal::state()
      ->set('block_test.content', $block_content);
    $this
      ->getSession()
      ->reload();

    // The block placeholder is no longer displayed and the content is visible.
    $assert_session
      ->pageTextNotContains($placeholder_content);
    $assert_session
      ->pageTextContains($block_content);
  }

  /**
   * Tests a custom alter of the overrides form.
   */
  public function testOverridesFormAlter() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'administer nodes',
    ]));
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

    // Enable overrides.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet('node/1');

    // The status checkbox should be checked by default.
    $page
      ->clickLink('Layout');
    $assert_session
      ->checkboxChecked('status[value]');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->pageTextContains('The layout override has been saved.');

    // Unchecking the status checkbox will unpublish the entity.
    $page
      ->clickLink('Layout');
    $page
      ->uncheckField('status[value]');
    $page
      ->pressButton('Save layout');
    $assert_session
      ->statusCodeEquals(403);
    $assert_session
      ->pageTextContains('The layout override has been saved.');
  }

  /**
   * Tests the Block UI when Layout Builder is installed.
   */
  public function testBlockUiListing() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'administer blocks',
    ]));
    $this
      ->drupalGet('admin/structure/block');
    $page
      ->clickLink('Place block');

    // Ensure that blocks expected to appear are available.
    $assert_session
      ->pageTextContains('Test HTML block');
    $assert_session
      ->pageTextContains('Block test');

    // Ensure that blocks not expected to appear are not available.
    $assert_session
      ->pageTextNotContains('Body');
    $assert_session
      ->pageTextNotContains('Content fields');
  }

  /**
   * Tests the expected breadcrumbs of the Layout Builder UI.
   */
  public function testBreadcrumb() {
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalPlaceBlock('system_breadcrumb_block');
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'administer content types',
      'access administration pages',
    ]));

    // From the manage display page, go to manage the layout.
    $this
      ->drupalGet('admin/structure/types/manage/bundle_with_section_field/display/default');
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $page
      ->clickLink('Manage layout');
    $breadcrumb_titles = [];
    foreach ($page
      ->findAll('css', '.breadcrumb a') as $link) {
      $breadcrumb_titles[$link
        ->getText()] = $link
        ->getAttribute('href');
    }
    $base_path = base_path();
    $expected = [
      'Home' => $base_path,
      'Administration' => $base_path . 'admin',
      'Structure' => $base_path . 'admin/structure',
      'Content types' => $base_path . 'admin/structure/types',
      'Bundle with section field' => $base_path . 'admin/structure/types/manage/bundle_with_section_field',
      'Manage display' => $base_path . 'admin/structure/types/manage/bundle_with_section_field/display/default',
      'External link' => 'http://www.example.com',
    ];
    $this
      ->assertSame($expected, $breadcrumb_titles);
  }

  /**
   * Tests a config-based implementation of Layout Builder.
   *
   * @see \Drupal\layout_builder_test\Plugin\SectionStorage\SimpleConfigSectionStorage
   */
  public function testSimpleConfigBasedLayout() {
    $assert_session = $this
      ->assertSession();
    $this
      ->drupalLogin($this
      ->createUser([
      'configure any layout',
    ]));

    // Prepare an object with a pre-existing section.
    $this->container
      ->get('config.factory')
      ->getEditable('layout_builder_test.test_simple_config.existing')
      ->set('sections', [
      (new Section('layout_twocol'))
        ->toArray(),
    ])
      ->save();

    // The pre-existing section is found.
    $this
      ->drupalGet('layout-builder-test-simple-config/existing');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->elementsCount('css', '.layout--twocol', 1);

    // No layout is selected for a new object.
    $this
      ->drupalGet('layout-builder-test-simple-config/new');
    $assert_session
      ->elementNotExists('css', '.layout');
  }

  /**
   * Tests removing all sections from overrides and defaults.
   */
  public function testRemovingAllSections() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();

    // Install Quick Edit as well.
    $this->container
      ->get('module_installer')
      ->install([
      'quickedit',
    ]);
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
      'access in-place editing',
    ]));
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';

    // Enable overrides.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');

    // By default, there is one section.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->pageTextContains('The first node body');
    $page
      ->clickLink('Layout');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 2);

    // Remove the only section from the override.
    $page
      ->clickLink('Remove Section 1');
    $page
      ->pressButton('Remove');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 1);

    // The override is still used instead of the default, despite being empty.
    $page
      ->pressButton('Save layout');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->pageTextNotContains('The first node body');
    $page
      ->clickLink('Layout');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 1);

    // Add one section to the override.
    $page
      ->clickLink('Add section');
    $page
      ->clickLink('One column');
    $page
      ->pressButton('Add section');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 2);
    $page
      ->pressButton('Save layout');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->pageTextNotContains('The first node body');

    // By default, the default has one section.
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 2);

    // Remove the only section from the default.
    $page
      ->clickLink('Remove Section 1');
    $page
      ->pressButton('Remove');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 1);
    $page
      ->pressButton('Save layout');
    $page
      ->clickLink('Manage layout');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 0);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 1);

    // The override is still in use.
    $this
      ->drupalGet('node/1');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->pageTextNotContains('The first node body');
    $page
      ->clickLink('Layout');
    $assert_session
      ->elementsCount('css', '.layout', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-block', 1);
    $assert_session
      ->elementsCount('css', '.layout-builder__add-section', 2);

    // Revert the override.
    $page
      ->pressButton('Revert to defaults');
    $page
      ->pressButton('Revert');
    $assert_session
      ->elementsCount('css', '.layout', 0);
    $assert_session
      ->pageTextNotContains('The first node body');
  }

  /**
   * Tests removing section without layout label configuration.
   */
  public function testRemovingSectionWithoutLayoutLabel() {
    $assert_session = $this
      ->assertSession();
    $page = $this
      ->getSession()
      ->getPage();
    $this
      ->drupalLogin($this
      ->drupalCreateUser([
      'configure any layout',
      'administer node display',
    ]));

    // Enable overrides.
    $field_ui_prefix = 'admin/structure/types/manage/bundle_with_section_field';
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default/layout");
    $page
      ->clickLink('Add section');
    $assert_session
      ->linkExists('Layout Without Label');
    $page
      ->clickLink('Layout Without Label');
    $page
      ->pressButton('Add section');
    $assert_session
      ->elementsCount('css', '.layout', 2);
    $assert_session
      ->linkExists('Remove Section 1');
    $this
      ->clickLink('Remove Section 1');
    $page
      ->pressButton('Remove');
    $assert_session
      ->statusCodeEquals(200);
    $assert_session
      ->elementsCount('css', '.layout', 1);
  }

  /**
   * Asserts that the correct layouts are available.
   */
  protected function assertCorrectLayouts() {
    $assert_session = $this
      ->assertSession();

    // Ensure the layouts provided by layout_builder are available.
    $expected_layouts_hrefs = [
      'layout_builder/configure/section/overrides/node.1/0/layout_onecol',
      'layout_builder/configure/section/overrides/node.1/0/layout_twocol_section',
      'layout_builder/configure/section/overrides/node.1/0/layout_threecol_section',
      'layout_builder/configure/section/overrides/node.1/0/layout_fourcol_section',
    ];
    foreach ($expected_layouts_hrefs as $expected_layouts_href) {
      $assert_session
        ->linkByHrefExists($expected_layouts_href);
    }

    // Ensure the layout_discovery module's layouts were removed.
    $unexpected_layouts = [
      'twocol',
      'twocol_bricks',
      'threecol_25_50_25',
      'threecol_33_34_33',
    ];
    foreach ($unexpected_layouts as $unexpected_layout) {
      $assert_session
        ->linkByHrefNotExists("layout_builder/add/section/overrides/node.1/0/{$unexpected_layout}");
      $assert_session
        ->linkByHrefNotExists("layout_builder/configure/section/overrides/node.1/0/{$unexpected_layout}");
    }
  }

  /**
   * Tests the Layout Builder UI with a context defined at runtime.
   */
  public function testLayoutBuilderContexts() {
    $node_url = 'node/1';
    $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';
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[enabled]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet("{$field_ui_prefix}/display/default");
    $this
      ->submitForm([
      'layout[allow_custom]' => TRUE,
    ], 'Save');
    $this
      ->drupalGet($node_url);
    $assert_session
      ->linkExists('Layout');
    $this
      ->clickLink('Layout');
    $assert_session
      ->linkExists('Add section');

    // Add the testing block.
    $page
      ->clickLink('Add block');
    $this
      ->clickLink('Can I have runtime contexts');
    $page
      ->pressButton('Add block');

    // Ensure the runtime context value is rendered before saving.
    $assert_session
      ->pageTextContains('for sure you can');

    // Save the layout, and test that the value is rendered after save.
    $page
      ->pressButton('Save layout');
    $assert_session
      ->addressEquals($node_url);
    $assert_session
      ->pageTextContains('for sure you can');
    $assert_session
      ->elementExists('css', '.layout');
  }

}

Members

Namesort descending Modifiers Type Description Overrides
AssertLegacyTrait::assert Deprecated protected function
AssertLegacyTrait::assertCacheTag Deprecated protected function Asserts whether an expected cache tag was present in the last response.
AssertLegacyTrait::assertElementNotPresent Deprecated protected function Asserts that the element with the given CSS selector is not present.
AssertLegacyTrait::assertElementPresent Deprecated protected function Asserts that the element with the given CSS selector is present.
AssertLegacyTrait::assertEqual Deprecated protected function
AssertLegacyTrait::assertEscaped Deprecated protected function Passes if the raw text IS found escaped on the loaded page, fail otherwise.
AssertLegacyTrait::assertField Deprecated protected function Asserts that a field exists with the given name or ID.
AssertLegacyTrait::assertFieldById Deprecated protected function Asserts that a field exists with the given ID and value.
AssertLegacyTrait::assertFieldByName Deprecated protected function Asserts that a field exists with the given name and value.
AssertLegacyTrait::assertFieldByXPath Deprecated protected function Asserts that a field exists in the current page by the given XPath.
AssertLegacyTrait::assertFieldChecked Deprecated protected function Asserts that a checkbox field in the current page is checked.
AssertLegacyTrait::assertFieldsByValue Deprecated protected function Asserts that a field exists in the current page with a given Xpath result.
AssertLegacyTrait::assertHeader Deprecated protected function Checks that current response header equals value.
AssertLegacyTrait::assertIdentical Deprecated protected function
AssertLegacyTrait::assertIdenticalObject Deprecated protected function
AssertLegacyTrait::assertLink Deprecated protected function Passes if a link with the specified label is found.
AssertLegacyTrait::assertLinkByHref Deprecated protected function Passes if a link containing a given href (part) is found.
AssertLegacyTrait::assertNoCacheTag Deprecated protected function Asserts whether an expected cache tag was absent in the last response.
AssertLegacyTrait::assertNoEscaped Deprecated protected function Passes if the raw text is not found escaped on the loaded page.
AssertLegacyTrait::assertNoField Deprecated protected function Asserts that a field does NOT exist with the given name or ID.
AssertLegacyTrait::assertNoFieldById Deprecated protected function Asserts that a field does not exist with the given ID and value.
AssertLegacyTrait::assertNoFieldByName Deprecated protected function Asserts that a field does not exist with the given name and value.
AssertLegacyTrait::assertNoFieldByXPath Deprecated protected function Asserts that a field does not exist or its value does not match, by XPath.
AssertLegacyTrait::assertNoFieldChecked Deprecated protected function Asserts that a checkbox field in the current page is not checked.
AssertLegacyTrait::assertNoLink Deprecated protected function Passes if a link with the specified label is not found.
AssertLegacyTrait::assertNoLinkByHref Deprecated protected function Passes if a link containing a given href (part) is not found.
AssertLegacyTrait::assertNoOption Deprecated protected function Asserts that a select option does NOT exist in the current page.
AssertLegacyTrait::assertNoPattern Deprecated protected function Triggers a pass if the Perl regex pattern is not found in the raw content.
AssertLegacyTrait::assertNoRaw Deprecated protected function Passes if the raw text IS not found on the loaded page, fail otherwise.
AssertLegacyTrait::assertNotEqual Deprecated protected function
AssertLegacyTrait::assertNoText Deprecated protected function Passes if the page (with HTML stripped) does not contains the text.
AssertLegacyTrait::assertNotIdentical Deprecated protected function
AssertLegacyTrait::assertNoUniqueText Deprecated protected function Passes if the text is found MORE THAN ONCE on the text version of the page.
AssertLegacyTrait::assertOption Deprecated protected function Asserts that a select option in the current page exists.
AssertLegacyTrait::assertOptionByText Deprecated protected function Asserts that a select option with the visible text exists.
AssertLegacyTrait::assertOptionSelected Deprecated protected function Asserts that a select option in the current page is checked.
AssertLegacyTrait::assertPattern Deprecated protected function Triggers a pass if the Perl regex pattern is found in the raw content.
AssertLegacyTrait::assertRaw Deprecated protected function Passes if the raw text IS found on the loaded page, fail otherwise.
AssertLegacyTrait::assertResponse Deprecated protected function Asserts the page responds with the specified response code.
AssertLegacyTrait::assertText Deprecated protected function Passes if the page (with HTML stripped) contains the text.
AssertLegacyTrait::assertTextHelper Deprecated protected function Helper for assertText and assertNoText.
AssertLegacyTrait::assertTitle Deprecated protected function Pass if the page title is the given string.
AssertLegacyTrait::assertUniqueText Deprecated protected function Passes if the text is found ONLY ONCE on the text version of the page.
AssertLegacyTrait::assertUrl Deprecated protected function Passes if the internal browser's URL matches the given path.
AssertLegacyTrait::buildXPathQuery Deprecated protected function Builds an XPath query.
AssertLegacyTrait::constructFieldXpath Deprecated protected function Helper: Constructs an XPath for the given set of attributes and value.
AssertLegacyTrait::getAllOptions Deprecated protected function Get all option elements, including nested options, in a select.
AssertLegacyTrait::getRawContent Deprecated protected function Gets the current raw content.
AssertLegacyTrait::pass Deprecated protected function
AssertLegacyTrait::verbose Deprecated protected function
BlockCreationTrait::placeBlock protected function Creates a block instance based on default settings. Aliased as: drupalPlaceBlock
BrowserHtmlDebugTrait::$htmlOutputBaseUrl protected property The Base URI to use for links to the output files.
BrowserHtmlDebugTrait::$htmlOutputClassName protected property Class name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounter protected property Counter for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputCounterStorage protected property Counter storage for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputDirectory protected property Directory name for HTML output logging.
BrowserHtmlDebugTrait::$htmlOutputEnabled protected property HTML output output enabled.
BrowserHtmlDebugTrait::$htmlOutputFile protected property The file name to write the list of URLs to.
BrowserHtmlDebugTrait::$htmlOutputTestId protected property HTML output test ID.
BrowserHtmlDebugTrait::formatHtmlOutputHeaders protected function Formats HTTP headers as string for HTML output logging.
BrowserHtmlDebugTrait::getHtmlOutputHeaders protected function Returns headers in HTML output format. 1
BrowserHtmlDebugTrait::getResponseLogHandler protected function Provides a Guzzle middleware handler to log every response received.
BrowserHtmlDebugTrait::htmlOutput protected function Logs a HTML output message in a text file.
BrowserHtmlDebugTrait::initBrowserOutputFile protected function Creates the directory to store browser output.
BrowserTestBase::$baseUrl protected property The base URL.
BrowserTestBase::$configImporter protected property The config importer that can be used in a test.
BrowserTestBase::$customTranslations protected property An array of custom translations suitable for drupal_rewrite_settings().
BrowserTestBase::$databasePrefix protected property The database prefix of this test run.
BrowserTestBase::$mink protected property Mink session manager.
BrowserTestBase::$minkDefaultDriverArgs protected property Mink default driver params.
BrowserTestBase::$minkDefaultDriverClass protected property Mink class for the default driver to use. 1
BrowserTestBase::$originalContainer protected property The original container.
BrowserTestBase::$originalShutdownCallbacks protected property The original array of shutdown function callbacks.
BrowserTestBase::$preserveGlobalState protected property
BrowserTestBase::$profile protected property The profile to install as a basis for testing. 39
BrowserTestBase::$root protected property The app root.
BrowserTestBase::$runTestInSeparateProcess protected property Browser tests are run in separate processes to prevent collisions between code that may be loaded by tests.
BrowserTestBase::$timeLimit protected property Time limit in seconds for the test.
BrowserTestBase::$translationFilesDirectory protected property The translation file directory for the test environment.
BrowserTestBase::cleanupEnvironment protected function Clean up the Simpletest environment.
BrowserTestBase::config protected function Configuration accessor for tests. Returns non-overridden configuration.
BrowserTestBase::drupalGetHeader Deprecated protected function Gets the value of an HTTP response header.
BrowserTestBase::filePreDeleteCallback public static function Ensures test files are deletable.
BrowserTestBase::getDefaultDriverInstance protected function Gets an instance of the default Mink driver.
BrowserTestBase::getDrupalSettings protected function Gets the JavaScript drupalSettings variable for the currently-loaded page. 1
BrowserTestBase::getHttpClient protected function Obtain the HTTP client for the system under test.
BrowserTestBase::getMinkDriverArgs protected function Get the Mink driver args from an environment variable, if it is set. Can be overridden in a derived class so it is possible to use a different value for a subset of tests, e.g. the JavaScript tests. 1
BrowserTestBase::getOptions protected function Helper function to get the options of select field.
BrowserTestBase::getSession public function Returns Mink session.
BrowserTestBase::getSessionCookies protected function Get session cookies from current session.
BrowserTestBase::getTestMethodCaller protected function Retrieves the current calling line in the class under test. Overrides BrowserHtmlDebugTrait::getTestMethodCaller
BrowserTestBase::initFrontPage protected function Visits the front page when initializing Mink. 3
BrowserTestBase::initMink protected function Initializes Mink sessions. 1
BrowserTestBase::installDrupal public function Installs Drupal into the Simpletest site. 1
BrowserTestBase::registerSessions protected function Registers additional Mink sessions.
BrowserTestBase::setUpAppRoot protected function Sets up the root application path.
BrowserTestBase::setUpBeforeClass public static function 1
BrowserTestBase::tearDown protected function 3
BrowserTestBase::translatePostValues protected function Transforms a nested array into a flat array suitable for submitForm().
BrowserTestBase::xpath protected function Performs an xpath search on the contents of the internal browser.
BrowserTestBase::__sleep public function Prevents serializing any properties.
ConfigTestTrait::configImporter protected function Returns a ConfigImporter object to import test configuration.
ConfigTestTrait::copyConfig protected function Copies configuration objects from source storage to target storage.
ContentTypeCreationTrait::createContentType protected function Creates a custom content type based on default settings. Aliased as: drupalCreateContentType 1
ExtensionListTestTrait::getModulePath protected function Gets the path for the specified module.
ExtensionListTestTrait::getThemePath protected function Gets the path for the specified theme.
FunctionalTestSetupTrait::$apcuEnsureUniquePrefix protected property The flag to set 'apcu_ensure_unique_prefix' setting. 1
FunctionalTestSetupTrait::$classLoader protected property The class loader to use for installation and initialization of setup.
FunctionalTestSetupTrait::$rootUser protected property The "#1" admin user.
FunctionalTestSetupTrait::doInstall protected function Execute the non-interactive installer. 1
FunctionalTestSetupTrait::getDatabaseTypes protected function Returns all supported database driver installer objects.
FunctionalTestSetupTrait::initConfig protected function Initialize various configurations post-installation. 1
FunctionalTestSetupTrait::initKernel protected function Initializes the kernel after installation.
FunctionalTestSetupTrait::initSettings protected function Initialize settings created during install.
FunctionalTestSetupTrait::initUserSession protected function Initializes user 1 for the site to be installed.
FunctionalTestSetupTrait::installDefaultThemeFromClassProperty protected function Installs the default theme defined by `static::$defaultTheme` when needed.
FunctionalTestSetupTrait::installModulesFromClassProperty protected function Install modules defined by `static::$modules`. 1
FunctionalTestSetupTrait::installParameters protected function Returns the parameters that will be used when Simpletest installs Drupal. 9
FunctionalTestSetupTrait::prepareEnvironment protected function Prepares the current environment for running the test. 20
FunctionalTestSetupTrait::prepareRequestForGenerator protected function Creates a mock request and sets it on the generator.
FunctionalTestSetupTrait::prepareSettings protected function Prepares site settings and services before installation. 2
FunctionalTestSetupTrait::rebuildAll protected function Resets and rebuilds the environment after setup.
FunctionalTestSetupTrait::rebuildContainer protected function Rebuilds \Drupal::getContainer().
FunctionalTestSetupTrait::resetAll protected function Resets all data structures after having enabled new modules.
FunctionalTestSetupTrait::setContainerParameter protected function Changes parameters in the services.yml file.
FunctionalTestSetupTrait::setupBaseUrl protected function Sets up the base URL based upon the environment variable.
FunctionalTestSetupTrait::writeSettings protected function Rewrites the settings.php file of the test site. 1
LayoutBuilderTest::$defaultTheme protected property The theme to install as the default for testing. Overrides BrowserTestBase::$defaultTheme
LayoutBuilderTest::$modules protected static property Modules to enable. Overrides BrowserTestBase::$modules
LayoutBuilderTest::assertCorrectLayouts protected function Asserts that the correct layouts are available.
LayoutBuilderTest::setUp protected function Overrides BrowserTestBase::setUp
LayoutBuilderTest::testAccess public function Tests that layout builder checks entity view access.
LayoutBuilderTest::testBlockPlaceholder public function Tests the usage of placeholders for empty blocks.
LayoutBuilderTest::testBlockUiListing public function Tests the Block UI when Layout Builder is installed.
LayoutBuilderTest::testBreadcrumb public function Tests the expected breadcrumbs of the Layout Builder UI.
LayoutBuilderTest::testContextAwareLayouts public function Tests that layouts can be context-aware.
LayoutBuilderTest::testCustomSectionAttributes public function Tests that sections can provide custom attributes.
LayoutBuilderTest::testDeletedView public function Tests that deleting a View block used in Layout Builder works.
LayoutBuilderTest::testDeleteField public function Tests deleting a field in-use by an overridden layout.
LayoutBuilderTest::testExtraFields public function Tests that extra fields work before and after enabling Layout Builder.
LayoutBuilderTest::testFormAlter public function Tests that hook_form_alter() has access to the Layout Builder info.
LayoutBuilderTest::testFullViewModeMultipleBundles public function Ensures that one bundle doesn't interfere with another bundle.
LayoutBuilderTest::testHtmlEntityFormControllerDecoration public function Test decorating controller.entity_form while layout_builder is installed.
LayoutBuilderTest::testLayoutBuilderChooseBlocksAlter public function
LayoutBuilderTest::testLayoutBuilderContexts public function Tests the Layout Builder UI with a context defined at runtime.
LayoutBuilderTest::testLayoutBuilderUi public function
LayoutBuilderTest::testLayoutBuilderUiFullViewMode public function Tests the interaction between full and default view modes.
LayoutBuilderTest::testNonBundleEntityType public function Tests the Layout Builder UI for an entity type without a bundle.
LayoutBuilderTest::testNonDefaultViewMode public function Tests that a non-default view mode works as expected.
LayoutBuilderTest::testOverrides public function Tests functionality of Layout Builder for overrides.
LayoutBuilderTest::testOverridesFormAlter public function Tests a custom alter of the overrides form.
LayoutBuilderTest::testOverridesWithoutDefaultsAccess public function Tests Layout Builder overrides without access to edit the default layout.
LayoutBuilderTest::testPendingRevision public function Tests loading a pending revision in the Layout Builder UI.
LayoutBuilderTest::testPluginDependencies public function Tests that component's dependencies are respected during removal.
LayoutBuilderTest::testPreserverEntityValues public function Tests that the Layout Builder preserves entity values.
LayoutBuilderTest::testRemovingAllSections public function Tests removing all sections from overrides and defaults.
LayoutBuilderTest::testRemovingSectionWithoutLayoutLabel public function Tests removing section without layout label configuration.
LayoutBuilderTest::testSectionLabels public function Tests the functionality of custom section labels.
LayoutBuilderTest::testSimpleConfigBasedLayout public function Tests a config-based implementation of Layout Builder.
NodeCreationTrait::createNode protected function Creates a node based on default settings. Aliased as: drupalCreateNode
NodeCreationTrait::getNodeByTitle public function Get a node from the database based on its title. Aliased as: drupalGetNodeByTitle
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
RandomGeneratorTrait::$randomGenerator protected property The random generator.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers. 1
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
RandomGeneratorTrait::randomStringValidate public function Callback for random string validation.
RefreshVariablesTrait::refreshVariables protected function Refreshes in-memory configuration and state information. 1
SessionTestTrait::$sessionName protected property The name of the session cookie.
SessionTestTrait::generateSessionName protected function Generates a session cookie name.
SessionTestTrait::getSessionName protected function Returns the session name in use on the child site.
StorageCopyTrait::replaceStorageContents protected static function Copy the configuration from one storage to another and remove stale items.
TestRequirementsTrait::checkModuleRequirements private function Checks missing module requirements.
TestRequirementsTrait::checkRequirements protected function Check module requirements for the Drupal use case. 1
TestRequirementsTrait::getDrupalRoot protected static function Returns the Drupal root directory.
TestSetupTrait::$configSchemaCheckerExclusions protected static property An array of config object names that are excluded from schema checking.
TestSetupTrait::$container protected property The dependency injection container used in the test.
TestSetupTrait::$kernel protected property The DrupalKernel instance used in the test.
TestSetupTrait::$originalSite protected property The site directory of the original parent site.
TestSetupTrait::$privateFilesDirectory protected property The private file directory for the test environment.
TestSetupTrait::$publicFilesDirectory protected property The public file directory for the test environment.
TestSetupTrait::$siteDirectory protected property The site directory of this test run.
TestSetupTrait::$strictConfigSchema protected property Set to TRUE to strict check all configuration saved. 1
TestSetupTrait::$tempFilesDirectory protected property The temporary file directory for the test environment.
TestSetupTrait::$testId protected property The test run ID.
TestSetupTrait::changeDatabasePrefix protected function Changes the database connection to the prefixed one.
TestSetupTrait::getConfigSchemaExclusions protected function Gets the config schema exclusions for this test.
TestSetupTrait::getDatabaseConnection public static function Returns the database connection to the site running Simpletest.
TestSetupTrait::prepareDatabasePrefix protected function Generates a database prefix for running tests. 1
UiHelperTrait::$loggedInUser protected property The current user logged in using the Mink controlled browser.
UiHelperTrait::$maximumMetaRefreshCount protected property The number of meta refresh redirects to follow, or NULL if unlimited.
UiHelperTrait::$metaRefreshCount protected property The number of meta refresh redirects followed during ::drupalGet().
UiHelperTrait::assertSession public function Returns WebAssert object. 1
UiHelperTrait::buildUrl protected function Builds an absolute URL from a system path or a URL object.
UiHelperTrait::checkForMetaRefresh protected function Checks for meta refresh tag and if found call drupalGet() recursively.
UiHelperTrait::click protected function Clicks the element with the given CSS selector.
UiHelperTrait::clickLink protected function Follows a link by complete name.
UiHelperTrait::cssSelect protected function Searches elements using a CSS selector in the raw content.
UiHelperTrait::cssSelectToXpath protected function Translates a CSS expression to its XPath equivalent.
UiHelperTrait::drupalGet protected function Retrieves a Drupal path or an absolute path. 2
UiHelperTrait::drupalLogin protected function Logs in a user using the Mink controlled browser.
UiHelperTrait::drupalLogout protected function Logs a user out of the Mink controlled browser and confirms.
UiHelperTrait::drupalPostForm Deprecated protected function Executes a form submission.
UiHelperTrait::drupalUserIsLoggedIn protected function Returns whether a given user account is logged in.
UiHelperTrait::getAbsoluteUrl protected function Takes a path and returns an absolute path.
UiHelperTrait::getTextContent protected function Retrieves the plain-text content from the current page.
UiHelperTrait::getUrl protected function Get the current URL from the browser.
UiHelperTrait::isTestUsingGuzzleClient protected function Determines if test is using DrupalTestBrowser.
UiHelperTrait::prepareRequest protected function Prepare for a request to testing site. 1
UiHelperTrait::submitForm protected function Fills and submits a form.
UserCreationTrait::checkPermissions protected function Checks whether a given list of permission names is valid.
UserCreationTrait::createAdminRole protected function Creates an administrative role.
UserCreationTrait::createRole protected function Creates a role with specified permissions. Aliased as: drupalCreateRole
UserCreationTrait::createUser protected function Create a user with a given set of permissions. Aliased as: drupalCreateUser
UserCreationTrait::grantPermissions protected function Grant permissions to a user role.
UserCreationTrait::setCurrentUser protected function Switch the current logged in user.
UserCreationTrait::setUpCurrentUser protected function Creates a random user account and sets it as current user.
XdebugRequestTrait::extractCookiesFromRequest protected function Adds xdebug cookies, from request setup.