You are here

public function RouterTest::testRouterUninstallInstall in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testRouterUninstallInstall()
  2. 9 core/modules/system/tests/src/Functional/Routing/RouterTest.php \Drupal\Tests\system\Functional\Routing\RouterTest::testRouterUninstallInstall()

Tests that routes no longer exist for a module that has been uninstalled.

File

core/modules/system/tests/src/Functional/Routing/RouterTest.php, line 309

Class

RouterTest
Functional class for the full integrated routing system.

Namespace

Drupal\Tests\system\Functional\Routing

Code

public function testRouterUninstallInstall() {
  \Drupal::service('module_installer')
    ->uninstall([
    'router_test',
  ]);
  try {
    \Drupal::service('router.route_provider')
      ->getRouteByName('router_test.1');
    $this
      ->fail('Route was delete on uninstall.');
  } catch (RouteNotFoundException $e) {

    // Expected exception; just continue testing.
  }

  // Install the module again.
  \Drupal::service('module_installer')
    ->install([
    'router_test',
  ]);
  $route = \Drupal::service('router.route_provider')
    ->getRouteByName('router_test.1');
  $this
    ->assertNotNull($route, 'Route exists after module installation');
}