884b587a11a0fc850fa0df03bebcb31a29c296d7
[yaffs-website] / web / core / modules / block / tests / src / Functional / BlockDemoTest.php
1 <?php
2
3 namespace Drupal\Tests\block\Functional;
4
5 use Drupal\Tests\BrowserTestBase;
6
7 /**
8  * Tests the block demo page with admin themes.
9  *
10  * @group block
11  */
12 class BlockDemoTest extends BrowserTestBase {
13
14   /**
15    * Modules to enable.
16    *
17    * @var array
18    */
19   public static $modules = ['block'];
20
21   /**
22    * Check for the accessibility of the admin block demo page.
23    */
24   public function testBlockDemo() {
25     // Create administrative user.
26     $admin_user = $this->drupalCreateUser(['administer blocks', 'administer themes']);
27     $this->drupalLogin($admin_user);
28
29     // Confirm we have access to the block demo page for the default theme.
30     $config = $this->container->get('config.factory')->get('system.theme');
31     $default_theme = $config->get('default');
32     $this->drupalGet('admin/structure/block/demo/' . $default_theme);
33     $this->assertResponse(200);
34     $this->assertLinkByHref('admin/structure/block');
35     $this->assertNoLinkByHref('admin/structure/block/list/' . $default_theme);
36
37     // All available themes in core.
38     $available_themes = [
39       'bartik',
40       'classy',
41       'seven',
42       'stark',
43     ];
44
45     // All available themes minute minus the default theme.
46     $themes = array_diff($available_themes, [$default_theme]);
47
48     foreach ($themes as $theme) {
49       // Install theme.
50       $this->container->get('theme_handler')->install([$theme]);
51       // Confirm access to the block demo page for the theme.
52       $this->drupalGet('admin/structure/block/demo/' . $theme);
53       $this->assertResponse(200);
54       // Confirm existence of link for "Exit block region demonstration".
55       $this->assertLinkByHref('admin/structure/block/list/' . $theme);
56     }
57
58     // Confirm access to the block demo page is denied for an invalid theme.
59     $this->drupalGet('admin/structure/block/demo/invalid_theme');
60     $this->assertResponse(403);
61   }
62
63 }