From 04b4d51d249a7eeb80166e5588b69ad10cdf6f54 Mon Sep 17 00:00:00 2001 From: catch <catch@35733.no-reply.drupal.org> Date: Mon, 21 Mar 2022 23:09:29 +0000 Subject: [PATCH] Issue #3270323 by Spokje, murilohp, xjm: ModuleConfigureRouteTest::testModuleConfigureRoutes fails for modules which have a configure route and are deprecated --- .../Extension/ModuleConfigureRouteTest.php | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php index e81a11de31b1..df2e99dcab92 100644 --- a/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php +++ b/core/tests/Drupal/KernelTests/Core/Extension/ModuleConfigureRouteTest.php @@ -2,6 +2,7 @@ namespace Drupal\KernelTests\Core\Extension; +use Drupal\Core\Extension\ExtensionLifecycle; use Drupal\KernelTests\FileSystemModuleDiscoveryDataProviderTrait; use Drupal\KernelTests\KernelTestBase; @@ -42,18 +43,53 @@ protected function setUp(): void { } /** - * Tests the module configure routes exist. + * Tests if the module configure routes exists. * * @dataProvider coreModuleListDataProvider */ - public function testModuleConfigureRoutes($module) { - $module_info = $this->moduleInfo[$module]->info; + public function testModuleConfigureRoutes(string $module_name): void { + $module_info = $this->moduleInfo[$module_name]->info; if (!isset($module_info['configure'])) { - $this->markTestSkipped("$module has no configure route"); + $this->markTestSkipped("$module_name has no configure route"); } - $this->container->get('module_installer')->install([$module]); + $module_lifecycle = $module_info[ExtensionLifecycle::LIFECYCLE_IDENTIFIER]; + if (isset($module_lifecycle) && $module_lifecycle === ExtensionLifecycle::DEPRECATED) { + $this->assertDeprecatedModuleConfigureRoutesExist($module_name, $module_info); + } + else { + $this->container->get('module_installer')->install([$module_name]); + $this->assertModuleConfigureRoutesExist($module_name, $module_info); + } + } + + /** + * Asserts the configure routes of a module with lifecycle deprecated exist. + * + * Note: This test is part of group legacy, to make sure installing the + * deprecated module doesn't trigger a deprecation notice. + * + * @group legacy + * + * @internal + */ + protected function assertDeprecatedModuleConfigureRoutesExist(string $module_name, array $module_info): void { + $this->container->get('module_installer')->install([$module_name]); + $this->assertModuleConfigureRoutesExist($module_name, $module_info); + } + + /** + * Asserts the configure routes of a module exist. + * + * @param string $module_name + * The name of the module. + * @param array $module_info + * An array module info. + * + * @internal + */ + 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)); + $this->assertNotEmpty($route, sprintf('The configure route for the "%s" module was found.', $module_name)); } } -- GitLab