3 namespace Drupal\Tests\system\Functional\Theme;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests the generation of 'theme_token' key in Drupal settings.
12 class ThemeTokenTest extends BrowserTestBase {
15 * We want to visit the 'admin/structure/block' page.
19 static public $modules = ['block'];
24 protected function setUp() {
26 $account = $this->drupalCreateUser(['administer blocks', 'view the administration theme']);
27 $this->drupalLogin($account);
31 * Tests if the 'theme_token' key of 'ajaxPageState' is computed.
33 public function testThemeToken() {
34 // Visit the block administrative page with default theme. We use that page
35 // because 'misc/ajax.js' is loaded there and we can test the token
37 $this->drupalGet('admin/structure/block');
38 $settings = $this->getDrupalSettings();
39 $this->assertNull($settings['ajaxPageState']['theme_token']);
41 // Install 'seven' and configure it as administrative theme.
42 $this->container->get('theme_installer')->install(['seven']);
43 $this->config('system.theme')->set('admin', 'seven')->save();
45 // Revisit the page. This time the page is displayed using the 'seven' theme
46 // and that is different from the default theme ('classy').
47 $this->drupalGet('admin/structure/block');
48 $settings = $this->getDrupalSettings();
49 $this->assertNotNull($settings['ajaxPageState']['theme_token']);
50 // The CSRF token is a 43 length string.
51 $this->assertTrue(is_string($settings['ajaxPageState']['theme_token']));
52 $this->assertEqual(strlen($settings['ajaxPageState']['theme_token']), 43);