3 namespace Drupal\Tests\simpletest\FunctionalJavascript;
5 use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
8 * Tests Drupal settings retrieval in JavascriptTestBase tests.
12 class JavascriptGetDrupalSettingsTest extends JavascriptTestBase {
17 protected static $modules = ['test_page_test'];
20 * Tests retrieval of Drupal settings.
22 * @see \Drupal\FunctionalJavascriptTests\JavascriptTestBase::getDrupalSettings()
24 public function testGetDrupalSettings() {
25 $this->drupalLogin($this->drupalCreateUser());
26 $this->drupalGet('test-page');
28 // Check that we can read the JS settings.
29 $js_settings = $this->getDrupalSettings();
30 $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
32 // Dynamically change the setting using Javascript.
33 $script = <<<EndOfScript
35 drupalSettings['test-setting'] = 'foo';
39 $this->getSession()->evaluateScript($script);
41 // Check that the setting has been changed.
42 $js_settings = $this->getDrupalSettings();
43 $this->assertSame('foo', $js_settings['test-setting']);