function BlockFormMessagesTest::assertMessagesDisplayed

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

Asserts that the validation messages are shown correctly.

@internal

1 call to BlockFormMessagesTest::assertMessagesDisplayed()
BlockFormMessagesTest::testValidationMessage in core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php
Tests that validation messages are shown on the block form.

File

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

Class

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

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function assertMessagesDisplayed() : void {
    $assert_session = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $messages_locator = '#drupal-off-canvas .messages--error';
    $assert_session->assertWaitOnAjaxRequest();
    $this->assertNotEmpty($assert_session->waitForElement('css', $messages_locator));
    $assert_session->elementTextContains('css', $messages_locator, 'Title field is required.');
    
    /** @var \Behat\Mink\Element\NodeElement[] $top_form_elements */
    $top_form_elements = $page->findAll('css', '#drupal-off-canvas form > *');
    // Ensure the messages are the first top level element of the form.
    $this->assertStringContainsStringIgnoringCase('Title field is required.', $top_form_elements[0]->getText());
    $this->assertGreaterThan(4, count($top_form_elements));
}

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