You are here

protected function BlockFormMessagesTest::assertMessagesDisplayed in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/layout_builder/tests/src/FunctionalJavascript/BlockFormMessagesTest.php \Drupal\Tests\layout_builder\FunctionalJavascript\BlockFormMessagesTest::assertMessagesDisplayed()

Asserts that the validation messages are shown correctly.

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 95

Class

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

Namespace

Drupal\Tests\layout_builder\FunctionalJavascript

Code

protected function assertMessagesDisplayed() {
  $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));
}