diff --git a/core/modules/system/src/Tests/Ajax/FrameworkTest.php b/core/modules/system/src/Tests/Ajax/FrameworkTest.php index 7b78b5c..c7ccd8b 100644 --- a/core/modules/system/src/Tests/Ajax/FrameworkTest.php +++ b/core/modules/system/src/Tests/Ajax/FrameworkTest.php @@ -216,14 +216,4 @@ public function testLazyLoadOverriddenCSS() { // cache control. $this->assertNoText('system.module.css?', 'Ajax lazy loading does not add overridden CSS files.'); } - - /** - * Tests if the 'theme_token' key of 'ajaxPageState' is computed. - */ - public function testThemeToken() { - $this->drupalGet('ajax_forms_test_lazy_load_form'); - $settings = $this->getDrupalSettings(); - $this->assertTrue(is_null($settings['ajaxPageState']['theme_token'])); - } - } diff --git a/core/modules/system/src/Tests/Theme/ThemeTokenTest.php b/core/modules/system/src/Tests/Theme/ThemeTokenTest.php new file mode 100644 index 0000000..3c04aa2 --- /dev/null +++ b/core/modules/system/src/Tests/Theme/ThemeTokenTest.php @@ -0,0 +1,60 @@ +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 '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->assertTrue(is_string($settings['ajaxPageState']['theme_token'])); + $this->assertEqual(strlen($settings['ajaxPageState']['theme_token']), 43); + } + +}