class JsMessageWhitespaceTest
Same name and namespace in other branches
- main core/tests/Drupal/FunctionalJavascriptTests/Core/JsMessageWhitespaceTest.php \Drupal\FunctionalJavascriptTests\Core\JsMessageWhitespaceTest
Tests that message.js handles whitespace in empty message wrappers.
Attributes
#[Group('Javascript')]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\FunctionalJavascriptTests\Core\JsMessageWhitespaceTest extends \Drupal\FunctionalJavascriptTests\WebDriverTestBase
- class \Drupal\FunctionalJavascriptTests\WebDriverTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of JsMessageWhitespaceTest
File
-
core/
tests/ Drupal/ FunctionalJavascriptTests/ Core/ JsMessageWhitespaceTest.php, line 14
Namespace
Drupal\FunctionalJavascriptTests\CoreView source
class JsMessageWhitespaceTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'js_message_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that message.js handles whitespace in empty message wrappers.
*
* This test verifies that getting the message wrapper does not fail when
* themes have a new line or something in their template.
*/
public function testMessageClearWithWhitespace() : void {
$this->drupalGet('js_message_test_link');
$this->assertSession()
->pageTextContains('JsMessageLinks');
// Simulate real-world scenario: theme template outputs whitespace
// in the messages wrapper but no actual message elements.
$this->getSession()
->executeScript("\n var wrapper = document.querySelector('[data-drupal-messages]');\n if (wrapper) {\n // Clear existing content\n wrapper.innerHTML = '';\n // Add whitespace like a theme template might (newlines, spaces, tabs)\n wrapper.innerHTML = '\\n \\t\\n \\n';\n }\n ");
// Drupal.Message should work without errors when the wrapper contains only
// whitespace.
$this->getSession()
->executeScript("\n try {\n var msg = new Drupal.Message();\n msg.add('Test message', {type: 'status'});\n msg.clear();\n // Mark success if no errors thrown\n document.body.setAttribute('data-message-test-success', 'true');\n } catch (e) {\n // Mark failure if any errors thrown\n document.body.setAttribute('data-message-test-error', e.toString());\n }\n ");
// Verify the test completed successfully without JavaScript errors.
$error = $this->getSession()
->evaluateScript("\n return document.body.getAttribute('data-message-test-error');\n ");
$this->assertNull($error);
// Verify the wrapper still exists after the operations.
$this->assertSession()
->elementExists('css', '[data-drupal-messages]');
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.