protected function JsMessageTest::assertCurrentMessages in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageTest::assertCurrentMessages()
Asserts that currently shown messages match expected messages.
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 112
Class
- JsMessageTest
- Tests core/drupal.message library.
Namespace
Drupal\FunctionalJavascriptTests\CoreCode
protected function assertCurrentMessages(array $expected_messages, $messagesSelector) {
$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]);
}
}