comparison core/tests/Drupal/FunctionalJavascriptTests/JavascriptGetDrupalSettingsTest.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php
2
3 namespace Drupal\FunctionalJavascriptTests;
4
5 /**
6 * Tests Drupal settings retrieval in JavascriptTestBase tests.
7 *
8 * @group javascript
9 */
10 class JavascriptGetDrupalSettingsTest extends WebDriverTestBase {
11
12 /**
13 * {@inheritdoc}
14 */
15 protected static $modules = ['test_page_test'];
16
17 /**
18 * Tests retrieval of Drupal settings.
19 *
20 * @see \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()
21 */
22 public function testGetDrupalSettings() {
23 $this->drupalLogin($this->drupalCreateUser());
24 $this->drupalGet('test-page');
25
26 // Check that we can read the JS settings.
27 $js_settings = $this->getDrupalSettings();
28 $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
29
30 // Dynamically change the setting using Javascript.
31 $script = <<<EndOfScript
32 (function () {
33 drupalSettings['test-setting'] = 'foo';
34 })();
35 EndOfScript;
36
37 $this->getSession()->evaluateScript($script);
38
39 // Check that the setting has been changed.
40 $js_settings = $this->getDrupalSettings();
41 $this->assertSame('foo', $js_settings['test-setting']);
42 }
43
44 }