class ThemeTokenTest
Same name and namespace in other branches
- 11.x core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest
- 10 core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest
- 8.9.x core/modules/system/tests/src/Functional/Theme/ThemeTokenTest.php \Drupal\Tests\system\Functional\Theme\ThemeTokenTest
Tests the generation of 'theme_token' key in Drupal settings.
@group Theme
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait implements \PHPUnit\Framework\TestCase
- class \Drupal\Tests\system\Functional\Theme\ThemeTokenTest implements \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ThemeTokenTest
File
-
core/
modules/ system/ tests/ src/ Functional/ Theme/ ThemeTokenTest.php, line 12
Namespace
Drupal\Tests\system\Functional\ThemeView source
class ThemeTokenTest extends BrowserTestBase {
/**
* We want to visit the 'admin/structure/block' page.
*
* @var array
*/
protected static $modules = [
'block',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$account = $this->drupalCreateUser([
'administer blocks',
'view the administration theme',
]);
$this->drupalLogin($account);
}
/**
* Tests if the 'theme_token' key of 'ajaxPageState' is computed.
*/
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 'claro' and configure it as administrative theme.
$this->container
->get('theme_installer')
->install([
'claro',
]);
$this->config('system.theme')
->set('admin', 'claro')
->save();
// Revisit the page. This time the page is displayed using the 'claro' theme
// and that is different from the default theme ('stark').
$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->assertEquals(43, strlen($settings['ajaxPageState']['theme_token']));
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.