function BlockFormMessagesTest::testValidationMessage

Same name in other branches
  1. 9 core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest::testValidationMessage()
  2. 8.9.x core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest::testValidationMessage()
  3. 10 core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest::testValidationMessage()

Tests that validation messages are shown on the block form.

File

core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php, line 51

Class

BlockFormMessagesTest
Tests that messages appear in the off-canvas dialog with configuring blocks.

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

public function testValidationMessage() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->drupalLogin($this->drupalCreateUser([
        'access contextual links',
        'configure any layout',
    ]));
    $this->drupalGet('node/1/layout');
    $page->findLink('Add block')
        ->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas .block-categories'));
    $page->findLink('Powered by Drupal')
        ->click();
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
    $page->findField('Title')
        ->setValue('');
    $page->findButton('Add block')
        ->click();
    $this->assertMessagesDisplayed();
    $page->findField('Title')
        ->setValue('New title');
    $page->pressButton('Add block');
    $block_css_locator = '#layout-builder .block-system-powered-by-block';
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', $block_css_locator));
    $assert_session->assertNoElementAfterWait('css', '#drupal-off-canvas');
    $assert_session->assertWaitOnAjaxRequest();
    $this->drupalGet($this->getUrl());
    $page->findButton('Save layout')
        ->click();
    $this->assertNotEmpty($assert_session->waitForElement('css', 'div:contains("The layout override has been saved")'));
    // Ensure that message are displayed when configuring an existing block.
    $this->drupalGet('node/1/layout');
    $this->clickContextualLink($block_css_locator, 'Configure', TRUE);
    $this->assertNotEmpty($assert_session->waitForElementVisible('css', '#drupal-off-canvas [name="settings[label]"]'));
    $page->findField('Title')
        ->setValue('');
    $page->findButton('Update')
        ->click();
    $this->assertMessagesDisplayed();
}

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