Commit dafc72c9 authored by catch's avatar catch

Issue #3057289 by alexpott: Move JsMessageTestCases out of src/Tests

parent 1305cbea
<?php
namespace Drupal\system\Tests;
/**
* Test cases for JS Messages tests.
*/
class JsMessageTestCases {
/**
* Gets the test types.
*
* @return string[]
* The test types.
*/
public static function getTypes() {
return ['status', 'error', 'warning'];
}
/**
* Gets the test messages selectors.
*
* @return string[]
* The test test messages selectors.
*
* @see core/modules/system/tests/themes/test_messages/templates/status-messages.html.twig
*/
public static function getMessagesSelectors() {
return ['', '[data-drupal-messages-other]'];
}
}
......@@ -2,13 +2,33 @@
namespace Drupal\js_message_test\Controller;
use Drupal\system\Tests\JsMessageTestCases;
/**
* Test Controller to show message links.
*/
class JSMessageTestController {
/**
* Gets the test types.
*
* @return string[]
* The test types.
*/
public static function getTypes() {
return ['status', 'error', 'warning'];
}
/**
* Gets the test messages selectors.
*
* @return string[]
* The test test messages selectors.
*
* @see core/modules/system/tests/themes/test_messages/templates/status-messages.html.twig
*/
public static function getMessagesSelectors() {
return ['', '[data-drupal-messages-other]'];
}
/**
* Displays links to show messages via Javascript.
*
......@@ -17,7 +37,7 @@ class JSMessageTestController {
*/
public function messageLinks() {
$buttons = [];
foreach (JsMessageTestCases::getMessagesSelectors() as $messagesSelector) {
foreach (static::getMessagesSelectors() as $messagesSelector) {
$buttons[$messagesSelector] = [
'#type' => 'details',
'#open' => TRUE,
......@@ -26,7 +46,7 @@ public function messageLinks() {
'data-drupal-messages-area' => $messagesSelector,
],
];
foreach (JsMessageTestCases::getTypes() as $type) {
foreach (static::getTypes() as $type) {
$buttons[$messagesSelector]["add-$type"] = [
'#type' => 'html_tag',
'#tag' => 'button',
......@@ -52,7 +72,7 @@ public function messageLinks() {
}
}
// Add alternative message area.
$buttons[JsMessageTestCases::getMessagesSelectors()[1]]['messages-other-area'] = [
$buttons[static::getMessagesSelectors()[1]]['messages-other-area'] = [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
......@@ -128,8 +148,8 @@ public function messageLinks() {
],
'drupalSettings' => [
'testMessages' => [
'selectors' => JsMessageTestCases::getMessagesSelectors(),
'types' => JsMessageTestCases::getTypes(),
'selectors' => static::getMessagesSelectors(),
'types' => static::getTypes(),
],
],
],
......
......@@ -3,7 +3,7 @@
namespace Drupal\FunctionalJavascriptTests\Core;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\system\Tests\JsMessageTestCases;
use Drupal\js_message_test\Controller\JSMessageTestController;
/**
* Tests core/drupal.messages library.
......@@ -38,9 +38,9 @@ public function testAddRemoveMessages() {
$this->drupalGet('js_message_test_link');
$current_messages = [];
foreach (JsMessageTestCases::getMessagesSelectors() as $messagesSelector) {
foreach (JSMessageTestController::getMessagesSelectors() as $messagesSelector) {
$web_assert->elementExists('css', $messagesSelector);
foreach (JsMessageTestCases::getTypes() as $type) {
foreach (JSMessageTestController::getTypes() as $type) {
$this->click('[id="add-' . $messagesSelector . '-' . $type . '"]');
$selector = "$messagesSelector .messages.messages--$type";
$msg_element = $web_assert->waitForElementVisible('css', $selector);
......@@ -50,7 +50,7 @@ public function testAddRemoveMessages() {
$this->assertCurrentMessages($current_messages, $messagesSelector);
}
// Remove messages 1 by 1 and confirm the messages are expected.
foreach (JsMessageTestCases::getTypes() as $type) {
foreach (JSMessageTestController::getTypes() as $type) {
$this->click('[id="remove-' . $messagesSelector . '-' . $type . '"]');
$selector = "$messagesSelector .messages.messages--$type";
// The message for this selector should not be on the page.
......@@ -59,9 +59,9 @@ public function testAddRemoveMessages() {
}
}
$messagesSelector = JsMessageTestCases::getMessagesSelectors()[0];
$messagesSelector = JSMessageTestController::getMessagesSelectors()[0];
$current_messages = [];
$types = JsMessageTestCases::getTypes();
$types = JSMessageTestController::getTypes();
$nb_messages = count($types) * 2;
for ($i = 0; $i < $nb_messages; $i++) {
$current_messages[] = "This is message number $i of the type, {$types[$i % count($types)]}. You be the the judge of its importance.";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment