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