1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SilverStripe\Dev\SapphireTest; |
4
|
|
|
use SilverStripe\Core\Config\Config; |
5
|
|
|
use SilverStripe\ORM\FieldType\DBDatetime; |
6
|
|
|
use Symbiote\QueuedJobs\Jobs\CleanupJob; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @author Andrew Aitken-Fincham <[email protected]> |
10
|
|
|
*/ |
11
|
|
|
class CleanupJobTest extends SapphireTest |
|
|
|
|
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* {@inheritDoc} |
15
|
|
|
* @var string |
16
|
|
|
*/ |
17
|
|
|
protected static $fixture_file = 'CleanupJobFixture.yml'; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* {@inheritDoc} |
21
|
|
|
*/ |
22
|
|
|
public function setUp() |
23
|
|
|
{ |
24
|
|
|
// Have to set a fake time here to work with |
25
|
|
|
// the LastEdited dates in the fixture |
26
|
|
|
DBDatetime::set_mock_now("2002-02-03 02:02:02"); |
27
|
|
|
parent::setUp(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* {@inheritDoc} |
32
|
|
|
*/ |
33
|
|
|
public function tearDown() |
34
|
|
|
{ |
35
|
|
|
parent::tearDown(); |
36
|
|
|
DBDatetime::clear_mock_now(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
View Code Duplication |
public function testByDays() |
|
|
|
|
40
|
|
|
{ |
41
|
|
|
$job = new CleanupJob(); |
42
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_method', 'age'); |
43
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_value', 30); |
44
|
|
|
Config::inst()->remove('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_statuses'); |
|
|
|
|
45
|
|
|
Config::modify()->set( |
46
|
|
|
'Symbiote\\QueuedJobs\\Jobs\\CleanupJob', |
47
|
|
|
'cleanup_statuses', |
48
|
|
|
array('Broken', 'Complete') |
49
|
|
|
); |
50
|
|
|
$job->process(); |
51
|
|
|
$data = $job->getJobData(); |
52
|
|
|
$this->assertContains("2 jobs cleaned up.", $data->messages[0]); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
View Code Duplication |
public function testByNumber() |
|
|
|
|
56
|
|
|
{ |
57
|
|
|
$job = new CleanupJob(); |
58
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_method', 'number'); |
59
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_value', 3); |
60
|
|
|
Config::inst()->remove('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_statuses'); |
|
|
|
|
61
|
|
|
Config::modify()->set( |
62
|
|
|
'Symbiote\\QueuedJobs\\Jobs\\CleanupJob', |
63
|
|
|
'cleanup_statuses', |
64
|
|
|
array('Broken', 'Complete') |
65
|
|
|
); |
66
|
|
|
$job->process(); |
67
|
|
|
$data = $job->getJobData(); |
68
|
|
|
$this->assertContains("2 jobs cleaned up.", $data->messages[0]); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
View Code Duplication |
public function testByStatus() |
|
|
|
|
72
|
|
|
{ |
73
|
|
|
$job = new CleanupJob(); |
74
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_method', 'number'); |
75
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_value', 3); |
76
|
|
|
Config::inst()->remove('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_statuses'); |
|
|
|
|
77
|
|
|
Config::modify()->set( |
78
|
|
|
'Symbiote\\QueuedJobs\\Jobs\\CleanupJob', |
79
|
|
|
'cleanup_statuses', |
80
|
|
|
array('Broken', 'Complete', 'New') |
81
|
|
|
); |
82
|
|
|
$job->process(); |
83
|
|
|
$data = $job->getJobData(); |
84
|
|
|
$this->assertContains("3 jobs cleaned up.", $data->messages[0]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
View Code Duplication |
public function testNoCleanup() |
|
|
|
|
88
|
|
|
{ |
89
|
|
|
$job = new CleanupJob(); |
90
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_method', 'number'); |
91
|
|
|
Config::modify()->set('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_value', 6); |
92
|
|
|
Config::inst()->remove('Symbiote\\QueuedJobs\\Jobs\\CleanupJob', 'cleanup_statuses'); |
|
|
|
|
93
|
|
|
Config::modify()->set( |
94
|
|
|
'Symbiote\\QueuedJobs\\Jobs\\CleanupJob', |
95
|
|
|
'cleanup_statuses', |
96
|
|
|
array('Broken', 'Complete', 'New') |
97
|
|
|
); |
98
|
|
|
$job->process(); |
99
|
|
|
$data = $job->getJobData(); |
100
|
|
|
$this->assertContains("No jobs to clean up.", $data->messages[0]); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
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.