Completed
Pull Request — master (#65)
by
unknown
08:59
created

testHandleCheckReturnsValidJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
class GridFieldRefreshButtonTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected static $fixture_file = 'GridFieldRefreshButtonTest.yml';
6
7
    public function testHasRunningJob()
8
    {
9
        $button = new GridFieldRefreshButton('test');
10
        $this->assertTrue($button->hasActiveJob());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
11
    }
12
13
    public function testDoesNotHaveCancelledCompletedOrBrokenJob()
14
    {
15
        $this->completeRunningJob();
16
17
        $button = new GridFieldRefreshButton('test');
18
        $this->assertFalse($button->hasActiveJob());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
19
    }
20
21 View Code Duplication
    public function testHandleRefreshDoesNotCreateJobWhenJobIsRunning()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $count = QueuedJobDescriptor::get()->count();
24
25
        $button = new GridFieldRefreshButton('test');
26
        $button->handleRefresh();
27
28
        $this->assertSame($count, QueuedJobDescriptor::get()->count());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
    }
30
31 View Code Duplication
    public function testHandleRefreshCreatesJobWhenNoJobIsRunning()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
41
    }
42
43
    public function testHandleCheckReturnsValidJson()
44
    {
45
        $button = new GridFieldRefreshButton('test');
46
        $this->assertSame('true', $button->handleCheck());
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
81
    {
82
        $gridFieldMock = $this
0 ignored issues
show
Bug introduced by
The method getMockBuilder() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
83
            ->getMockBuilder(GridField::class)
84
            ->setConstructorArgs(['TestGridField'])
85
            ->setMethods(['Link'])
86
            ->getMock();
87
        $gridFieldMock
88
            ->expects($this->any())
0 ignored issues
show
Bug introduced by
The method any() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
            ->method('Link')
90
            ->will($this->returnValue('http://example.com'));
0 ignored issues
show
Bug introduced by
The method returnValue() does not seem to exist on object<GridFieldRefreshButtonTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
92
        return $gridFieldMock;
93
    }
94
}
95