function MoveBlockFormTest::testMoveBlock

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

Tests moving a block.

File

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

Class

MoveBlockFormTest
Tests moving blocks via the form.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testMoveBlock() {
  $page = $this->getSession()
    ->getPage();
  // Reorder body field in current region.
  $this->openBodyMoveForm(1, 'content', [
    'Links',
    'Body (current)',
  ]);
  $this->moveBlockWithKeyboard('up', 'Body (current)', [
    'Body (current)*',
    'Links',
  ]);
  $page->pressButton('Move');
  $expected_block_order = [
    '.block-field-blocknodebundle-with-section-fieldbody',
    '.block-extra-field-blocknodebundle-with-section-fieldlinks',
  ];
  $this->assertRegionBlocksOrder(1, 'content', $expected_block_order);
  $page->pressButton('Save layout');
  $page->clickLink('Manage layout');
  $this->assertRegionBlocksOrder(1, 'content', $expected_block_order);
  // Move the body block into the first region above existing block.
  $this->openBodyMoveForm(1, 'content', [
    'Body (current)',
    'Links',
  ]);
  $page->selectFieldOption('Region', '0:first');
  $this->assertBlockTable([
    'Powered by Drupal',
    'Body (current)',
  ]);
  $this->moveBlockWithKeyboard('up', 'Body', [
    'Body (current)*',
    'Powered by Drupal',
  ]);
  $page->pressButton('Move');
  $expected_block_order = [
    '.block-field-blocknodebundle-with-section-fieldbody',
    '.block-system-powered-by-block',
  ];
  $this->assertRegionBlocksOrder(0, 'first', $expected_block_order);
  // Ensure the body block is no longer in the content region.
  $this->assertRegionBlocksOrder(1, 'content', [
    '.block-extra-field-blocknodebundle-with-section-fieldlinks',
  ]);
  $page->pressButton('Save layout');
  $page->clickLink('Manage layout');
  $this->assertRegionBlocksOrder(0, 'first', $expected_block_order);
  // Move into the second region that has no existing blocks.
  $this->openBodyMoveForm(0, 'first', [
    'Body (current)',
    'Powered by Drupal',
  ]);
  $page->selectFieldOption('Region', '0:second');
  $this->assertBlockTable([
    'Body (current)',
  ]);
  $page->pressButton('Move');
  $this->assertRegionBlocksOrder(0, 'second', [
    '.block-field-blocknodebundle-with-section-fieldbody',
  ]);
}

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