blob: b6fd573122f5193f3fcabf3e555acd2317793f16 (
plain)
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
|
<?php
/*
* Copyright (C) 2013 - Jan-Hendrik Willms <tleilax+studip@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
class CronjobTestSchedule extends SimpleORMap
{
}
class CronjobScheduleTest extends \Codeception\Test\Unit
{
function setUp(): void
{
date_default_timezone_set('Europe/Berlin');
StudipTestHelper::set_up_tables(['cronjobs_schedules', 'cronjobs_tasks']);
}
function tearDown(): void
{
StudipTestHelper::tear_down_tables();
}
function testPeriodicSchedule()
{
$schedule = new CronjobSchedule();
$schedule->minute = null;
$schedule->hour = null;
$schedule->day = null;
$schedule->month = null;
$schedule->day_of_week = null;
return $schedule;
}
/**
* @depends testPeriodicSchedule
*/
function testNextExecutionPeriodicMinutely($schedule)
{
$now = strtotime('10.11.2013 01:02:00');
$then = strtotime('10.11.2013 01:03:00');
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
/**
* @depends testPeriodicSchedule
*/
function testNextExecutionPeriodicHourly($schedule)
{
$now = strtotime('10.11.2013 01:02:00');
$then = strtotime('10.11.2013 02:00:00');
$schedule->minute = 0;
$schedule->hour = null;
$schedule->day = null;
$schedule->month = null;
$schedule->day_of_week = null;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
/**
* @depends testPeriodicSchedule
*/
function testNextExecutionPeriodicDaily($schedule)
{
$now = strtotime('10.11.2013 01:02:00');
$then = strtotime('11.11.2013 00:00:00');
$schedule->minute = 0;
$schedule->hour = 0;
$schedule->day = null;
$schedule->month = null;
$schedule->day_of_week = null;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
/**
* @depends testPeriodicSchedule
*/
function testNextExecutionPeriodicMonthly($schedule)
{
$now = strtotime('10.11.2013 01:02:00');
$then = strtotime('01.12.2013 00:00:00');
$schedule->minute = 0;
$schedule->hour = 0;
$schedule->day = 1;
$schedule->month = null;
$schedule->day_of_week = null;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
/*
* @depends testPeriodicSchedule
function testNextExecutionPeriodicYearly($schedule)
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete('This section needs to be optimized so this test is skipped.');
$now = strtotime('01.01.2013 00:01:00');
$then = strtotime('01.01.2014 00:00:00');
$schedule->minute = 0;
$schedule->hour = 0;
$schedule->day = 1;
$schedule->month = 1;
$schedule->day_of_week = null;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
*/
/**
* @depends testPeriodicSchedule
*/
function testNextExecutionPeriodicFriday($schedule)
{
$now = strtotime('10.11.2013 01:02:00');
$then = strtotime('next friday 0:00:00', $now);
$schedule->minute = null;
$schedule->hour = null;
$schedule->day = null;
$schedule->month = null;
$schedule->day_of_week = 5;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
/**
* @depends testPeriodicSchedule
*/
function testBuggyConditions($schedule)
{
$now = strtotime('16.04.2013 01:10:00');
$then = strtotime('17.04.2013 01:07:00');
$schedule->minute = 7;
$schedule->hour = 1;
$schedule->day = null;
$schedule->month = null;
$schedule->day_of_week = null;
$schedule->calculateNextExecution($now);
$this->assertEquals($then, $schedule->next_execution);
}
}
|