3 namespace Drupal\FunctionalJavascriptTests;
6 * Tests Drupal settings retrieval in JavascriptTestBase tests.
10 class JavascriptGetDrupalSettingsTest extends WebDriverTestBase {
15 protected static $modules = ['test_page_test'];
18 * Tests retrieval of Drupal settings.
20 * @see \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()
22 public function testGetDrupalSettings() {
23 $this->drupalLogin($this->drupalCreateUser());
24 $this->drupalGet('test-page');
26 // Check that we can read the JS settings.
27 $js_settings = $this->getDrupalSettings();
28 $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
30 // Dynamically change the setting using Javascript.
31 $script = <<<EndOfScript
33 drupalSettings['test-setting'] = 'foo';
37 $this->getSession()->evaluateScript($script);
39 // Check that the setting has been changed.
40 $js_settings = $this->getDrupalSettings();
41 $this->assertSame('foo', $js_settings['test-setting']);