MDL-36315 backup: reduce the DST tests failing-window
[moodle.git] / backup / util / helper / tests / cronhelper_test.php
CommitLineData
68480630
FM
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
70746c43 18 * Unit tests for backups cron helper.
68480630 19 *
70746c43 20 * @package core_backup
68480630
FM
21 * @category phpunit
22 * @copyright 2012 Frédéric Massart <fred@moodle.com>
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 */
25
26defined('MOODLE_INTERNAL') || die();
27
28global $CFG;
29require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php');
30
31/**
70746c43 32 * Unit tests for backup cron helper
68480630 33 */
70746c43 34class backup_cron_helper_testcase extends advanced_testcase {
68480630 35
70746c43
FM
36 /**
37 * Test {@link backup_cron_automated_helper::calculate_next_automated_backup}.
38 */
68480630 39 public function test_next_automated_backup() {
68480630 40 $this->resetAfterTest();
68576ef6 41 set_config('backup_auto_active', '1', 'backup');
68480630
FM
42
43 // Notes
68480630 44 // - backup_auto_weekdays starts on Sunday
68576ef6
FM
45 // - Tests cannot be done in the past
46 // - Only the DST on the server side is handled.
68480630 47
68576ef6 48 // Every Tue and Fri at 11pm.
68480630
FM
49 set_config('backup_auto_weekdays', '0010010', 'backup');
50 set_config('backup_auto_hour', '23', 'backup');
51 set_config('backup_auto_minute', '0', 'backup');
68576ef6 52 $timezone = 99;
68480630 53
68576ef6 54 $now = strtotime('next Monday 17:00:00');
68480630
FM
55 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
56 $this->assertEquals('2-23:00', date('w-H:i', $next));
57
68576ef6 58 $now = strtotime('next Tuesday 18:00:00');
68480630 59 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
68576ef6 60 $this->assertEquals('2-23:00', date('w-H:i', $next));
68480630 61
68576ef6 62 $now = strtotime('next Wednesday 17:00:00');
68480630
FM
63 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
64 $this->assertEquals('5-23:00', date('w-H:i', $next));
65
68576ef6 66 $now = strtotime('next Thursday 17:00:00');
68480630
FM
67 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
68 $this->assertEquals('5-23:00', date('w-H:i', $next));
69
68576ef6 70 $now = strtotime('next Friday 17:00:00');
68480630 71 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
68576ef6 72 $this->assertEquals('5-23:00', date('w-H:i', $next));
68480630 73
68576ef6 74 $now = strtotime('next Saturday 17:00:00');
68480630
FM
75 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
76 $this->assertEquals('2-23:00', date('w-H:i', $next));
77
68576ef6 78 $now = strtotime('next Sunday 17:00:00');
68480630
FM
79 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
80 $this->assertEquals('2-23:00', date('w-H:i', $next));
81
82 // Every Sun and Sat at 12pm.
68480630
FM
83 set_config('backup_auto_weekdays', '1000001', 'backup');
84 set_config('backup_auto_hour', '0', 'backup');
85 set_config('backup_auto_minute', '0', 'backup');
68576ef6 86 $timezone = 99;
68480630 87
68576ef6 88 $now = strtotime('next Monday 17:00:00');
68480630
FM
89 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
90 $this->assertEquals('6-00:00', date('w-H:i', $next));
91
68576ef6 92 $now = strtotime('next Tuesday 17:00:00');
68480630
FM
93 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
94 $this->assertEquals('6-00:00', date('w-H:i', $next));
95
68576ef6 96 $now = strtotime('next Wednesday 17:00:00');
68480630
FM
97 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
98 $this->assertEquals('6-00:00', date('w-H:i', $next));
99
68576ef6 100 $now = strtotime('next Thursday 17:00:00');
68480630
FM
101 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
102 $this->assertEquals('6-00:00', date('w-H:i', $next));
103
68576ef6 104 $now = strtotime('next Friday 17:00:00');
68480630
FM
105 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
106 $this->assertEquals('6-00:00', date('w-H:i', $next));
107
68576ef6 108 $now = strtotime('next Saturday 17:00:00');
68480630
FM
109 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
110 $this->assertEquals('0-00:00', date('w-H:i', $next));
111
68576ef6 112 $now = strtotime('next Sunday 17:00:00');
68480630
FM
113 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
114 $this->assertEquals('6-00:00', date('w-H:i', $next));
115
116 // Every Sun at 4am.
68480630
FM
117 set_config('backup_auto_weekdays', '1000000', 'backup');
118 set_config('backup_auto_hour', '4', 'backup');
119 set_config('backup_auto_minute', '0', 'backup');
68576ef6 120 $timezone = 99;
68480630 121
68576ef6 122 $now = strtotime('next Monday 17:00:00');
68480630
FM
123 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
124 $this->assertEquals('0-04:00', date('w-H:i', $next));
125
68576ef6 126 $now = strtotime('next Tuesday 17:00:00');
68480630
FM
127 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
128 $this->assertEquals('0-04:00', date('w-H:i', $next));
129
68576ef6 130 $now = strtotime('next Wednesday 17:00:00');
68480630
FM
131 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
132 $this->assertEquals('0-04:00', date('w-H:i', $next));
133
68576ef6 134 $now = strtotime('next Thursday 17:00:00');
68480630
FM
135 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
136 $this->assertEquals('0-04:00', date('w-H:i', $next));
137
68576ef6 138 $now = strtotime('next Friday 17:00:00');
68480630
FM
139 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
140 $this->assertEquals('0-04:00', date('w-H:i', $next));
141
68576ef6 142 $now = strtotime('next Saturday 17:00:00');
68480630
FM
143 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
144 $this->assertEquals('0-04:00', date('w-H:i', $next));
145
68576ef6 146 $now = strtotime('next Sunday 17:00:00');
68480630
FM
147 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
148 $this->assertEquals('0-04:00', date('w-H:i', $next));
149
150 // Every day but Wed at 8:30pm.
68480630
FM
151 set_config('backup_auto_weekdays', '1110111', 'backup');
152 set_config('backup_auto_hour', '20', 'backup');
153 set_config('backup_auto_minute', '30', 'backup');
68576ef6
FM
154 $timezone = 99;
155
156 $now = strtotime('next Monday 17:00:00');
157 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
158 $this->assertEquals('1-20:30', date('w-H:i', $next));
68480630 159
68576ef6 160 $now = strtotime('next Tuesday 17:00:00');
68480630
FM
161 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
162 $this->assertEquals('2-20:30', date('w-H:i', $next));
163
68576ef6 164 $now = strtotime('next Wednesday 17:00:00');
68480630
FM
165 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
166 $this->assertEquals('4-20:30', date('w-H:i', $next));
167
68576ef6 168 $now = strtotime('next Thursday 17:00:00');
68480630
FM
169 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
170 $this->assertEquals('4-20:30', date('w-H:i', $next));
171
68576ef6 172 $now = strtotime('next Friday 17:00:00');
68480630
FM
173 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
174 $this->assertEquals('5-20:30', date('w-H:i', $next));
175
68576ef6 176 $now = strtotime('next Saturday 17:00:00');
68480630
FM
177 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
178 $this->assertEquals('6-20:30', date('w-H:i', $next));
179
68576ef6 180 $now = strtotime('next Sunday 17:00:00');
68480630
FM
181 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
182 $this->assertEquals('0-20:30', date('w-H:i', $next));
183
68576ef6
FM
184 // Sun, Tue, Thu, Sat at 12pm.
185 set_config('backup_auto_weekdays', '1010101', 'backup');
186 set_config('backup_auto_hour', '0', 'backup');
187 set_config('backup_auto_minute', '0', 'backup');
188 $timezone = 99;
189
190 $now = strtotime('next Monday 13:00:00');
e9ec895d 191 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
68576ef6
FM
192 $this->assertEquals('2-00:00', date('w-H:i', $next));
193
194 $now = strtotime('next Tuesday 13:00:00');
195 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
196 $this->assertEquals('4-00:00', date('w-H:i', $next));
197
198 $now = strtotime('next Wednesday 13:00:00');
199 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
200 $this->assertEquals('4-00:00', date('w-H:i', $next));
201
202 $now = strtotime('next Thursday 13:00:00');
203 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
204 $this->assertEquals('6-00:00', date('w-H:i', $next));
205
206 $now = strtotime('next Friday 13:00:00');
207 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
208 $this->assertEquals('6-00:00', date('w-H:i', $next));
209
210 $now = strtotime('next Saturday 13:00:00');
211 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
212 $this->assertEquals('0-00:00', date('w-H:i', $next));
213
214 $now = strtotime('next Sunday 13:00:00');
215 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
216 $this->assertEquals('2-00:00', date('w-H:i', $next));
217
218 // None.
219 set_config('backup_auto_weekdays', '0000000', 'backup');
220 set_config('backup_auto_hour', '15', 'backup');
221 set_config('backup_auto_minute', '30', 'backup');
222 $timezone = 99;
223
224 $now = strtotime('next Sunday 13:00:00');
225 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
226 $this->assertEquals('0', $next);
227
228 // Playing with timezones.
229 set_config('backup_auto_weekdays', '1111111', 'backup');
230 set_config('backup_auto_hour', '20', 'backup');
231 set_config('backup_auto_minute', '00', 'backup');
232
233 $timezone = 99;
234 date_default_timezone_set('Australia/Perth');
235 $now = strtotime('18:00:00');
236 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
237 $this->assertEquals(date('w-20:00'), date('w-H:i', $next));
238
239 $timezone = 99;
240 date_default_timezone_set('Europe/Brussels');
241 $now = strtotime('18:00:00');
242 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
243 $this->assertEquals(date('w-20:00'), date('w-H:i', $next));
244
245 $timezone = 99;
246 date_default_timezone_set('America/New_York');
247 $now = strtotime('18:00:00');
248 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
249 $this->assertEquals(date('w-20:00'), date('w-H:i', $next));
250
251 // Viva Australia! (UTC+8).
252 date_default_timezone_set('Australia/Perth');
253 $now = strtotime('18:00:00');
254
255 $timezone = -10.0; // 12am for the user.
256 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
257 $this->assertEquals(date('w-14:00', strtotime('tomorrow')), date('w-H:i', $next));
258
259 $timezone = -5.0; // 5am for the user.
260 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
261 $this->assertEquals(date('w-09:00', strtotime('tomorrow')), date('w-H:i', $next));
262
263 $timezone = 0.0; // 10am for the user.
264 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
265 $this->assertEquals(date('w-04:00', strtotime('tomorrow')), date('w-H:i', $next));
266
267 $timezone = 3.0; // 1pm for the user.
268 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
269 $this->assertEquals(date('w-01:00', strtotime('tomorrow')), date('w-H:i', $next));
270
271 $timezone = 8.0; // 6pm for the user (same than the server).
272 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
273 $this->assertEquals(date('w-20:00'), date('w-H:i', $next));
274
275 $timezone = 9.0; // 7pm for the user.
276 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
277 $this->assertEquals(date('w-19:00'), date('w-H:i', $next));
278
279 $timezone = 13.0; // 12am for the user.
280 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
281 $this->assertEquals(date('w-15:00', strtotime('tomorrow')), date('w-H:i', $next));
282
283 // Let's have a Belgian beer! (UTC+1 / UTC+2 DST).
391f8b39
EL
284 // Warning: Some of these tests will fail if executed "around"
285 // 'Europe/Brussels' DST changes (last Sunday in March and
286 // last Sunday in October right now - 2012). Once Moodle
287 // moves to PHP TZ support this could be fixed properly.
68576ef6
FM
288 date_default_timezone_set('Europe/Brussels');
289 $now = strtotime('18:00:00');
391f8b39 290 $dst = date('I', $now);
68576ef6
FM
291
292 $timezone = -10.0; // 7am for the user.
293 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
294 $expected = !$dst ? date('w-07:00', strtotime('tomorrow')) : date('w-08:00', strtotime('tomorrow'));
295 $this->assertEquals($expected, date('w-H:i', $next));
296
297 $timezone = -5.0; // 12pm for the user.
298 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
299 $expected = !$dst ? date('w-02:00', strtotime('tomorrow')) : date('w-03:00', strtotime('tomorrow'));
300 $this->assertEquals($expected, date('w-H:i', $next));
301
302 $timezone = 0.0; // 5pm for the user.
303 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
304 $expected = !$dst ? date('w-21:00') : date('w-22:00');
305 $this->assertEquals($expected, date('w-H:i', $next));
306
307 $timezone = 3.0; // 8pm for the user (note the expected time is today while in DST).
308 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
309 $expected = !$dst ? date('w-18:00', strtotime('tomorrow')) : date('w-19:00');
310 $this->assertEquals($expected, date('w-H:i', $next));
311
312 $timezone = 8.0; // 1am for the user.
313 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
314 $expected = !$dst ? date('w-13:00', strtotime('tomorrow')) : date('w-14:00', strtotime('tomorrow'));
315 $this->assertEquals($expected, date('w-H:i', $next));
316
317 $timezone = 9.0; // 2am for the user.
318 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
319 $expected = !$dst ? date('w-12:00', strtotime('tomorrow')) : date('w-13:00', strtotime('tomorrow'));
320 $this->assertEquals($expected, date('w-H:i', $next));
321
322 $timezone = 13.0; // 6am for the user.
323 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
324 $expected = !$dst ? date('w-08:00', strtotime('tomorrow')) : date('w-09:00', strtotime('tomorrow'));
325 $this->assertEquals($expected, date('w-H:i', $next));
326
327 // The big apple! (UTC-5 / UTC-4 DST).
391f8b39
EL
328 // Warning: Some of these tests will fail if executed "around"
329 // 'America/New_York' DST changes (2nd Sunday in March and
330 // 1st Sunday in November right now - 2012). Once Moodle
331 // moves to PHP TZ support this could be fixed properly.
68576ef6
FM
332 date_default_timezone_set('America/New_York');
333 $now = strtotime('18:00:00');
391f8b39 334 $dst = date('I', $now);
68576ef6
FM
335
336 $timezone = -10.0; // 1pm for the user.
337 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
338 $expected = !$dst ? date('w-01:00', strtotime('tomorrow')) : date('w-02:00', strtotime('tomorrow'));
339 $this->assertEquals($expected, date('w-H:i', $next));
340
341 $timezone = -5.0; // 6pm for the user (server time).
342 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
343 $expected = !$dst ? date('w-20:00') : date('w-21:00');
344 $this->assertEquals($expected, date('w-H:i', $next));
345
346 $timezone = 0.0; // 11pm for the user.
347 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
348 $expected = !$dst ? date('w-15:00', strtotime('tomorrow')) : date('w-16:00', strtotime('tomorrow'));
349 $this->assertEquals($expected, date('w-H:i', $next));
350
351 $timezone = 3.0; // 2am for the user.
352 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
353 $expected = !$dst ? date('w-12:00', strtotime('tomorrow')) : date('w-13:00', strtotime('tomorrow'));
354 $this->assertEquals($expected, date('w-H:i', $next));
355
356 $timezone = 8.0; // 7am for the user.
357 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
358 $expected = !$dst ? date('w-07:00', strtotime('tomorrow')) : date('w-08:00', strtotime('tomorrow'));
359 $this->assertEquals($expected, date('w-H:i', $next));
360
361 $timezone = 9.0; // 8am for the user.
362 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
363 $expected = !$dst ? date('w-06:00', strtotime('tomorrow')) : date('w-07:00', strtotime('tomorrow'));
364 $this->assertEquals($expected, date('w-H:i', $next));
365
366 $timezone = 13.0; // 6am for the user.
367 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
368 $expected = !$dst ? date('w-02:00', strtotime('tomorrow')) : date('w-03:00', strtotime('tomorrow'));
369 $this->assertEquals($expected, date('w-H:i', $next));
370
371 // Some more timezone tests
372 set_config('backup_auto_weekdays', '0100001', 'backup');
373 set_config('backup_auto_hour', '20', 'backup');
374 set_config('backup_auto_minute', '00', 'backup');
375
391f8b39
EL
376 // Note: These tests should not fail because they are "unnafected"
377 // by DST changes, as far as execution always happens on Monday and
378 // Saturday and those week days are not, right now, the ones rulez
379 // to peform the DST changes (Sunday is). This may change if rules
380 // are modified in the future.
68576ef6
FM
381 date_default_timezone_set('Europe/Brussels');
382 $now = strtotime('next Monday 18:00:00');
391f8b39 383 $dst = date('I', $now);
68576ef6
FM
384
385 $timezone = -12.0; // 1pm for the user.
386 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
387 $expected = !$dst ? '2-09:00' : '2-10:00';
388 $this->assertEquals($expected, date('w-H:i', $next));
389
390 $timezone = -4.0; // 1pm for the user.
391 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
392 $expected = !$dst ? '2-01:00' : '2-02:00';
393 $this->assertEquals($expected, date('w-H:i', $next));
394
395 $timezone = 0.0; // 5pm for the user.
396 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
397 $expected = !$dst ? '1-21:00' : '1-22:00';
398 $this->assertEquals($expected, date('w-H:i', $next));
399
400 $timezone = 2.0; // 7pm for the user.
401 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
402 $expected = !$dst ? '1-19:00' : '1-20:00';
403 $this->assertEquals($expected, date('w-H:i', $next));
404
405 $timezone = 4.0; // 9pm for the user.
406 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
407 $expected = !$dst ? '6-17:00' : '6-18:00';
408 $this->assertEquals($expected, date('w-H:i', $next));
409
410 $timezone = 12.0; // 6am for the user.
411 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
412 $expected = !$dst ? '6-09:00' : '6-10:00';
413 $this->assertEquals($expected, date('w-H:i', $next));
414
415 // Some more timezone tests
416 set_config('backup_auto_weekdays', '0100001', 'backup');
417 set_config('backup_auto_hour', '02', 'backup');
418 set_config('backup_auto_minute', '00', 'backup');
419
391f8b39
EL
420 // Note: These tests should not fail because they are "unnafected"
421 // by DST changes, as far as execution always happens on Monday and
422 // Saturday and those week days are not, right now, the ones rulez
423 // to peform the DST changes (Sunday is). This may change if rules
424 // are modified in the future.
68576ef6
FM
425 date_default_timezone_set('America/New_York');
426 $now = strtotime('next Monday 04:00:00');
391f8b39 427 $dst = date('I', $now);
68576ef6
FM
428
429 $timezone = -12.0; // 8pm for the user.
430 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
431 $expected = !$dst ? '1-09:00' : '1-10:00';
432 $this->assertEquals($expected, date('w-H:i', $next));
433
434 $timezone = -4.0; // 4am for the user.
435 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
436 $expected = !$dst ? '6-01:00' : '6-02:00';
437 $this->assertEquals($expected, date('w-H:i', $next));
438
439 $timezone = 0.0; // 8am for the user.
440 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
441 $expected = !$dst ? '5-21:00' : '5-22:00';
442 $this->assertEquals($expected, date('w-H:i', $next));
443
444 $timezone = 2.0; // 10am for the user.
445 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
446 $expected = !$dst ? '5-19:00' : '5-20:00';
447 $this->assertEquals($expected, date('w-H:i', $next));
448
449 $timezone = 4.0; // 12pm for the user.
450 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
451 $expected = !$dst ? '5-17:00' : '5-18:00';
452 $this->assertEquals($expected, date('w-H:i', $next));
453
454 $timezone = 12.0; // 8pm for the user.
455 $next = backup_cron_automated_helper::calculate_next_automated_backup($timezone, $now);
456 $expected = !$dst ? '5-09:00' : '5-10:00';
457 $this->assertEquals($expected, date('w-H:i', $next));
68480630
FM
458
459 }
460}