function BrowserTestBase::getDrupalSettings

Same name and namespace in other branches
  1. 10 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDrupalSettings()
  2. 11.x core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDrupalSettings()

Gets the JavaScript drupalSettings variable for the currently-loaded page.

Return value

array The JSON decoded drupalSettings value from the current page.

10 calls to BrowserTestBase::getDrupalSettings()
AccessDeniedTest::testAccessDenied in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
HistoryTest::testHistory in core/modules/history/tests/src/Functional/HistoryTest.php
Verifies that the history endpoints work.
LanguageSwitchingTest::doTestLanguageBlockAuthenticated in core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
For authenticated users, the "active" class is set by JavaScript.
LanguageSwitchingTest::doTestLanguageLinkActiveClassAuthenticated in core/modules/language/tests/src/Functional/LanguageSwitchingTest.php
For authenticated users, the "active" class is set by JavaScript.
NoJavaScriptAnonymousTest::assertNoJavaScript in core/modules/system/tests/src/Functional/Common/NoJavaScriptAnonymousTest.php
Passes if no JavaScript is found on the page.

... See full list

File

core/tests/Drupal/Tests/BrowserTestBase.php, line 644

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\Tests

Code

protected function getDrupalSettings() {
  $html = $this->getSession()
    ->getPage()
    ->getContent();
  if (preg_match('@<script type="application/json" data-drupal-selector="drupal-settings-json">([^<]*)</script>@', $html, $matches)) {
    return Json::decode($matches[1]);
  }
  return [];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.