| Línea 32... |
Línea 32... |
| 32 |
* @copyright 2012, 2015 David Mudrak <david@moodle.com>
|
32 |
* @copyright 2012, 2015 David Mudrak <david@moodle.com>
|
| 33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 34 |
*/
|
34 |
*/
|
| 35 |
class update_checker_test extends \advanced_testcase {
|
35 |
class update_checker_test extends \advanced_testcase {
|
| Línea 36... |
Línea 36... |
| 36 |
|
36 |
|
| 37 |
public function test_core_available_update() {
|
37 |
public function test_core_available_update(): void {
|
| 38 |
$provider = testable_checker::instance();
|
38 |
$provider = testable_checker::instance();
|
| Línea 39... |
Línea 39... |
| 39 |
$this->assertInstanceOf('\core\update\checker', $provider);
|
39 |
$this->assertInstanceOf('\core\update\checker', $provider);
|
| 40 |
|
40 |
|
| Línea 52... |
Línea 52... |
| 52 |
}
|
52 |
}
|
| Línea 53... |
Línea 53... |
| 53 |
|
53 |
|
| 54 |
/**
|
54 |
/**
|
| 55 |
* If there are no fetched data yet, the first cron should fetch them.
|
55 |
* If there are no fetched data yet, the first cron should fetch them.
|
| 56 |
*/
|
56 |
*/
|
| 57 |
public function test_cron_initial_fetch() {
|
57 |
public function test_cron_initial_fetch(): void {
|
| 58 |
$provider = testable_checker::instance();
|
58 |
$provider = testable_checker::instance();
|
| 59 |
$provider->fakerecentfetch = null;
|
59 |
$provider->fakerecentfetch = null;
|
| 60 |
$provider->fakecurrenttimestamp = -1;
|
60 |
$provider->fakecurrenttimestamp = -1;
|
| 61 |
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
61 |
$this->expectException(\core\update\testable_checker_cron_executed::class);
|
| 62 |
$provider->cron();
|
62 |
$provider->cron();
|
| Línea 63... |
Línea 63... |
| 63 |
}
|
63 |
}
|
| 64 |
|
64 |
|
| 65 |
/**
|
65 |
/**
|
| 66 |
* If there is a fresh fetch available, no cron execution is expected.
|
66 |
* If there is a fresh fetch available, no cron execution is expected.
|
| 67 |
*/
|
67 |
*/
|
| 68 |
public function test_cron_has_fresh_fetch() {
|
68 |
public function test_cron_has_fresh_fetch(): void {
|
| 69 |
$provider = testable_checker::instance();
|
69 |
$provider = testable_checker::instance();
|
| 70 |
$provider->fakerecentfetch = time() - 23 * HOURSECS; // Fetched 23 hours ago.
|
70 |
$provider->fakerecentfetch = time() - 23 * HOURSECS; // Fetched 23 hours ago.
|
| 71 |
$provider->fakecurrenttimestamp = -1;
|
71 |
$provider->fakecurrenttimestamp = -1;
|
| 72 |
$provider->cron();
|
72 |
$provider->cron();
|
| Línea 73... |
Línea 73... |
| 73 |
$this->assertTrue(true); // We should get here with no exception thrown.
|
73 |
$this->assertTrue(true); // We should get here with no exception thrown.
|
| 74 |
}
|
74 |
}
|
| 75 |
|
75 |
|
| 76 |
/**
|
76 |
/**
|
| 77 |
* If there is an outdated fetch, the cron execution is expected.
|
77 |
* If there is an outdated fetch, the cron execution is expected.
|
| 78 |
*/
|
78 |
*/
|
| 79 |
public function test_cron_has_outdated_fetch() {
|
79 |
public function test_cron_has_outdated_fetch(): void {
|
| 80 |
$provider = testable_checker::instance();
|
80 |
$provider = testable_checker::instance();
|
| 81 |
$provider->fakerecentfetch = time() - 49 * HOURSECS; // Fetched 49 hours ago.
|
81 |
$provider->fakerecentfetch = time() - 49 * HOURSECS; // Fetched 49 hours ago.
|
| Línea 87... |
Línea 87... |
| 87 |
/**
|
87 |
/**
|
| 88 |
* The first cron after 01:42 AM today should fetch the data.
|
88 |
* The first cron after 01:42 AM today should fetch the data.
|
| 89 |
*
|
89 |
*
|
| 90 |
* @see testable_checker::cron_execution_offset()
|
90 |
* @see testable_checker::cron_execution_offset()
|
| 91 |
*/
|
91 |
*/
|
| 92 |
public function test_cron_offset_execution_not_yet() {
|
92 |
public function test_cron_offset_execution_not_yet(): void {
|
| 93 |
$provider = testable_checker::instance();
|
93 |
$provider = testable_checker::instance();
|
| 94 |
$provider->fakecurrenttimestamp = mktime(1, 40, 02); // 01:40:02 AM today
|
94 |
$provider->fakecurrenttimestamp = mktime(1, 40, 02); // 01:40:02 AM today
|
| 95 |
$provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS;
|
95 |
$provider->fakerecentfetch = $provider->fakecurrenttimestamp - 24 * HOURSECS;
|
| 96 |
$provider->cron();
|
96 |
$provider->cron();
|
| 97 |
$this->assertTrue(true); // We should get here with no exception thrown.
|
97 |
$this->assertTrue(true); // We should get here with no exception thrown.
|
| Línea 101... |
Línea 101... |
| 101 |
* The first cron after 01:42 AM today should fetch the data and then
|
101 |
* The first cron after 01:42 AM today should fetch the data and then
|
| 102 |
* it is supposed to wait next 24 hours.
|
102 |
* it is supposed to wait next 24 hours.
|
| 103 |
*
|
103 |
*
|
| 104 |
* @see testable_checker::cron_execution_offset()
|
104 |
* @see testable_checker::cron_execution_offset()
|
| 105 |
*/
|
105 |
*/
|
| 106 |
public function test_cron_offset_execution() {
|
106 |
public function test_cron_offset_execution(): void {
|
| 107 |
$provider = testable_checker::instance();
|
107 |
$provider = testable_checker::instance();
|
| Línea 108... |
Línea 108... |
| 108 |
|
108 |
|
| 109 |
// The cron at 01:45 should fetch the data.
|
109 |
// The cron at 01:45 should fetch the data.
|
| 110 |
$provider->fakecurrenttimestamp = mktime(1, 45, 02); // 01:45:02 AM today
|
110 |
$provider->fakecurrenttimestamp = mktime(1, 45, 02); // 01:45:02 AM today
|
| Línea 137... |
Línea 137... |
| 137 |
$executed = true;
|
137 |
$executed = true;
|
| 138 |
}
|
138 |
}
|
| 139 |
$this->assertTrue($executed, 'Cron should be executed the next night but it was not.');
|
139 |
$this->assertTrue($executed, 'Cron should be executed the next night but it was not.');
|
| 140 |
}
|
140 |
}
|
| Línea 141... |
Línea 141... |
| 141 |
|
141 |
|
| 142 |
public function test_compare_responses_both_empty() {
|
142 |
public function test_compare_responses_both_empty(): void {
|
| 143 |
$provider = testable_checker::instance();
|
143 |
$provider = testable_checker::instance();
|
| 144 |
$old = array();
|
144 |
$old = array();
|
| 145 |
$new = array();
|
145 |
$new = array();
|
| 146 |
$cmp = $provider->compare_responses($old, $new);
|
146 |
$cmp = $provider->compare_responses($old, $new);
|
| 147 |
$this->assertIsArray($cmp);
|
147 |
$this->assertIsArray($cmp);
|
| 148 |
$this->assertEmpty($cmp);
|
148 |
$this->assertEmpty($cmp);
|
| Línea 149... |
Línea 149... |
| 149 |
}
|
149 |
}
|
| 150 |
|
150 |
|
| 151 |
public function test_compare_responses_old_empty() {
|
151 |
public function test_compare_responses_old_empty(): void {
|
| 152 |
$provider = testable_checker::instance();
|
152 |
$provider = testable_checker::instance();
|
| 153 |
$old = array();
|
153 |
$old = array();
|
| 154 |
$new = array(
|
154 |
$new = array(
|
| Línea 165... |
Línea 165... |
| 165 |
$this->assertNotEmpty($cmp);
|
165 |
$this->assertNotEmpty($cmp);
|
| 166 |
$this->assertTrue(isset($cmp['core'][0]['version']));
|
166 |
$this->assertTrue(isset($cmp['core'][0]['version']));
|
| 167 |
$this->assertEquals(2012060103, $cmp['core'][0]['version']);
|
167 |
$this->assertEquals(2012060103, $cmp['core'][0]['version']);
|
| 168 |
}
|
168 |
}
|
| Línea 169... |
Línea 169... |
| 169 |
|
169 |
|
| 170 |
public function test_compare_responses_no_change() {
|
170 |
public function test_compare_responses_no_change(): void {
|
| 171 |
$provider = testable_checker::instance();
|
171 |
$provider = testable_checker::instance();
|
| 172 |
$old = $new = array(
|
172 |
$old = $new = array(
|
| 173 |
'updates' => array(
|
173 |
'updates' => array(
|
| 174 |
'core' => array(
|
174 |
'core' => array(
|
| Línea 189... |
Línea 189... |
| 189 |
$cmp = $provider->compare_responses($old, $new);
|
189 |
$cmp = $provider->compare_responses($old, $new);
|
| 190 |
$this->assertIsArray($cmp);
|
190 |
$this->assertIsArray($cmp);
|
| 191 |
$this->assertEmpty($cmp);
|
191 |
$this->assertEmpty($cmp);
|
| 192 |
}
|
192 |
}
|
| Línea 193... |
Línea 193... |
| 193 |
|
193 |
|
| 194 |
public function test_compare_responses_new_and_missing_update() {
|
194 |
public function test_compare_responses_new_and_missing_update(): void {
|
| 195 |
$provider = testable_checker::instance();
|
195 |
$provider = testable_checker::instance();
|
| 196 |
$old = array(
|
196 |
$old = array(
|
| 197 |
'updates' => array(
|
197 |
'updates' => array(
|
| 198 |
'core' => array(
|
198 |
'core' => array(
|
| Línea 225... |
Línea 225... |
| 225 |
$this->assertCount(1, $cmp);
|
225 |
$this->assertCount(1, $cmp);
|
| 226 |
$this->assertCount(1, $cmp['core']);
|
226 |
$this->assertCount(1, $cmp['core']);
|
| 227 |
$this->assertEquals(2012120100, $cmp['core'][0]['version']);
|
227 |
$this->assertEquals(2012120100, $cmp['core'][0]['version']);
|
| 228 |
}
|
228 |
}
|
| Línea 229... |
Línea 229... |
| 229 |
|
229 |
|
| 230 |
public function test_compare_responses_modified_update() {
|
230 |
public function test_compare_responses_modified_update(): void {
|
| 231 |
$provider = testable_checker::instance();
|
231 |
$provider = testable_checker::instance();
|
| 232 |
$old = array(
|
232 |
$old = array(
|
| 233 |
'updates' => array(
|
233 |
'updates' => array(
|
| 234 |
'mod_foo' => array(
|
234 |
'mod_foo' => array(
|
| Línea 253... |
Línea 253... |
| 253 |
$this->assertCount(1, $cmp);
|
253 |
$this->assertCount(1, $cmp);
|
| 254 |
$this->assertCount(1, $cmp['mod_foo']);
|
254 |
$this->assertCount(1, $cmp['mod_foo']);
|
| 255 |
$this->assertEquals(2011010102, $cmp['mod_foo'][0]['version']);
|
255 |
$this->assertEquals(2011010102, $cmp['mod_foo'][0]['version']);
|
| 256 |
}
|
256 |
}
|
| Línea 257... |
Línea 257... |
| 257 |
|
257 |
|
| 258 |
public function test_compare_responses_invalid_format() {
|
258 |
public function test_compare_responses_invalid_format(): void {
|
| 259 |
$provider = testable_checker::instance();
|
259 |
$provider = testable_checker::instance();
|
| 260 |
$broken = array(
|
260 |
$broken = array(
|
| 261 |
'status' => 'ERROR' // No 'updates' key here.
|
261 |
'status' => 'ERROR' // No 'updates' key here.
|
| 262 |
);
|
262 |
);
|
| 263 |
$this->expectException(\core\update\checker_exception::class);
|
263 |
$this->expectException(\core\update\checker_exception::class);
|
| 264 |
$cmp = $provider->compare_responses($broken, $broken);
|
264 |
$cmp = $provider->compare_responses($broken, $broken);
|
| Línea 265... |
Línea 265... |
| 265 |
}
|
265 |
}
|
| 266 |
|
266 |
|
| 267 |
public function test_is_same_release_explicit() {
|
267 |
public function test_is_same_release_explicit(): void {
|
| 268 |
$provider = testable_checker::instance();
|
268 |
$provider = testable_checker::instance();
|
| 269 |
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120323)'));
|
269 |
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120323)'));
|
| 270 |
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120330)'));
|
270 |
$this->assertTrue($provider->is_same_release('2.3dev (Build: 20120323)', '2.3dev (Build: 20120330)'));
|
| Línea 276... |
Línea 276... |
| 276 |
$this->assertTrue($provider->is_same_release('2.3.2 (Build: 123456)', '2.3.2+ (Build: 123457)'));
|
276 |
$this->assertTrue($provider->is_same_release('2.3.2 (Build: 123456)', '2.3.2+ (Build: 123457)'));
|
| 277 |
$this->assertFalse($provider->is_same_release('3.0 Community Edition', '3.0 Enterprise Edition'));
|
277 |
$this->assertFalse($provider->is_same_release('3.0 Community Edition', '3.0 Enterprise Edition'));
|
| 278 |
$this->assertTrue($provider->is_same_release('3.0 Community Edition', '3.0 Community Edition (Build: 20290101)'));
|
278 |
$this->assertTrue($provider->is_same_release('3.0 Community Edition', '3.0 Community Edition (Build: 20290101)'));
|
| 279 |
}
|
279 |
}
|
| Línea 280... |
Línea 280... |
| 280 |
|
280 |
|
| 281 |
public function test_is_same_release_implicit() {
|
281 |
public function test_is_same_release_implicit(): void {
|
| 282 |
$provider = testable_checker::instance();
|
282 |
$provider = testable_checker::instance();
|
| 283 |
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
|
283 |
$provider->fake_current_environment(2012060102.00, '2.3.2 (Build: 20121012)', '2.3', array());
|
| 284 |
$this->assertTrue($provider->is_same_release('2.3.2'));
|
284 |
$this->assertTrue($provider->is_same_release('2.3.2'));
|
| 285 |
$this->assertTrue($provider->is_same_release('2.3.2+'));
|
285 |
$this->assertTrue($provider->is_same_release('2.3.2+'));
|