JavascriptGetDrupalSettingsTest.php in Drupal 10
File
core/tests/Drupal/FunctionalJavascriptTests/JavascriptGetDrupalSettingsTest.php
View source
<?php
namespace Drupal\FunctionalJavascriptTests;
class JavascriptGetDrupalSettingsTest extends WebDriverTestBase {
protected static $modules = [
'test_page_test',
];
protected $defaultTheme = 'stark';
public function testGetDrupalSettings() {
$this
->drupalLogin($this
->drupalCreateUser());
$this
->drupalGet('test-page');
$js_settings = $this
->getDrupalSettings();
$this
->assertSame('azAZ09();.,\\\\/-_{}', $js_settings['test-setting']);
$script = <<<EndOfScript
(function () {
drupalSettings['test-setting'] = 'foo';
})();
EndOfScript;
$this
->getSession()
->evaluateScript($script);
$js_settings = $this
->getDrupalSettings();
$this
->assertSame('foo', $js_settings['test-setting']);
}
}