Commit 04b4d51d authored by catch's avatar catch
Browse files

Issue #3270323 by Spokje, murilohp, xjm:...

Issue #3270323 by Spokje, murilohp, xjm: ModuleConfigureRouteTest::testModuleConfigureRoutes fails for modules which have a configure route and are deprecated
parent 1e549762
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -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));
  }

}