View source
<?php
namespace Drupal\Tests\devel\Kernel;
use Drupal\block\Entity\Block;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Menu;
class DevelEnforcedDependenciesTest extends KernelTestBase {
public static $modules = [
'devel',
'block',
'user',
'system',
];
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installConfig('devel');
$this
->installSchema('user', [
'users_data',
]);
}
public function testMenuEnforcedDependencies() {
$config_manager = $this->container
->get('config.manager');
$menu = Menu::load('devel');
$this
->assertEquals([
'enforced' => [
'module' => [
'devel',
],
],
], $menu
->get('dependencies'));
$block_id = strtolower($this
->randomMachineName(8));
$block = Block::create([
'plugin' => 'system_menu_block:devel',
'region' => 'sidebar_first',
'id' => $block_id,
'theme' => $this
->config('system.theme')
->get('default'),
'label' => $this
->randomMachineName(8),
'visibility' => [],
'weight' => 0,
]);
$block
->save();
$dependents = $config_manager
->findConfigEntityDependents('module', [
'devel',
]);
$this
->assertArrayHasKey('system.menu.devel', $dependents);
$this
->assertArrayHasKey('block.block.' . $block_id, $dependents);
$this->container
->get('module_installer')
->uninstall([
'devel',
]);
$this
->assertNull(Menu::load('devel'));
$this
->assertNull(Block::load($block_id));
$dependents = $config_manager
->findConfigEntityDependents('module', [
'devel',
]);
$this
->assertArrayNotHasKey('system.menu.devel', $dependents);
$this
->assertArrayNotHasKey('block.block.' . $block_id, $dependents);
}
}