Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\update\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Core\Extension\InfoParserDynamic;
|
Chris@0
|
6 use Drupal\Core\Updater\Updater;
|
Chris@0
|
7 use Drupal\Core\Url;
|
Chris@0
|
8 use Drupal\Tests\TestFileCreationTrait;
|
Chris@0
|
9
|
Chris@0
|
10 /**
|
Chris@0
|
11 * Tests the Update Manager module's upload and extraction functionality.
|
Chris@0
|
12 *
|
Chris@0
|
13 * @group update
|
Chris@0
|
14 */
|
Chris@0
|
15 class UpdateUploadTest extends UpdateTestBase {
|
Chris@0
|
16
|
Chris@0
|
17 use TestFileCreationTrait {
|
Chris@0
|
18 getTestFiles as drupalGetTestFiles;
|
Chris@0
|
19 }
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Modules to enable.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @var array
|
Chris@0
|
25 */
|
Chris@0
|
26 public static $modules = ['update', 'update_test'];
|
Chris@0
|
27
|
Chris@0
|
28 protected function setUp() {
|
Chris@0
|
29 parent::setUp();
|
Chris@0
|
30 $admin_user = $this->drupalCreateUser(['administer modules', 'administer software updates', 'administer site configuration']);
|
Chris@0
|
31 $this->drupalLogin($admin_user);
|
Chris@0
|
32 }
|
Chris@0
|
33
|
Chris@0
|
34 /**
|
Chris@0
|
35 * Tests upload, extraction, and update of a module.
|
Chris@0
|
36 */
|
Chris@0
|
37 public function testUploadModule() {
|
Chris@0
|
38 // Ensure that the update information is correct before testing.
|
Chris@0
|
39 update_get_available(TRUE);
|
Chris@0
|
40
|
Chris@0
|
41 // Images are not valid archives, so get one and try to install it. We
|
Chris@0
|
42 // need an extra variable to store the result of drupalGetTestFiles()
|
Chris@0
|
43 // since reset() takes an argument by reference and passing in a constant
|
Chris@0
|
44 // emits a notice in strict mode.
|
Chris@0
|
45 $imageTestFiles = $this->drupalGetTestFiles('image');
|
Chris@0
|
46 $invalidArchiveFile = reset($imageTestFiles);
|
Chris@0
|
47 $edit = [
|
Chris@0
|
48 'files[project_upload]' => $invalidArchiveFile->uri,
|
Chris@0
|
49 ];
|
Chris@0
|
50 // This also checks that the correct archive extensions are allowed.
|
Chris@0
|
51 $this->drupalPostForm('admin/modules/install', $edit, t('Install'));
|
Chris@0
|
52 $this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', ['@archive_extensions' => archiver_get_extensions()]), 'Only valid archives can be uploaded.');
|
Chris@0
|
53 $this->assertUrl('admin/modules/install');
|
Chris@0
|
54
|
Chris@0
|
55 // Check to ensure an existing module can't be reinstalled. Also checks that
|
Chris@0
|
56 // the archive was extracted since we can't know if the module is already
|
Chris@0
|
57 // installed until after extraction.
|
Chris@0
|
58 $validArchiveFile = __DIR__ . '/../../aaa_update_test.tar.gz';
|
Chris@0
|
59 $edit = [
|
Chris@0
|
60 'files[project_upload]' => $validArchiveFile,
|
Chris@0
|
61 ];
|
Chris@0
|
62 $this->drupalPostForm('admin/modules/install', $edit, t('Install'));
|
Chris@0
|
63 $this->assertText(t('@module_name is already installed.', ['@module_name' => 'AAA Update test']), 'Existing module was extracted and not reinstalled.');
|
Chris@0
|
64 $this->assertUrl('admin/modules/install');
|
Chris@0
|
65
|
Chris@0
|
66 // Ensure that a new module can be extracted and installed.
|
Chris@0
|
67 $updaters = drupal_get_updaters();
|
Chris@0
|
68 $moduleUpdater = $updaters['module']['class'];
|
Chris@0
|
69 $installedInfoFilePath = $this->container->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml';
|
Chris@0
|
70 $this->assertFalse(file_exists($installedInfoFilePath), 'The new module does not exist in the filesystem before it is installed with the Update Manager.');
|
Chris@0
|
71 $validArchiveFile = __DIR__ . '/../../update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
|
Chris@0
|
72 $edit = [
|
Chris@0
|
73 'files[project_upload]' => $validArchiveFile,
|
Chris@0
|
74 ];
|
Chris@0
|
75 $this->drupalPostForm('admin/modules/install', $edit, t('Install'));
|
Chris@0
|
76 // Check that submitting the form takes the user to authorize.php.
|
Chris@0
|
77 $this->assertUrl('core/authorize.php');
|
Chris@0
|
78 $this->assertTitle('Update manager | Drupal');
|
Chris@0
|
79 // Check for a success message on the page, and check that the installed
|
Chris@0
|
80 // module now exists in the expected place in the filesystem.
|
Chris@0
|
81 $this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module']));
|
Chris@0
|
82 $this->assertTrue(file_exists($installedInfoFilePath), 'The new module exists in the filesystem after it is installed with the Update Manager.');
|
Chris@0
|
83 // Ensure the links are relative to the site root and not
|
Chris@0
|
84 // core/authorize.php.
|
Chris@0
|
85 $this->assertLink(t('Install another module'));
|
Chris@0
|
86 $this->assertLinkByHref(Url::fromRoute('update.module_install')->toString());
|
Chris@0
|
87 $this->assertLink(t('Enable newly added modules'));
|
Chris@0
|
88 $this->assertLinkByHref(Url::fromRoute('system.modules_list')->toString());
|
Chris@0
|
89 $this->assertLink(t('Administration pages'));
|
Chris@0
|
90 $this->assertLinkByHref(Url::fromRoute('system.admin')->toString());
|
Chris@0
|
91 // Ensure we can reach the "Install another module" link.
|
Chris@0
|
92 $this->clickLink(t('Install another module'));
|
Chris@0
|
93 $this->assertResponse(200);
|
Chris@0
|
94 $this->assertUrl('admin/modules/install');
|
Chris@0
|
95
|
Chris@0
|
96 // Check that the module has the correct version before trying to update
|
Chris@0
|
97 // it. Since the module is installed in sites/simpletest, which only the
|
Chris@0
|
98 // child site has access to, standard module API functions won't find it
|
Chris@0
|
99 // when called here. To get the version, the info file must be parsed
|
Chris@0
|
100 // directly instead.
|
Chris@0
|
101 $info_parser = new InfoParserDynamic();
|
Chris@0
|
102 $info = $info_parser->parse($installedInfoFilePath);
|
Chris@0
|
103 $this->assertEqual($info['version'], '8.x-1.0');
|
Chris@0
|
104
|
Chris@0
|
105 // Enable the module.
|
Chris@0
|
106 $this->drupalPostForm('admin/modules', ['modules[update_test_new_module][enable]' => TRUE], t('Install'));
|
Chris@0
|
107
|
Chris@0
|
108 // Define the update XML such that the new module downloaded above needs an
|
Chris@0
|
109 // update from 8.x-1.0 to 8.x-1.1.
|
Chris@0
|
110 $update_test_config = $this->config('update_test.settings');
|
Chris@0
|
111 $system_info = [
|
Chris@0
|
112 'update_test_new_module' => [
|
Chris@0
|
113 'project' => 'update_test_new_module',
|
Chris@0
|
114 ],
|
Chris@0
|
115 ];
|
Chris@0
|
116 $update_test_config->set('system_info', $system_info)->save();
|
Chris@0
|
117 $xml_mapping = [
|
Chris@0
|
118 'update_test_new_module' => '1_1',
|
Chris@0
|
119 ];
|
Chris@0
|
120 $this->refreshUpdateStatus($xml_mapping);
|
Chris@0
|
121
|
Chris@0
|
122 // Run the updates for the new module.
|
Chris@0
|
123 $this->drupalPostForm('admin/reports/updates/update', ['projects[update_test_new_module]' => TRUE], t('Download these updates'));
|
Chris@0
|
124 $this->drupalPostForm(NULL, ['maintenance_mode' => FALSE], t('Continue'));
|
Chris@0
|
125 $this->assertText(t('Update was completed successfully.'));
|
Chris@0
|
126 $this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module']));
|
Chris@0
|
127
|
Chris@0
|
128 // Parse the info file again to check that the module has been updated to
|
Chris@0
|
129 // 8.x-1.1.
|
Chris@0
|
130 $info = $info_parser->parse($installedInfoFilePath);
|
Chris@0
|
131 $this->assertEqual($info['version'], '8.x-1.1');
|
Chris@0
|
132 }
|
Chris@0
|
133
|
Chris@0
|
134 /**
|
Chris@0
|
135 * Ensures that archiver extensions are properly merged in the UI.
|
Chris@0
|
136 */
|
Chris@0
|
137 public function testFileNameExtensionMerging() {
|
Chris@0
|
138 $this->drupalGet('admin/modules/install');
|
Chris@0
|
139 // Make sure the bogus extension supported by update_test.module is there.
|
Chris@0
|
140 $this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension.");
|
Chris@0
|
141 // Make sure it didn't clobber the first option from core.
|
Chris@0
|
142 $this->assertPattern('/file extensions are supported:.*tar/', "Found 'tar' extension.");
|
Chris@0
|
143 }
|
Chris@0
|
144
|
Chris@0
|
145 /**
|
Chris@0
|
146 * Checks the messages on update manager pages when missing a security update.
|
Chris@0
|
147 */
|
Chris@0
|
148 public function testUpdateManagerCoreSecurityUpdateMessages() {
|
Chris@0
|
149 $setting = [
|
Chris@0
|
150 '#all' => [
|
Chris@0
|
151 'version' => '8.0.0',
|
Chris@0
|
152 ],
|
Chris@0
|
153 ];
|
Chris@0
|
154 $this->config('update_test.settings')
|
Chris@0
|
155 ->set('system_info', $setting)
|
Chris@0
|
156 ->set('xml_map', ['drupal' => '0.2-sec'])
|
Chris@0
|
157 ->save();
|
Chris@0
|
158 $this->config('update.settings')
|
Chris@0
|
159 ->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
|
Chris@0
|
160 ->save();
|
Chris@0
|
161 // Initialize the update status.
|
Chris@0
|
162 $this->drupalGet('admin/reports/updates');
|
Chris@0
|
163
|
Chris@0
|
164 // Now, make sure none of the Update manager pages have duplicate messages
|
Chris@0
|
165 // about core missing a security update.
|
Chris@0
|
166
|
Chris@0
|
167 $this->drupalGet('admin/modules/install');
|
Chris@0
|
168 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
169
|
Chris@0
|
170 $this->drupalGet('admin/modules/update');
|
Chris@0
|
171 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
172
|
Chris@0
|
173 $this->drupalGet('admin/appearance/install');
|
Chris@0
|
174 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
175
|
Chris@0
|
176 $this->drupalGet('admin/appearance/update');
|
Chris@0
|
177 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
178
|
Chris@0
|
179 $this->drupalGet('admin/reports/updates/install');
|
Chris@0
|
180 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
181
|
Chris@0
|
182 $this->drupalGet('admin/reports/updates/update');
|
Chris@0
|
183 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
184
|
Chris@0
|
185 $this->drupalGet('admin/update/ready');
|
Chris@0
|
186 $this->assertNoText(t('There is a security update available for your version of Drupal.'));
|
Chris@0
|
187 }
|
Chris@0
|
188
|
Chris@0
|
189 /**
|
Chris@0
|
190 * Tests only an *.info.yml file are detected without supporting files.
|
Chris@0
|
191 */
|
Chris@0
|
192 public function testUpdateDirectory() {
|
Chris@17
|
193 $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/modules/aaa_update_test');
|
Chris@0
|
194 $this->assertEqual($type, 'Drupal\\Core\\Updater\\Module', 'Detected a Module');
|
Chris@0
|
195
|
Chris@17
|
196 $type = Updater::getUpdaterFromDirectory($this->root . '/core/modules/update/tests/themes/update_test_basetheme');
|
Chris@0
|
197 $this->assertEqual($type, 'Drupal\\Core\\Updater\\Theme', 'Detected a Theme.');
|
Chris@0
|
198 }
|
Chris@0
|
199
|
Chris@0
|
200 }
|