function BrowserTestBase::getDrupalSettings

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDrupalSettings()
  2. 10 core/tests/Drupal/Tests/BrowserTestBase.php \Drupal\Tests\BrowserTestBase::getDrupalSettings()
  3. 8.9.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.

16 calls to BrowserTestBase::getDrupalSettings()
AccessDeniedTest::testAccessDenied in core/modules/system/tests/src/Functional/System/AccessDeniedTest.php
Tests access denied functionality.
BigPipeTest::testBigPipe in core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
Tests BigPipe-delivered HTML responses when JavaScript is enabled.
BigPipeTest::testBigPipeNoJs in core/modules/big_pipe/tests/src/Functional/BigPipeTest.php
Tests BigPipe-delivered HTML responses when JavaScript is disabled.
BrowserTestBaseTest::testDrupalSettings in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Tests that JavaScript Drupal settings can be read.
BrowserTestBaseTest::testGoTo in core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php
Tests basic page test.

... See full list

1 method overrides BrowserTestBase::getDrupalSettings()
WebDriverTestBase::getDrupalSettings in core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php
Gets the current Drupal javascript settings and parses into an array.

File

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

Class

BrowserTestBase
Provides a test case for functional Drupal tests.

Namespace

Drupal\Tests

Code

protected function getDrupalSettings() {
  if ($elements = $this->xpath('//script[@type="application/json" and @data-drupal-selector="drupal-settings-json"]')) {
    $settings = Json::decode($elements[0]->getText());
    if (isset($settings['ajaxPageState']['libraries'])) {
      $settings['ajaxPageState']['libraries'] = UrlHelper::uncompressQueryParameter($settings['ajaxPageState']['libraries']);
    }
    return $settings;
  }
  return [];
}

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