NewDefaultThemeBlocksTest.php in Drupal 8
File
core/modules/block/tests/src/Kernel/NewDefaultThemeBlocksTest.php
View source
<?php
namespace Drupal\Tests\block\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\block\Traits\BlockCreationTrait;
class NewDefaultThemeBlocksTest extends KernelTestBase {
use BlockCreationTrait;
protected static $modules = [
'block',
'system',
];
public function testNewDefaultThemeBlocks() {
$theme_installer = $this->container
->get('theme_installer');
$default_theme = $this
->config('system.theme')
->get('default');
$this
->placeBlock('user_login_block', [
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
]);
$this
->placeBlock('user_login_block', [
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
]);
$this
->placeBlock('system_powered_by_block', [
'id' => $default_theme . '_' . strtolower($this
->randomMachineName(8)),
]);
$new_theme = 'bartik';
$this
->assertNotEquals($new_theme, $default_theme);
$theme_installer
->install([
$new_theme,
]);
$this
->config('system.theme')
->set('default', $new_theme)
->save();
$block_storage = $this->container
->get('entity_type.manager')
->getStorage('block');
$default_block_names = $block_storage
->getQuery()
->condition('theme', $default_theme)
->execute();
$new_blocks = $block_storage
->getQuery()
->condition('theme', $new_theme)
->execute();
$this
->assertEquals(count($default_block_names), count($new_blocks));
foreach ($default_block_names as $default_block_name) {
unset($new_blocks[str_replace($default_theme . '_', $new_theme . '_', $default_block_name)]);
}
$this
->assertEmpty($new_blocks);
$base_theme = 'test_basetheme';
$theme_installer
->install([
$base_theme,
]);
$new_blocks = $block_storage
->getQuery()
->condition('theme', $base_theme)
->execute();
$this
->assertEmpty($new_blocks);
}
}