You are here

public function MoveBlockRestrictionTest::testLayoutLibraryMovePluginBlock in Layout Builder Restrictions 8.2

Move a plugin block in the Layout Library.

File

tests/src/FunctionalJavascript/MoveBlockRestrictionTest.php, line 68

Class

MoveBlockRestrictionTest
Tests moving blocks via the form.

Namespace

Drupal\Tests\layout_builder_restrictions\FunctionalJavascript

Code

public function testLayoutLibraryMovePluginBlock() {
  $page = $this
    ->getSession()
    ->getPage();
  $assert_session = $this
    ->assertSession();
  $this
    ->drupalPlaceBlock('local_actions_block');
  $this
    ->drupalPlaceBlock('local_tasks_block');

  // Add a layout to the library.
  $this
    ->drupalGet('admin/structure/layouts');
  $page
    ->clickLink('Edit layout');
  $page
    ->clickLink('Add section');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Choose a layout for this section'));
  $page
    ->clickLink('One column');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Configure section'));
  $page
    ->pressButton('Add section');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('You have unsaved changes'));
  $page
    ->clickLink('Add block');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Choose a block'));
  $page
    ->clickLink('Powered by Drupal');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Configure block'));
  $page
    ->fillField('settings[label]', 'Powered by Drupal');
  $page
    ->checkField('settings[label_display]');
  $page
    ->pressButton('Add block');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', '.block-system-powered-by-block'));
  $page
    ->clickLink('Add block');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Choose a block'));
  $page
    ->clickLink('Site branding');
  $this
    ->assertNotEmpty($assert_session
    ->waitForText('Configure block'));
  $page
    ->fillField('settings[label]', 'Site branding');
  $page
    ->checkField('settings[label_display]');
  $page
    ->pressButton('Add block');
  $this
    ->assertNotEmpty($assert_session
    ->waitForElementVisible('css', '.block-system-branding-block'));
  $page
    ->pressButton('Save layout');

  // Two blocks have been saved to the Layout, in the order
  // Powered by Drupal, Site branding.
  // Change the order & save.
  $this
    ->drupalGet('admin/structure/layouts');
  $page
    ->clickLink('Edit layout');

  // Move the body block into the first region above existing block.
  $this
    ->openMoveForm(0, 'content', 'block-system-powered-by-block', [
    'Powered by Drupal (current)',
    'Site branding',
  ]);
  $page
    ->selectFieldOption('Region', '0:content');
  $this
    ->assertBlockTable([
    'Powered by Drupal (current)',
    'Site branding',
  ]);
  $this
    ->moveBlockWithKeyboard('up', 'Site branding', [
    'Site branding*',
    'Powered by Drupal (current)',
  ]);
  $page
    ->pressButton('Move');
  $this
    ->assertSession()
    ->assertWaitOnAjaxRequest();
  $page
    ->pressButton('Save layout');

  // Confirm the order has successfully changed.
  $this
    ->drupalGet('admin/structure/layouts');
  $page
    ->clickLink('Edit layout');
  $expected_block_order = [
    '.block-system-branding-block',
    '.block-system-powered-by-block',
  ];
  $this
    ->assertRegionBlocksOrder(0, 'content', $expected_block_order);
}