NewDefaultThemeBlocksTest.php in Zircon Profile 8
File
core/modules/block/src/Tests/NewDefaultThemeBlocksTest.php
View source
<?php
namespace Drupal\block\Tests;
use Drupal\simpletest\WebTestBase;
class NewDefaultThemeBlocksTest extends WebTestBase {
public static $modules = array(
'block',
);
function testNewDefaultThemeBlocks() {
$default_theme = $this
->config('system.theme')
->get('default');
$this
->drupalPlaceBlock('user_login_block', array(
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
));
$this
->drupalPlaceBlock('user_login_block', array(
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
));
$this
->drupalPlaceBlock('system_powered_by_block', array(
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
));
$new_theme = 'bartik';
$this
->assertFalse($new_theme == $default_theme, 'The new theme is different from the previous default theme.');
\Drupal::service('theme_handler')
->install(array(
$new_theme,
));
$this
->config('system.theme')
->set('default', $new_theme)
->save();
$default_block_names = $this->container
->get('entity.query')
->get('block')
->condition('theme', $default_theme)
->execute();
$new_blocks = $this->container
->get('entity.query')
->get('block')
->condition('theme', $new_theme)
->execute();
$this
->assertTrue(count($default_block_names) == count($new_blocks), 'The new default theme has the same number of blocks as the previous theme.');
foreach ($default_block_names as $default_block_name) {
unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]);
}
$this
->assertTrue(empty($new_blocks), 'The new theme has exactly the same blocks as the previous default theme.');
$base_theme = 'test_basetheme';
\Drupal::service('theme_handler')
->install([
$base_theme,
]);
$new_blocks = $this->container
->get('entity.query')
->get('block')
->condition('theme', $base_theme)
->execute();
$this
->assertTrue(empty($new_blocks), 'Installing a hidden base theme does not copy blocks from the default theme.');
}
}