PlaceholderMessageTest.php in Drupal 9
File
core/modules/system/tests/src/Functional/Render/PlaceholderMessageTest.php
View source
<?php
namespace Drupal\Tests\system\Functional\Render;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class PlaceholderMessageTest extends BrowserTestBase {
protected static $modules = [
'render_placeholder_message_test',
];
protected $defaultTheme = 'stark';
public function testMessagePlaceholder() {
$messages_markup = '<div role="contentinfo" aria-label="Status message"';
$test_routes = [
'render_placeholder_message_test.first',
'render_placeholder_message_test.middle',
'render_placeholder_message_test.last',
];
$assert = $this
->assertSession();
foreach ($test_routes as $route) {
$this
->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
$assert
->responseNotContains($messages_markup);
$this
->drupalGet(Url::fromRoute($route));
$assert
->elementContains('css', 'p.logged-message:nth-of-type(1)', 'Message: P1');
$assert
->elementContains('css', 'p.logged-message:nth-of-type(2)', 'Message: P2');
$assert
->responseContains($messages_markup);
$assert
->elementExists('css', 'div[aria-label="Status message"] ul');
$assert
->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(1)', 'P1');
$assert
->elementContains('css', 'div[aria-label="Status message"] ul li:nth-of-type(2)', 'P2');
$this
->drupalGet(Url::fromRoute('render_placeholder_message_test.queued'));
$assert
->responseNotContains($messages_markup);
}
}
}