Backup of db before drupal security update
[yaffs-website] / web / core / modules / system / tests / src / Functional / Module / InstallTest.php
1 <?php
2
3 namespace Drupal\Tests\system\Functional\Module;
4
5 use Drupal\Core\Extension\ExtensionNameLengthException;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests the installation of modules.
10  *
11  * @group Module
12  */
13 class InstallTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['module_test'];
21
22   /**
23    * Verify that drupal_get_schema() can be used during module installation.
24    */
25   public function testGetSchemaAtInstallTime() {
26     // @see module_test_install()
27     $value = db_query("SELECT data FROM {module_test}")->fetchField();
28     $this->assertIdentical($value, 'varchar');
29   }
30
31   /**
32    * Tests enabling User module once more.
33    *
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
36    * be an array.
37    */
38   public function testEnableUserTwice() {
39     \Drupal::service('module_installer')->install(['user'], FALSE);
40     $this->assertIdentical($this->config('core.extension')->get('module.user'), 0);
41   }
42
43   /**
44    * Tests recorded schema versions of early installed modules in the installer.
45    */
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.');
51
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));
55   }
56
57   /**
58    * Ensures that post update functions are removed on uninstall.
59    */
60   public function testUninstallPostUpdateFunctions() {
61     \Drupal::service('module_installer')->uninstall(['module_test']);
62
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));
66   }
67
68   /**
69    * Tests that an exception is thrown when a module name is too long.
70    */
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]);
74     try {
75       $this->container->get('module_installer')->install([$module_name]);
76       $this->fail($message);
77     }
78     catch (ExtensionNameLengthException $e) {
79       $this->pass($message);
80     }
81
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]);
84     try {
85       $this->container->get('module_installer')->install([$module_name], FALSE);
86       $this->fail($message);
87     }
88     catch (ExtensionNameLengthException $e) {
89       $this->pass($message);
90     }
91   }
92
93 }