Commit 2b865e37 authored by willzyx's avatar willzyx Committed by willzyx

Issue #2663558 by GaëlG, willzyx: Add enforced dependency to system.menu.devel

parent 95479b31
......@@ -3,4 +3,7 @@ label: 'Development'
description: 'Links related to Devel module.'
langcode: en
locked: true
dependencies:
enforced:
module:
- devel
......@@ -5,18 +5,6 @@
* Install, update and uninstall functions for the devel module.
*/
use Drupal\system\Entity\Menu;
/**
* Implements hook_uninstall().
*/
function devel_uninstall() {
// Delete the development menu.
if ($devel_menu = Menu::load('devel')) {
$devel_menu->delete();
}
}
/**
* Set the default devel dumper plugin.
*/
......@@ -30,3 +18,13 @@ function devel_update_8001() {
->set('devel_dumper', $default_dumper)
->save(TRUE);
}
/**
* Add enforced dependencies to system.menu.devel
*/
function devel_update_8002() {
$config = \Drupal::configFactory()->getEditable('system.menu.devel');
$dependencies = $config->get('dependencies');
$dependencies['enforced']['module'][] = 'devel';
$config->set('dependencies', $dependencies)->save(TRUE);
}
<?php
namespace Drupal\Tests\devel\Kernel;
use Drupal\block\Entity\Block;
use Drupal\KernelTests\KernelTestBase;
use Drupal\system\Entity\Menu;
/**
* Tests Devel enforced dependencies.
*
* @group devel
*/
class DevelEnforcedDependenciesTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['devel', 'block', 'user', 'system'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('user');
$this->installConfig('devel');
// For uninstall to work.
$this->installSchema('user', ['users_data']);
}
/**
* Tests devel menu enforced dependencies.
*/
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]));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment