function ThemeTokenTest::testThemeToken

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest::testThemeToken()
  2. 10 core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest::testThemeToken()
  3. 11.x core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest::testThemeToken()

Tests if the 'theme_token' key of 'ajaxPageState' is computed.

File

core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php, line 41

Class

ThemeTokenTest
Tests the generation of 'theme_token' key in Drupal settings.

Namespace

Drupal\Tests\system\Functional\Theme

Code

public function testThemeToken() {
    // Visit the block administrative page with default theme. We use that page
    // because 'misc/ajax.js' is loaded there and we can test the token
    // generation.
    $this->drupalGet('admin/structure/block');
    $settings = $this->getDrupalSettings();
    $this->assertNull($settings['ajaxPageState']['theme_token']);
    // Install 'seven' and configure it as administrative theme.
    $this->container
        ->get('theme_installer')
        ->install([
        'seven',
    ]);
    $this->config('system.theme')
        ->set('admin', 'seven')
        ->save();
    // Revisit the page. This time the page is displayed using the 'seven' theme
    // and that is different from the default theme ('classy').
    $this->drupalGet('admin/structure/block');
    $settings = $this->getDrupalSettings();
    $this->assertNotNull($settings['ajaxPageState']['theme_token']);
    // The CSRF token is a 43 length string.
    $this->assertIsString($settings['ajaxPageState']['theme_token']);
    $this->assertEqual(strlen($settings['ajaxPageState']['theme_token']), 43);
}

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