DevelEnforcedDependenciesTest.php in Devel 8
File
tests/src/Kernel/DevelEnforcedDependenciesTest.php
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' => array(),
'weight' => 0,
]);
$block
->save();
$dependents = $config_manager
->findConfigEntityDependents('module', [
'devel',
]);
$this
->assertTrue(isset($dependents['system.menu.devel']));
$this
->assertTrue(isset($dependents['block.block.' . $block_id]));
$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
->assertFalse(isset($dependents['system.menu.devel']));
$this
->assertFalse(isset($dependents['block.block.' . $block_id]));
}
}