-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
80 lines (51 loc) · 1.66 KB
/
test.php
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
<?php
// Load classes
require_once('class.tdcron.php');
require_once('class.tdcron.entry.php');
// Load tests
require_once('test.data.php');
// Rock it....
$ok = 0;
$fail = 0;
echo "\n".str_repeat('-',80)."\n";
echo 'Testing '.count($tests).' expressions...';
echo "\n\n".str_repeat('-',80)."\n";
foreach ($tests as $curtest) {
try {
if (!empty($curtest['desc'])) {
echo 'Description: ['.$curtest['desc'].']'."\n";
}
echo 'Expression: ['.$curtest['expression'].']'."\n";
echo 'Ref-Time: ['.date('d.m.Y, H:i:s', $curtest['reftime'])."]\n\n";
if (isset($curtest['expected_n'])) {
echo 'nextRun(): ['.date('d.m.Y, H:i:s', tdCron::getNextOccurrence($curtest['expression'],$curtest['reftime']))."]\n";
echo 'Expected: ['.$curtest['expected_n']."] - ";
if (date('d.m.Y, H:i:s', tdCron::getNextOccurrence($curtest['expression'],$curtest['reftime'])) == $curtest['expected_n']) {
echo 'passed!';
$ok++;
} else {
echo 'FAILED!';
$fail++;
}
echo "\n\n";
}
if (isset($curtest['expected_l'])) {
echo 'lastRun(): ['.date('d.m.Y, H:i:s', tdCron::getLastOccurrence($curtest['expression'],$curtest['reftime']))."]\n";
echo 'Expected: ['.$curtest['expected_l']."] - ";
if (date('d.m.Y, H:i:s', tdCron::getLastOccurrence($curtest['expression'],$curtest['reftime'])) == $curtest['expected_l']) {
echo 'passed!';
$ok++;
} else {
echo 'FAILED!';
$fail++;
}
echo "\n\n";
}
} catch (Exception $e) {
echo 'ERROR!'."\n\n";
print_r($e);
}
echo str_repeat('-',80)."\n";
}
echo 'OK: '.$ok."\n";
echo 'FAIL: '.$fail."\n";