1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
<?php
declare(strict_types=1);
namespace Drupal\Tests\update\Functional;
use Drupal\Core\Url;
use Drupal\Tests\Traits\Core\CronRunTrait;
/**
* Tests general functionality of the Update Status module.
*
* @group update
*/
class UpdateMiscTest extends UpdateTestBase {
use CronRunTrait;
/**
* {@inheritdoc}
*/
protected static $modules = ['language', 'block'];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$setting = [
'#all' => [
'version' => '8.0.0',
],
];
$this->config('update_test.settings')->set('system_info', $setting)->save();
$this->drupalPlaceBlock('local_actions_block');
}
/**
* Tests the Update Status module when the update server returns 503 errors.
*/
public function testServiceUnavailable(): void {
$admin_user = $this->drupalCreateUser([
'administer site configuration',
]);
$this->drupalLogin($admin_user);
$this->refreshUpdateStatus([], '503-error');
// Ensure that no "Warning: SimpleXMLElement..." parse errors are found.
$this->assertSession()->pageTextNotContains('SimpleXMLElement');
$this->assertSession()->pageTextContainsOnce('Failed to get available update data for one project.');
}
/**
* Tests that exactly one fetch task per project is created and not more.
*/
public function testFetchTasks(): void {
$project_a = [
'name' => 'aaa_update_test',
];
$project_b = [
'name' => 'bbb_update_test',
];
$queue = \Drupal::queue('update_fetch_tasks');
$this->assertEquals(0, $queue->numberOfItems(), 'Queue is empty');
update_create_fetch_task($project_a);
$this->assertEquals(1, $queue->numberOfItems(), 'Queue contains one item');
update_create_fetch_task($project_b);
$this->assertEquals(2, $queue->numberOfItems(), 'Queue contains two items');
// Try to add a project again.
update_create_fetch_task($project_a);
$this->assertEquals(2, $queue->numberOfItems(), 'Queue still contains two items');
// Clear storage and try again.
update_storage_clear();
update_create_fetch_task($project_a);
$this->assertEquals(2, $queue->numberOfItems(), 'Queue contains two items');
}
/**
* Checks the messages at admin/modules when the site is up to date.
*/
public function testModulePageUpToDate(): void {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
'view update notifications',
]));
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')
->setAbsolute()
->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', ['drupal' => '8.0.0'])
->save();
$this->drupalGet('admin/reports/updates');
$this->clickLink('Check manually');
$this->checkForMetaRefresh();
$this->assertSession()->pageTextContains('Checked available update data for one project.');
$this->drupalGet('admin/modules');
$this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
$this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');
}
/**
* Checks the messages at admin/modules when an update is missing.
*/
public function testModulePageRegularUpdate(): void {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
'administer modules',
'view update notifications',
]));
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', ['drupal' => '8.0.1'])
->save();
$this->drupalGet('admin/reports/updates');
$this->clickLink('Check manually');
$this->checkForMetaRefresh();
$this->assertSession()->pageTextContains('Checked available update data for one project.');
$this->drupalGet('admin/modules');
$this->assertSession()->pageTextContains('There are updates available for your version of Drupal.');
$this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');
// A user without the "view update notifications" permission shouldn't be
// notified about available updates.
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
'administer modules',
]));
$this->drupalGet('admin/modules');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
}
/**
* Checks the messages at admin/modules when a security update is missing.
*/
public function testModulePageSecurityUpdate(): void {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
'administer modules',
'administer themes',
'view update notifications',
]));
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->mockReleaseHistory(['drupal' => 'sec.8.0.2']);
$this->drupalGet('admin/reports/updates');
$this->clickLink('Check manually');
$this->checkForMetaRefresh();
$this->assertSession()->pageTextContains('Checked available update data for one project.');
$this->drupalGet('admin/modules');
$this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
$this->assertSession()->pageTextContains('There is a security update available for your version of Drupal.');
// Make sure admin/appearance warns you you're missing a security update.
$this->drupalGet('admin/appearance');
$this->assertSession()->pageTextNotContains('There are updates available for your version of Drupal.');
$this->assertSession()->pageTextContains('There is a security update available for your version of Drupal.');
// Make sure duplicate messages don't appear on Update status pages.
$this->drupalGet('admin/reports/status');
$this->assertSession()->pageTextContainsOnce('There is a security update available for your version of Drupal.');
$this->drupalGet('admin/reports/updates');
$this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');
$this->drupalGet('admin/reports/updates/settings');
$this->assertSession()->pageTextNotContains('There is a security update available for your version of Drupal.');
}
/**
* Checks that running cron updates the list of available updates.
*/
public function testModulePageRunCron(): void {
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->mockReleaseHistory(['drupal' => '8.0.0']);
$this->cronRun();
$this->drupalGet('admin/modules');
$this->assertSession()->pageTextNotContains('No update information available.');
}
/**
* Checks language module in core package at admin/reports/updates.
*/
public function testLanguageModuleUpdate(): void {
$this->drupalLogin($this->drupalCreateUser([
'administer site configuration',
]));
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->mockReleaseHistory(['drupal' => '0.1']);
$this->drupalGet('admin/reports/updates');
$this->assertSession()->pageTextContains('Language');
}
}
|