interdiff impossible; taking evasive action reverted: --- b/core/modules/system/tests/src/Kernel/Module/InstallTest.php +++ a/core/modules/system/tests/src/Functional/Module/InstallTest.php @@ -1,64 +1,44 @@ moduleInstaller = $this->container->get('module_installer'); - $this->moduleInstaller->install([ - 'module_test', - 'system', - 'user', - ]); - } /** * Verify that drupal_get_schema() can be used during module installation. */ public function testGetSchemaAtInstallTime() { + // @see module_test_install() + $value = Database::getConnection()->query("SELECT data FROM {module_test}")->fetchField(); + $this->assertIdentical($value, 'varchar'); - $database = $this->container->get('database'); - $value = $database->select('module_test') - ->fields('module_test', ['data']) - ->execute() - ->fetchField(); - $this->assertEquals('varchar', $value); } /** * 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 - * 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->assertIdentical($this->config('core.extension')->get('module.user'), 0); - $this->moduleInstaller->install(['user'], FALSE); - $this->assertSame(0, $this->config('core.extension')->get('module.user')); - - // To avoid false positives, ensure that a module that does not exist does - // not return exactly zero. - $this->assertNotSame(0, $this->config('core.extension')->get('module.does_not_exist')); } /** @@ -66,32 +46,24 @@ */ public function testRequiredModuleSchemaVersions() { $version = drupal_get_installed_schema_version('system', TRUE); + $this->assertTrue($version > 0, 'System module version is > 0.'); - $this->assertGreaterThan(0, $version); $version = drupal_get_installed_schema_version('user', TRUE); + $this->assertTrue($version > 0, 'User module version is > 0.'); - $this->assertGreaterThan(0, $version); + $post_update_key_value = \Drupal::keyValue('post_update'); - $post_update_key_value = $this->container->get('keyvalue')->get('post_update'); $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertTrue(in_array('module_test_post_update_test', $existing_updates)); - - $this->assertContains('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']); - // First, to avoid false positives, ensure that the post_update function - // exists while the module is still installed. - $post_update_key_value = $this->container->get('keyvalue')->get('post_update'); - $existing_updates = $post_update_key_value->get('existing_updates', []); - $this->assertContains('module_test_post_update_test', $existing_updates); - - // Uninstall the module. - $this->moduleInstaller->uninstall(['module_test']); + $post_update_key_value = \Drupal::keyValue('post_update'); - // Ensure the post update function is no longer listed. $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertFalse(in_array('module_test_post_update_test', $existing_updates)); - $this->assertNotContains('module_test_post_update_test', $existing_updates); } /** @@ -99,18 +71,24 @@ */ 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', ['%name' => $module_name]); + try { + $this->container->get('module_installer')->install([$module_name]); + $this->fail($message); + } + catch (ExtensionNameLengthException $e) { + $this->pass($message); + } - $this->setExpectedException(ExtensionNameLengthException::class); - $this->moduleInstaller->install([$module_name]); - } - /** - * Tests that an exception is thrown when a module name is too long. - */ - public function testModuleNameLengthWithDependencyCheck() { // 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', ['%name' => $module_name]); + try { + $this->container->get('module_installer')->install([$module_name], FALSE); + $this->fail($message); + } + catch (ExtensionNameLengthException $e) { + $this->pass($message); + } - $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; - $this->setExpectedException(ExtensionNameLengthException::class); - $this->moduleInstaller->install([$module_name], FALSE); } } unchanged: --- /dev/null +++ b/core/modules/system/tests/src/Kernel/Module/InstallTest.php @@ -0,0 +1,123 @@ +moduleInstaller = $this->container->get('module_installer'); + $this->moduleInstaller->install([ + 'module_test', + 'system', + 'user', + ]); + } + + /** + * Verify that drupal_get_schema() can be used during module installation. + */ + public function testGetSchemaAtInstallTime(): void { + // @see module_test_install() + $database = $this->container->get('database'); + $value = $database->select('module_test') + ->fields('module_test', ['data']) + ->execute() + ->fetchField(); + $this->assertEquals('varchar', $value); + } + + /** + * 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(): void { + $this->moduleInstaller->install(['user'], FALSE); + $this->assertSame(0, $this->config('core.extension')->get('module.user')); + + // To avoid false positives, ensure that a module that does not exist does + // not return exactly zero. + $this->assertNotSame(0, $this->config('core.extension') + ->get('module.does_not_exist')); + } + + /** + * Tests recorded schema versions of early installed modules in the installer. + */ + public function testRequiredModuleSchemaVersions(): void { + /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ + $update_registry = \Drupal::service('update.update_hook_registry'); + $version = $update_registry->getInstalledVersion('system'); + $this->assertGreaterThan(0, $version); + $version = $update_registry->getInstalledVersion('user'); + $this->assertGreaterThan(0, $version); + + $post_update_key_value = \Drupal::keyValue('post_update'); + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertContains('module_test_post_update_test', $existing_updates); + } + + /** + * Ensures that post update functions are removed on uninstallation. + */ + public function testUninstallPostUpdateFunctions(): void { + // First, to avoid false positives, ensure that the post_update function + // exists while the module is still installed. + $post_update_key_value = $this->container->get('keyvalue') + ->get('post_update'); + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertContains('module_test_post_update_test', $existing_updates); + + // Uninstall the module. + $this->moduleInstaller->uninstall(['module_test']); + + // Ensure the post update function is no longer listed. + $existing_updates = $post_update_key_value->get('existing_updates', []); + $this->assertNotContains('module_test_post_update_test', $existing_updates); + } + + /** + * Tests that an exception is thrown when a module name is too long. + */ + public function testModuleNameLength(): void { + $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; + $this->expectException(ExtensionNameLengthException::class); + $this->expectExceptionMessage("Module name 'invalid_module_name_over_the_maximum_allowed_character_length' is over the maximum allowed length of 50 characters"); + $this->moduleInstaller->install([$module_name]); + } + + /** + * Tests that an exception is thrown when a module name is too long. + * + * We do this without checking dependencies for the module to install. + */ + public function testModuleNameLengthWithoutDependencyCheck(): void { + $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length'; + $this->expectException(ExtensionNameLengthException::class); + $this->expectExceptionMessage("Module name 'invalid_module_name_over_the_maximum_allowed_character_length' is over the maximum allowed length of 50 characters"); + $this->moduleInstaller->install([$module_name], FALSE); + } + +} only in patch2: unchanged: --- a/core/modules/system/tests/src/Functional/Module/InstallTest.php +++ /dev/null @@ -1,102 +0,0 @@ -select('module_test', 'mt')->fields('mt', ['data'])->execute()->fetchField(); - $this->assertSame('varchar', $value); - } - - /** - * 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(0, $this->config('core.extension')->get('module.user')); - } - - /** - * Tests recorded schema versions of early installed modules in the installer. - */ - public function testRequiredModuleSchemaVersions() { - /** @var \Drupal\Core\Update\UpdateHookRegistry $update_registry */ - $update_registry = \Drupal::service('update.update_hook_registry'); - $version = $update_registry->getInstalledVersion('system'); - $this->assertGreaterThan(0, $version); - $version = $update_registry->getInstalledVersion('user'); - $this->assertGreaterThan(0, $version); - - $post_update_key_value = \Drupal::keyValue('post_update'); - $existing_updates = $post_update_key_value->get('existing_updates', []); - $this->assertContains('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->assertNotContains('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 = 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); - } - catch (\Exception $e) { - $this->assertInstanceOf(ExtensionNameLengthException::class, $e); - } - - // 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 (\Exception $e) { - $this->assertInstanceOf(ExtensionNameLengthException::class, $e); - } - } - -}