You are here

protected function JsMessageTest::assertCurrentMessages in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageTest::assertCurrentMessages()
  2. 9 core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageTest::assertCurrentMessages()

Asserts that currently shown messages match expected messages.

@internal

Parameters

array $expected_messages: Expected messages.

string $messagesSelector: The css selector for the containing messages element.

1 call to JsMessageTest::assertCurrentMessages()
JsMessageTest::testAddRemoveMessages in core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php
Tests click on links to show messages and remove messages.

File

core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php, line 114

Class

JsMessageTest
Tests core/drupal.message library.

Namespace

Drupal\FunctionalJavascriptTests\Core

Code

protected function assertCurrentMessages(array $expected_messages, string $messagesSelector) : void {
  $expected_messages = array_values($expected_messages);
  $current_messages = [];
  if ($message_divs = $this
    ->getSession()
    ->getPage()
    ->findAll('css', "{$messagesSelector} .messages")) {
    foreach ($message_divs as $message_div) {

      /** @var \Behat\Mink\Element\NodeElement $message_div */
      $current_messages[] = $message_div
        ->getText();
    }
  }

  // Check that each message text contains the expected text.
  if (count($expected_messages) !== count($current_messages)) {
    $this
      ->fail('The expected messages array contains a different number of values than the current messages array.');
  }
  for ($i = 0; $i < count($expected_messages); $i++) {
    $this
      ->assertStringContainsString($expected_messages[$i], $current_messages[$i]);
  }
}