function BlockDragTest::testDragAndDropBlocks

Same name in other branches
  1. 10 core/modules/block/tests/src/FunctionalJavascript/BlockDragTest.php \Drupal\Tests\block\FunctionalJavascript\BlockDragTest::testDragAndDropBlocks()

Tests drag and drop blocks.

File

core/modules/block/tests/src/FunctionalJavascript/BlockDragTest.php, line 40

Class

BlockDragTest
Tests drag and drop blocks on block layout page.

Namespace

Drupal\Tests\block\FunctionalJavascript

Code

public function testDragAndDropBlocks() : void {
    // Resize window to work around https://github.com/bitovi/syn/issues/164.
    $this->getSession()
        ->resizeWindow(1024, 2048);
    $this->drupalGet('admin/structure/block');
    $assertSession = $this->assertSession();
    $session = $this->getSession();
    $page = $session->getPage();
    // Test if drag orientation on block layout page was applied with success.
    $this->assertNotEmpty($assertSession->waitForElementVisible('css', '.tabledrag-handle-y'));
    // Dragging main-menu and status messages to header region.
    $siteBranding = $this->getDragRow($page, 'edit-blocks-olivero-site-branding');
    $mainMenuRow = $this->getDragRow($page, 'edit-blocks-olivero-main-menu');
    $mainMenuRow->dragTo($siteBranding);
    $messages = $this->getDragRow($page, 'edit-blocks-olivero-messages');
    $messages->dragTo($siteBranding);
    // Test if both blocks above was positioned on the header region.
    $this->assertEquals('header', $page->findField('edit-blocks-olivero-main-menu-region')
        ->getValue(), 'Main menu should be positioned on header region');
    $this->assertEquals('header', $page->findField('edit-blocks-olivero-messages-region')
        ->getValue(), 'Status messages should be positioned on header region');
    // Check if the message unsaved changed appears.
    $assertSession->pageTextContains('You have unsaved changes.');
    // Test if the message for empty regions appear after drag the unique block on the region.
    $noBlockMessage = $page->find('css', 'tr[data-drupal-selector="edit-blocks-region-primary-menu-message"] td')
        ->getText();
    $this->assertSession()
        ->assert($noBlockMessage === 'No blocks in this region', 'Region primary menu should be empty.');
    // Testing drag row to an empty region.
    $pageTitle = $this->getDragRow($page, 'edit-blocks-olivero-page-title');
    $heroRegion = $page->find('css', 'tr[data-drupal-selector="edit-blocks-region-hero-message"]');
    $pageTitle->dragTo($heroRegion);
    $this->assertSession()
        ->assert($page->find('css', 'tr[data-drupal-selector="edit-blocks-region-hero-message"] td')
        ->getText() !== 'No blocks in this region', "Region here shouldn't be empty");
}

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