function JsMessageTest::assertCurrentMessages

Same name in other branches
  1. 9 core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageTest::assertCurrentMessages()
  2. 8.9.x core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageTest::assertCurrentMessages()
  3. 10 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 116

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]);
    }
}

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