Version 1
[yaffs-website] / web / core / tests / Drupal / KernelTests / Core / Extension / ModuleInstallerTest.php
diff --git a/web/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php b/web/core/tests/Drupal/KernelTests/Core/Extension/ModuleInstallerTest.php
new file mode 100644 (file)
index 0000000..c15e7fb
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+
+namespace Drupal\KernelTests\Core\Extension;
+
+use Drupal\Core\Database\Database;
+use Drupal\KernelTests\KernelTestBase;
+use Symfony\Component\Routing\Exception\RouteNotFoundException;
+
+/**
+ * Tests the ModuleInstaller class.
+ *
+ * @coversDefaultClass \Drupal\Core\Extension\ModuleInstaller
+ *
+ * @group Extension
+ */
+class ModuleInstallerTest extends KernelTestBase {
+
+  /**
+   * Modules to install.
+   *
+   * The System module is required because system_rebuild_module_data() is used.
+   *
+   * @var array
+   */
+  public static $modules = ['system'];
+
+  /**
+   * Tests that routes are rebuilt during install and uninstall of modules.
+   *
+   * @covers ::install
+   * @covers ::uninstall
+   */
+  public function testRouteRebuild() {
+    // Remove the routing table manually to ensure it can be created lazily
+    // properly.
+    Database::getConnection()->schema()->dropTable('router');
+
+    $this->container->get('module_installer')->install(['router_test']);
+    $route = $this->container->get('router.route_provider')->getRouteByName('router_test.1');
+    $this->assertEquals('/router_test/test1', $route->getPath());
+
+    $this->container->get('module_installer')->uninstall(['router_test']);
+    $this->setExpectedException(RouteNotFoundException::class);
+    $this->container->get('router.route_provider')->getRouteByName('router_test.1');
+  }
+
+}