Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\block\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests that the new default theme gets blocks.
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group block
|
Chris@0
|
11 */
|
Chris@0
|
12 class NewDefaultThemeBlocksTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to install.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['block'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Check the enabled Bartik blocks are correctly copied over.
|
Chris@0
|
23 */
|
Chris@0
|
24 public function testNewDefaultThemeBlocks() {
|
Chris@0
|
25 $default_theme = $this->config('system.theme')->get('default');
|
Chris@0
|
26
|
Chris@0
|
27 // Add two instances of the user login block.
|
Chris@0
|
28 $this->drupalPlaceBlock('user_login_block', [
|
Chris@0
|
29 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
Chris@0
|
30 ]);
|
Chris@0
|
31 $this->drupalPlaceBlock('user_login_block', [
|
Chris@0
|
32 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
Chris@0
|
33 ]);
|
Chris@0
|
34
|
Chris@0
|
35 // Add an instance of a different block.
|
Chris@0
|
36 $this->drupalPlaceBlock('system_powered_by_block', [
|
Chris@0
|
37 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)),
|
Chris@0
|
38 ]);
|
Chris@0
|
39
|
Chris@0
|
40 // Install a different theme.
|
Chris@0
|
41 $new_theme = 'bartik';
|
Chris@0
|
42 $this->assertFalse($new_theme == $default_theme, 'The new theme is different from the previous default theme.');
|
Chris@0
|
43 \Drupal::service('theme_handler')->install([$new_theme]);
|
Chris@0
|
44 $this->config('system.theme')
|
Chris@0
|
45 ->set('default', $new_theme)
|
Chris@0
|
46 ->save();
|
Chris@0
|
47
|
Chris@0
|
48 /** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */
|
Chris@0
|
49 $block_storage = $this->container->get('entity_type.manager')->getStorage('block');
|
Chris@0
|
50
|
Chris@0
|
51 // Ensure that the new theme has all the blocks as the previous default.
|
Chris@0
|
52 $default_block_names = $block_storage->getQuery()
|
Chris@0
|
53 ->condition('theme', $default_theme)
|
Chris@0
|
54 ->execute();
|
Chris@0
|
55 $new_blocks = $block_storage->getQuery()
|
Chris@0
|
56 ->condition('theme', $new_theme)
|
Chris@0
|
57 ->execute();
|
Chris@0
|
58 $this->assertTrue(count($default_block_names) == count($new_blocks), 'The new default theme has the same number of blocks as the previous theme.');
|
Chris@0
|
59 foreach ($default_block_names as $default_block_name) {
|
Chris@0
|
60 // Remove the matching block from the list of blocks in the new theme.
|
Chris@0
|
61 // E.g., if the old theme has block.block.stark_admin,
|
Chris@0
|
62 // unset block.block.bartik_admin.
|
Chris@0
|
63 unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]);
|
Chris@0
|
64 }
|
Chris@0
|
65 $this->assertTrue(empty($new_blocks), 'The new theme has exactly the same blocks as the previous default theme.');
|
Chris@0
|
66
|
Chris@0
|
67 // Install a hidden base theme and ensure blocks are not copied.
|
Chris@0
|
68 $base_theme = 'test_basetheme';
|
Chris@0
|
69 \Drupal::service('theme_handler')->install([$base_theme]);
|
Chris@0
|
70 $new_blocks = $block_storage->getQuery()
|
Chris@0
|
71 ->condition('theme', $base_theme)
|
Chris@0
|
72 ->execute();
|
Chris@0
|
73 $this->assertTrue(empty($new_blocks), 'Installing a hidden base theme does not copy blocks from the default theme.');
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 }
|