ModuleConfigureRouteTest.php in Drupal 10
File
core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php
View source
<?php
namespace Drupal\KernelTests\Core\Extension;
use Drupal\Core\Extension\ExtensionLifecycle;
use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait;
use Drupal\KernelTests\KernelTestBase;
class ModuleConfigureRouteTest extends KernelTestBase {
use FileSystemModuleDiscoveryDataProviderTrait;
protected static $modules = [
'system',
'user',
'path_alias',
];
protected $routeProvider;
protected $moduleInfo;
protected function setUp() : void {
parent::setUp();
$this->routeProvider = \Drupal::service('router.route_provider');
$this->moduleInfo = \Drupal::service('extension.list.module')
->getList();
}
public function testModuleConfigureRoutes(string $module_name) : void {
$module_info = $this->moduleInfo[$module_name]->info;
if (!isset($module_info['configure'])) {
$this
->markTestSkipped("{$module_name} has no configure route");
}
$module_lifecycle = $module_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER];
if (isset($module_lifecycle) && $module_lifecycle === ExtensionLifecycle::DEPRECATED) {
$this
->markTestSkipped("{$module_name} is {$module_lifecycle}");
}
$this->container
->get('module_installer')
->install([
$module_name,
]);
$this
->assertModuleConfigureRoutesExist($module_name, $module_info);
}
public function testDeprecatedModuleConfigureRoutes(string $module_name) : void {
$module_info = $this->moduleInfo[$module_name]->info;
if (!isset($module_info['configure'])) {
$this
->markTestSkipped("{$module_name} has no configure route");
}
$module_lifecycle = $module_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER];
if (isset($module_lifecycle) && $module_lifecycle !== ExtensionLifecycle::DEPRECATED) {
$this
->markTestSkipped("{$module_name} is not {$module_lifecycle}");
}
$this->container
->get('module_installer')
->install([
$module_name,
]);
$this
->assertModuleConfigureRoutesExist($module_name, $module_info);
}
protected function assertModuleConfigureRoutesExist(string $module_name, array $module_info) : void {
$route = $this->routeProvider
->getRouteByName($module_info['configure']);
$this
->assertNotEmpty($route, sprintf('The configure route for the "%s" module was found.', $module_name));
}
}