function MoveBlockFormTest::setUp

Same name and namespace in other branches
  1. 11.x core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\MoveBlockFormTest::setUp()
  2. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\MoveBlockFormTest::setUp()
  3. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\MoveBlockFormTest::setUp()

File

core/modules/layout_builder/tests/src/FunctionalJavascript/MoveBlockFormTest.php, line 42

Class

MoveBlockFormTest
Tests moving blocks via the form.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function setUp() {
  parent::setUp();
  $page = $this->getSession()
    ->getPage();
  $assert_session = $this->assertSession();
  $this->createContentType([
    'type' => 'bundle_with_section_field',
  ]);
  $this->drupalLogin($this->drupalCreateUser([
    'configure any layout',
    'administer node display',
    'administer node fields',
    'access contextual links',
  ]));
  // Enable layout builder.
  $this->drupalPostForm(static::FIELD_UI_PREFIX . '/display/default', [
    'layout[enabled]' => TRUE,
  ], 'Save');
  $page->clickLink('Manage layout');
  $assert_session->addressEquals(static::FIELD_UI_PREFIX . '/display/default/layout');
  $expected_block_order = [
    '.block-extra-field-blocknodebundle-with-section-fieldlinks',
    '.block-field-blocknodebundle-with-section-fieldbody',
  ];
  $this->assertRegionBlocksOrder(0, 'content', $expected_block_order);
  // Add a top section using the Two column layout.
  $page->clickLink('Add section');
  $assert_session->waitForElementVisible('css', '#drupal-off-canvas');
  $assert_session->assertWaitOnAjaxRequest();
  $page->clickLink('Two column');
  $assert_session->assertWaitOnAjaxRequest();
  $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'input[value="Add section"]'));
  $page->pressButton('Add section');
  $this->assertRegionBlocksOrder(1, 'content', $expected_block_order);
  // Add a 'Powered by Drupal' block in the 'first' region of the new section.
  $first_region_block_locator = '[data-layout-delta="0"].layout--twocol-section [data-region="first"] [data-layout-block-uuid]';
  $assert_session->elementNotExists('css', $first_region_block_locator);
  $assert_session->elementExists('css', '[data-layout-delta="0"].layout--twocol-section [data-region="first"] .layout-builder__add-block')
    ->click();
  $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas a:contains("Powered by Drupal")'));
  $assert_session->assertWaitOnAjaxRequest();
  $page->clickLink('Powered by Drupal');
  $this->assertNotEmpty($assert_session->waitForElementVisible('css', 'input[value="Add block"]'));
  $assert_session->assertWaitOnAjaxRequest();
  $page->pressButton('Add block');
  $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
  $this->assertNotEmpty($assert_session->waitForElementVisible('css', $first_region_block_locator));
  // Ensure the request has completed before the test starts.
  $assert_session->assertWaitOnAjaxRequest();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.