Chris@0: config('system.theme')->get('default'); Chris@0: Chris@0: // Add two instances of the user login block. Chris@0: $this->drupalPlaceBlock('user_login_block', [ Chris@0: 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)), Chris@0: ]); Chris@0: $this->drupalPlaceBlock('user_login_block', [ Chris@0: 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)), Chris@0: ]); Chris@0: Chris@0: // Add an instance of a different block. Chris@0: $this->drupalPlaceBlock('system_powered_by_block', [ Chris@0: 'id' => $default_theme . '_' . strtolower($this->randomMachineName(8)), Chris@0: ]); Chris@0: Chris@0: // Install a different theme. Chris@0: $new_theme = 'bartik'; Chris@0: $this->assertFalse($new_theme == $default_theme, 'The new theme is different from the previous default theme.'); Chris@0: \Drupal::service('theme_handler')->install([$new_theme]); Chris@0: $this->config('system.theme') Chris@0: ->set('default', $new_theme) Chris@0: ->save(); Chris@0: Chris@0: /** @var \Drupal\Core\Entity\EntityStorageInterface $block_storage */ Chris@0: $block_storage = $this->container->get('entity_type.manager')->getStorage('block'); Chris@0: Chris@0: // Ensure that the new theme has all the blocks as the previous default. Chris@0: $default_block_names = $block_storage->getQuery() Chris@0: ->condition('theme', $default_theme) Chris@0: ->execute(); Chris@0: $new_blocks = $block_storage->getQuery() Chris@0: ->condition('theme', $new_theme) Chris@0: ->execute(); Chris@0: $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: foreach ($default_block_names as $default_block_name) { Chris@0: // Remove the matching block from the list of blocks in the new theme. Chris@0: // E.g., if the old theme has block.block.stark_admin, Chris@0: // unset block.block.bartik_admin. Chris@0: unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]); Chris@0: } Chris@0: $this->assertTrue(empty($new_blocks), 'The new theme has exactly the same blocks as the previous default theme.'); Chris@0: Chris@0: // Install a hidden base theme and ensure blocks are not copied. Chris@0: $base_theme = 'test_basetheme'; Chris@0: \Drupal::service('theme_handler')->install([$base_theme]); Chris@0: $new_blocks = $block_storage->getQuery() Chris@0: ->condition('theme', $base_theme) Chris@0: ->execute(); Chris@0: $this->assertTrue(empty($new_blocks), 'Installing a hidden base theme does not copy blocks from the default theme.'); Chris@0: } Chris@0: Chris@0: }