1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class GridFieldRefreshButtonTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected static $fixture_file = 'GridFieldRefreshButtonTest.yml'; |
6
|
|
|
|
7
|
|
|
public function testHasRunningJob() |
8
|
|
|
{ |
9
|
|
|
$button = new GridFieldRefreshButton('test'); |
10
|
|
|
$this->assertTrue($button->hasActiveJob()); |
|
|
|
|
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
public function testDoesNotHaveCancelledCompletedOrBrokenJob() |
14
|
|
|
{ |
15
|
|
|
$this->completeRunningJob(); |
16
|
|
|
|
17
|
|
|
$button = new GridFieldRefreshButton('test'); |
18
|
|
|
$this->assertFalse($button->hasActiveJob()); |
|
|
|
|
19
|
|
|
} |
20
|
|
|
|
21
|
|
View Code Duplication |
public function testHandleRefreshDoesNotCreateJobWhenJobIsRunning() |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$count = QueuedJobDescriptor::get()->count(); |
24
|
|
|
|
25
|
|
|
$button = new GridFieldRefreshButton('test'); |
26
|
|
|
$button->handleRefresh(); |
27
|
|
|
|
28
|
|
|
$this->assertSame($count, QueuedJobDescriptor::get()->count()); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public function testHandleRefreshCreatesJobWhenNoJobIsRunning() |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$this->completeRunningJob(); |
34
|
|
|
|
35
|
|
|
$count = QueuedJobDescriptor::get()->count(); |
36
|
|
|
|
37
|
|
|
$button = new GridFieldRefreshButton('test'); |
38
|
|
|
$button->handleRefresh(); |
39
|
|
|
|
40
|
|
|
$this->assertSame($count + 1, QueuedJobDescriptor::get()->count()); |
|
|
|
|
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testHandleCheckReturnsValidJson() |
44
|
|
|
{ |
45
|
|
|
$button = new GridFieldRefreshButton('test'); |
46
|
|
|
$this->assertSame('true', $button->handleCheck()); |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testButtonIsDisabledWhenJobIsRunning() |
50
|
|
|
{ |
51
|
|
|
$button = new GridFieldRefreshButton('test'); |
52
|
|
|
|
53
|
|
|
$gridFieldMock = $this->getGridFieldMock(); |
54
|
|
|
|
55
|
|
|
$output = $button->getHTMLFragments($gridFieldMock); |
56
|
|
|
|
57
|
|
|
$this->assertContains('disabled', $output['test']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testButtonIsEnabledWhenNoJobIsRunning() |
61
|
|
|
{ |
62
|
|
|
$this->completeRunningJob(); |
63
|
|
|
|
64
|
|
|
$button = new GridFieldRefreshButton('test'); |
65
|
|
|
|
66
|
|
|
$gridFieldMock = $this->getGridFieldMock(); |
67
|
|
|
|
68
|
|
|
$output = $button->getHTMLFragments($gridFieldMock); |
69
|
|
|
|
70
|
|
|
$this->assertNotContains('disabled', $output['test']); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
protected function completeRunningJob() |
74
|
|
|
{ |
75
|
|
|
$runningJob = $this->objFromFixture('QueuedJobDescriptor', 'runningjob'); |
76
|
|
|
$runningJob->JobStatus = 'Complete'; |
77
|
|
|
$runningJob->write(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
protected function getGridFieldMock() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$gridFieldMock = $this |
|
|
|
|
83
|
|
|
->getMockBuilder(GridField::class) |
84
|
|
|
->setConstructorArgs(['TestGridField']) |
85
|
|
|
->setMethods(['Link']) |
86
|
|
|
->getMock(); |
87
|
|
|
$gridFieldMock |
88
|
|
|
->expects($this->any()) |
|
|
|
|
89
|
|
|
->method('Link') |
90
|
|
|
->will($this->returnValue('http://example.com')); |
|
|
|
|
91
|
|
|
|
92
|
|
|
return $gridFieldMock; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
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.