Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / system / tests / src / Functional / Theme / ThemeTokenTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Theme;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the generation of 'theme_token' key in Drupal settings.
9  *
10  * @group Theme
11  */
12 class ThemeTokenTest extends BrowserTestBase {
13
14   /**
15    * We want to visit the 'admin/structure/block' page.
16    *
17    * @var array
18    */
19   static public $modules = ['block'];
20
21   /**
22    * {@inheritdoc}
23    */
24   protected function setUp() {
25     parent::setUp();
26     $account = $this->drupalCreateUser(['administer blocks', 'view the administration theme']);
27     $this->drupalLogin($account);
28   }
29
30   /**
31    * Tests if the 'theme_token' key of 'ajaxPageState' is computed.
32    */
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
36     // generation.
37     $this->drupalGet('admin/structure/block');
38     $settings = $this->getDrupalSettings();
39     $this->assertNull($settings['ajaxPageState']['theme_token']);
40
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();
44
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);
53   }
54
55 }