3 namespace Drupal\Tests\devel\Kernel;
5 use Drupal\block\Entity\Block;
6 use Drupal\KernelTests\KernelTestBase;
7 use Drupal\system\Entity\Menu;
10 * Tests Devel enforced dependencies.
14 class DevelEnforcedDependenciesTest extends KernelTestBase {
21 public static $modules = ['devel', 'block', 'user', 'system'];
26 protected function setUp() {
29 $this->installEntitySchema('user');
30 $this->installConfig('devel');
31 // For uninstall to work.
32 $this->installSchema('user', ['users_data']);
36 * Tests devel menu enforced dependencies.
38 public function testMenuEnforcedDependencies() {
39 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
40 $config_manager = $this->container->get('config.manager');
42 // Ensure that the Devel menu has explicit enforced dependencies on devel
44 $menu = Menu::load('devel');
45 $this->assertEquals(['enforced' => ['module' => ['devel']]], $menu->get('dependencies'));
47 // Creates an instance of devel menu block so you can test if enforced
48 // dependencies work properly with it.
49 $block_id = strtolower($this->randomMachineName(8));
51 $block = Block::create([
52 'plugin' => 'system_menu_block:devel',
53 'region' => 'sidebar_first',
55 'theme' => $this->config('system.theme')->get('default'),
56 'label' => $this->randomMachineName(8),
57 'visibility' => array(),
62 // Ensure that the menu and block instance depend on devel module.
63 $dependents = $config_manager->findConfigEntityDependents('module', ['devel']);
64 $this->assertTrue(isset($dependents['system.menu.devel']));
65 $this->assertTrue(isset($dependents['block.block.' . $block_id]));
67 $this->container->get('module_installer')->uninstall(['devel']);
69 // Ensure that the menu and block instance are deleted when the dependency
71 $this->assertNull(Menu::load('devel'));
72 $this->assertNull(Block::load($block_id));
74 // Ensure that no config entities depend on devel once uninstalled.
75 $dependents = $config_manager->findConfigEntityDependents('module', ['devel']);
76 $this->assertFalse(isset($dependents['system.menu.devel']));
77 $this->assertFalse(isset($dependents['block.block.' . $block_id]));