1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @author Andrew Aitken-Fincham <[email protected]> |
5
|
|
|
*/ |
6
|
|
|
class CleanupJobTest extends SapphireTest { |
|
|
|
|
7
|
|
|
|
8
|
|
|
protected static $fixture_file = 'CleanupJobFixture.yml'; |
9
|
|
|
|
10
|
|
|
public function setUp() { |
11
|
|
|
parent::setUp(); |
12
|
|
|
// Have to set a fake time here to work with |
13
|
|
|
// the LastEdited dates in the fixture |
14
|
|
|
SS_Datetime::set_mock_now("02-02-03 02:02:02"); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public function tearDown() { |
18
|
|
|
parent::tearDown(); |
19
|
|
|
SS_Datetime::clear_mock_now(); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
View Code Duplication |
public function testByDays() { |
|
|
|
|
23
|
|
|
$job = new CleanupJob(); |
24
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_method', 'age'); |
25
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_value', 30); |
26
|
|
|
Config::inst()->remove('CleanupJob', 'cleanup_statuses'); |
27
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_statuses', |
28
|
|
|
array('Broken', 'Complete')); |
29
|
|
|
$job->process(); |
30
|
|
|
$data = $job->getJobData(); |
31
|
|
|
$this->assertContains("2 jobs cleaned up.", $data->messages[0]); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function testByNumber() { |
|
|
|
|
35
|
|
|
$job = new CleanupJob(); |
36
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_method', 'number'); |
37
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_value', 3); |
38
|
|
|
Config::inst()->remove('CleanupJob', 'cleanup_statuses'); |
39
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_statuses', |
40
|
|
|
array('Broken', 'Complete')); |
41
|
|
|
$job->process(); |
42
|
|
|
$data = $job->getJobData(); |
43
|
|
|
$this->assertContains("2 jobs cleaned up.", $data->messages[0]); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
public function testByStatus() { |
|
|
|
|
47
|
|
|
$job = new CleanupJob(); |
48
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_method', 'number'); |
49
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_value', 3); |
50
|
|
|
Config::inst()->remove('CleanupJob', 'cleanup_statuses'); |
51
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_statuses', |
52
|
|
|
array('Broken', 'Complete', 'New')); |
53
|
|
|
$job->process(); |
54
|
|
|
$data = $job->getJobData(); |
55
|
|
|
$this->assertContains("3 jobs cleaned up.", $data->messages[0]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testNoCleanup() { |
|
|
|
|
59
|
|
|
$job = new CleanupJob(); |
60
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_method', 'number'); |
61
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_value', 6); |
62
|
|
|
Config::inst()->remove('CleanupJob', 'cleanup_statuses'); |
63
|
|
|
Config::inst()->update('CleanupJob', 'cleanup_statuses', |
64
|
|
|
array('Broken', 'Complete', 'New')); |
65
|
|
|
$job->process(); |
66
|
|
|
$data = $job->getJobData(); |
67
|
|
|
$this->assertContains("No jobs to clean up.", $data->messages[0]); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.