function DevelEnforcedDependenciesTest::testMenuEnforcedDependencies
Same name in other branches
- 4.x tests/src/Kernel/DevelEnforcedDependenciesTest.php \Drupal\Tests\devel\Kernel\DevelEnforcedDependenciesTest::testMenuEnforcedDependencies()
- 5.x tests/src/Kernel/DevelEnforcedDependenciesTest.php \Drupal\Tests\devel\Kernel\DevelEnforcedDependenciesTest::testMenuEnforcedDependencies()
Tests devel menu enforced dependencies.
File
-
tests/
src/ Kernel/ DevelEnforcedDependenciesTest.php, line 38
Class
- DevelEnforcedDependenciesTest
- Tests Devel enforced dependencies.
Namespace
Drupal\Tests\devel\KernelCode
public function testMenuEnforcedDependencies() {
/** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
$config_manager = $this->container
->get('config.manager');
// Ensure that the Devel menu has explicit enforced dependencies on devel
// module.
$menu = Menu::load('devel');
$this->assertEquals([
'enforced' => [
'module' => [
'devel',
],
],
], $menu->get('dependencies'));
// Creates an instance of devel menu block so you can test if enforced
// dependencies work properly with it.
$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();
// Ensure that the menu and block instance depend on devel module.
$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',
]);
// Ensure that the menu and block instance are deleted when the dependency
// is uninstalled.
$this->assertNull(Menu::load('devel'));
$this->assertNull(Block::load($block_id));
// Ensure that no config entities depend on devel once uninstalled.
$dependents = $config_manager->findConfigEntityDependents('module', [
'devel',
]);
$this->assertFalse(isset($dependents['system.menu.devel']));
$this->assertFalse(isset($dependents['block.block.' . $block_id]));
}