You are here

protected function BlockFormMessagesTest::assertMessagesDisplayed in Drupal 8

Same name and namespace in other branches
  1. 9 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 98

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
    ->assertTrue(stristr($top_form_elements[0]
    ->getText(), 'Title field is required.') !== FALSE);
  $this
    ->assertGreaterThan(4, count($top_form_elements));
}