JavascriptGetDrupalSettingsTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Drupal\FunctionalJavascriptTests;
  3. /**
  4. * Tests Drupal settings retrieval in JavascriptTestBase tests.
  5. *
  6. * @group javascript
  7. */
  8. class JavascriptGetDrupalSettingsTest extends WebDriverTestBase {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. protected static $modules = ['test_page_test'];
  13. /**
  14. * Tests retrieval of Drupal settings.
  15. *
  16. * @see \Drupal\FunctionalJavascriptTests\WebDriverTestBase::getDrupalSettings()
  17. */
  18. public function testGetDrupalSettings() {
  19. $this->drupalLogin($this->drupalCreateUser());
  20. $this->drupalGet('test-page');
  21. // Check that we can read the JS settings.
  22. $js_settings = $this->getDrupalSettings();
  23. $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']);
  24. // Dynamically change the setting using Javascript.
  25. $script = <<<EndOfScript
  26. (function () {
  27. drupalSettings['test-setting'] = 'foo';
  28. })();
  29. EndOfScript;
  30. $this->getSession()->evaluateScript($script);
  31. // Check that the setting has been changed.
  32. $js_settings = $this->getDrupalSettings();
  33. $this->assertSame('foo', $js_settings['test-setting']);
  34. }
  35. }