class DevelEnforcedDependenciesTest

Same name in other branches
  1. 4.x tests/src/Kernel/DevelEnforcedDependenciesTest.php \Drupal\Tests\devel\Kernel\DevelEnforcedDependenciesTest
  2. 5.x tests/src/Kernel/DevelEnforcedDependenciesTest.php \Drupal\Tests\devel\Kernel\DevelEnforcedDependenciesTest

Tests Devel enforced dependencies.

@group devel

Hierarchy

Expanded class hierarchy of DevelEnforcedDependenciesTest

File

tests/src/Kernel/DevelEnforcedDependenciesTest.php, line 14

Namespace

Drupal\Tests\devel\Kernel
View source
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]));
    }

}

Members

Title Sort descending Modifiers Object type Summary
DevelEnforcedDependenciesTest::$modules public static property Modules to enable.
DevelEnforcedDependenciesTest::setUp protected function
DevelEnforcedDependenciesTest::testMenuEnforcedDependencies public function Tests devel menu enforced dependencies.