diff --git a/core/modules/system/src/Tests/Module/InstallTest.php b/core/modules/system/src/Tests/Module/InstallTest.php deleted file mode 100644 index babdd76..0000000 --- a/core/modules/system/src/Tests/Module/InstallTest.php +++ /dev/null @@ -1,93 +0,0 @@ -fetchField(); - $this->assertIdentical($value, 'varchar'); - } - - /** - * Tests enabling User module once more. - * - * Regression: The installer might enable a module twice due to automatic - * dependency resolution. A bug caused the stored weight for User module to - * be an array. - */ - public function testEnableUserTwice() { - \Drupal::service('module_installer')->install(array('user'), FALSE); - $this->assertIdentical($this->config('core.extension')->get('module.user'), 0); - } - - /** - * Tests recorded schema versions of early installed modules in the installer. - */ - public function testRequiredModuleSchemaVersions() { - $version = drupal_get_installed_schema_version('system', TRUE); - $this->assertTrue($version > 0, 'System module version is > 0.'); - $version = drupal_get_installed_schema_version('user', TRUE); - $this->assertTrue($version > 0, 'User module version is > 0.'); - - $post_update_key_value = \Drupal::keyValue('post_update'); - $existing_updates = $post_update_key_value->get('existing_updates', []); - $this->assertTrue(in_array('module_test_post_update_test', $existing_updates)); - } - - /** - * Ensures that post update functions are removed on uninstall. - */ - public function testUninstallPostUpdateFunctions() { - \Drupal::service('module_installer')->uninstall(['module_test']); - - $post_update_key_value = \Drupal::keyValue('post_update'); - $existing_updates = $post_update_key_value->get('existing_updates', []); - $this->assertFalse(in_array('module_test_post_update_test', $existing_updates)); - } - - /** - * Tests that an exception is thrown when a module name is too long. - */ - public function testModuleNameLength() { - $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; - $message = format_string('Exception thrown when enabling module %name with a name length over the allowed maximum', array('%name' => $module_name)); - try { - $this->container->get('module_installer')->install(array($module_name)); - $this->fail($message); - } - catch (ExtensionNameLengthException $e) { - $this->pass($message); - } - - // Since for the UI, the submit callback uses FALSE, test that too. - $message = format_string('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', array('%name' => $module_name)); - try { - $this->container->get('module_installer')->install(array($module_name), FALSE); - $this->fail($message); - } - catch (ExtensionNameLengthException $e) { - $this->pass($message); - } - } - -} diff --git a/core/modules/system/tests/src/Kernel/Module/ModuleInstallerKernelTest.php b/core/modules/system/tests/src/Kernel/Module/ModuleInstallerKernelTest.php new file mode 100644 index 0000000..e3cfd9d --- /dev/null +++ b/core/modules/system/tests/src/Kernel/Module/ModuleInstallerKernelTest.php @@ -0,0 +1,117 @@ +root . '/core/modules/system/system.module'; + \Drupal::service('module_installer')->install([ + 'system', + 'user', + 'module_test', + ]); + } + + /** + * Tests enabling User module once more. + * + * Regression: The installer might enable a module twice due to automatic + * dependency resolution. A bug caused the stored weight for User module to + * be an array. + */ + public function testEnableUserTwice() { + \Drupal::service('module_installer')->install(['user'], FALSE); + $this->assertSame($this->config('core.extension')->get('module.user'), 0); + + // To avoid false positives, ensure that a module that does not exist does + // not return exactly zero. + $this->assertNotSame($this->config('core.extension')->get('module.does_not_exist'), 0); + } + + /** + * Tests that an exception is thrown when a module name is too long. + */ + public function testModuleNameLength() { + $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; + $message = new FormattableMarkup('Exception thrown when enabling module %name with a name length over the allowed maximum', ['%name' => $module_name]); + try { + $this->container->get('module_installer')->install([$module_name]); + $this->fail($message->__toString()); + } + catch (ExtensionNameLengthException $e) { + $this->assertTrue(TRUE, $message->__toString()); + } + + // Since for the UI, the submit callback uses FALSE, test that too. + $message = new FormattableMarkup('Exception thrown when enabling as if via the UI the module %name with a name length over the allowed maximum', ['%name' => $module_name]); + try { + $this->container->get('module_installer')->install([$module_name], FALSE); + $this->fail($message); + } + catch (ExtensionNameLengthException $e) { + $this->assertTrue(TRUE, $message->__toString()); + } + } + + /** + * Ensures that post update functions are removed on uninstall. + */ + public function testUninstallPostUpdateFunctions() { + // First, to avoid false positives, ensure that the post_update function + // exists while the module is still installed. + $post_update_key_value = \Drupal::keyValue('post_update'); + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertTrue(in_array('module_test_post_update_test', $existing_updates)); + + // Uninstall the module. + \Drupal::service('module_installer')->uninstall(['module_test']); + + // Ensure the post update function is no longer listed. + $post_update_key_value = \Drupal::keyValue('post_update'); + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertFalse(in_array('module_test_post_update_test', $existing_updates)); + } + + /** + * Tests recorded schema versions of early installed modules in the installer. + */ + public function testRequiredModuleSchemaVersions() { + $version = drupal_get_installed_schema_version('system', TRUE); + $this->assertTrue($version > 0, 'System module version is > 0.'); + $version = drupal_get_installed_schema_version('user', TRUE); + $this->assertTrue($version > 0, 'User module version is > 0.'); + + $post_update_key_value = \Drupal::keyValue('post_update'); + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertTrue(in_array('module_test_post_update_test', $existing_updates)); + } + + /** + * Verify that drupal_get_schema() can be used during module installation. + */ + public function testGetSchemaAtInstallTime() { + $database = $this->container->get('database'); + $query = $database->select('module_test'); + $query->addField('module_test', 'data'); + $value = $query->execute()->fetchField(); + + $this->assertSame($value, 'varchar'); + } + +}