3 namespace Drupal\Tests\system\Functional\Module;
5 use Drupal\Core\Extension\ExtensionNameLengthException;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests the installation of modules.
13 class InstallTest extends BrowserTestBase {
20 public static $modules = ['module_test'];
23 * Verify that drupal_get_schema() can be used during module installation.
25 public function testGetSchemaAtInstallTime() {
26 // @see module_test_install()
27 $value = db_query("SELECT data FROM {module_test}")->fetchField();
28 $this->assertIdentical($value, 'varchar');
32 * Tests enabling User module once more.
34 * Regression: The installer might enable a module twice due to automatic
35 * dependency resolution. A bug caused the stored weight for User module to
38 public function testEnableUserTwice() {
39 \Drupal::service('module_installer')->install(['user'], FALSE);
40 $this->assertIdentical($this->config('core.extension')->get('module.user'), 0);
44 * Tests recorded schema versions of early installed modules in the installer.
46 public function testRequiredModuleSchemaVersions() {
47 $version = drupal_get_installed_schema_version('system', TRUE);
48 $this->assertTrue($version > 0, 'System module version is > 0.');
49 $version = drupal_get_installed_schema_version('user', TRUE);
50 $this->assertTrue($version > 0, 'User module version is > 0.');
52 $post_update_key_value = \Drupal::keyValue('post_update');
53 $existing_updates = $post_update_key_value->get('existing_updates', []);
54 $this->assertTrue(in_array('module_test_post_update_test', $existing_updates));
58 * Ensures that post update functions are removed on uninstall.
60 public function testUninstallPostUpdateFunctions() {
61 \Drupal::service('module_installer')->uninstall(['module_test']);
63 $post_update_key_value = \Drupal::keyValue('post_update');
64 $existing_updates = $post_update_key_value->get('existing_updates', []);
65 $this->assertFalse(in_array('module_test_post_update_test', $existing_updates));
69 * Tests that an exception is thrown when a module name is too long.
71 public function testModuleNameLength() {
72 $module_name = 'invalid_module_name_over_the_maximum_allowed_character_length';
73 $message = format_string('Exception thrown when enabling module %name with a name length over the allowed maximum', ['%name' => $module_name]);
75 $this->container->get('module_installer')->install([$module_name]);
76 $this->fail($message);
78 catch (ExtensionNameLengthException $e) {
79 $this->pass($message);
82 // Since for the UI, the submit callback uses FALSE, test that too.
83 $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]);
85 $this->container->get('module_installer')->install([$module_name], FALSE);
86 $this->fail($message);
88 catch (ExtensionNameLengthException $e) {
89 $this->pass($message);