diff --git a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php index 796360f..4d1906e 100644 --- a/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php +++ b/core/modules/simpletest/tests/src/Functional/BrowserTestBaseTest.php @@ -36,6 +36,10 @@ public function testGoTo() { // Response includes cache tags that we can assert. $this->assertSession()->responseHeaderEquals('X-Drupal-Cache-Tags', 'rendered'); + // Test that we can read the JS settings. + $js_settings = $this->getDrupalSettings(); + $this->assertSame('azAZ09();.,\\\/-_{}', $js_settings['test-setting']); + // Test drupalGet with a url object. $url = Url::fromRoute('test_page_test.render_title'); $this->drupalGet($url); diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 3beb32f..c0a82d0 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -7,6 +7,7 @@ use Behat\Mink\Mink; use Behat\Mink\Session; use Drupal\Component\FileCache\FileCacheFactory; +use Drupal\Component\Serialization\Json; use Drupal\Component\Serialization\Yaml; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\SafeMarkup; @@ -1768,6 +1769,20 @@ protected function getUrl() { } /** + * Gets the JavaScript drupalSettings variable for the currently-loaded page. + * + * @return array + * The JSON decoded drupalSettings value from the current page. + */ + protected function getDrupalSettings() { + $html = $this->getSession()->getPage()->getHtml(); + if (preg_match('@@', $html, $matches)) { + return Json::decode($matches[1]); + } + return []; + } + + /** * {@inheritdoc} */ public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) {