Completed
Pull Request — master (#70)
by Daniel
04:46
created

testObjectsToDeleteOnUnpublishIfVirtualExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 22
Code Lines 14

Duplication

Lines 20
Ratio 90.91 %

Importance

Changes 0
Metric Value
dl 20
loc 22
rs 9.2
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
namespace SilverStripe\StaticPublishQueue\Test;
4
5
use SilverStripe\Core\Config\Config;
6
use SilverStripe\Dev\SapphireTest;
7
use SilverStripe\ORM\ArrayList;
8
use SilverStripe\StaticPublishQueue\Extension\Publishable\PublishableSiteTree;
9
use SilverStripe\StaticPublishQueue\Model\StaticPagesQueue;
10
use SilverStripe\StaticPublishQueue\Test\PublishableSiteTreeTest\Model\PublishablePage;
11
12
class PublishableSiteTreeTest extends SapphireTest
13
{
14
    protected static $required_extensions = array(
15
        PublishablePage::class => array(PublishableSiteTree::class)
16
    );
17
18
    protected function setUp()
19
    {
20
        parent::setUp();
21
        Config::modify()->set(StaticPagesQueue::class, 'realtime', true);
22
    }
23
24 View Code Duplication
    public function testObjectsToUpdateOnPublish()
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...
25
    {
26
        $parent = PublishablePage::create();
27
        $parent->Title = 'parent';
28
29
        $stub = $this->getMockBuilder(PublishablePage::class)
30
            ->setMethods(
31
                array(
32
                    'getParentID',
33
                    'Parent',
34
                )
35
            )->getMock();
36
37
        $stub->Title = 'stub';
38
39
        $stub->expects($this->once())
40
            ->method('getParentID')
41
            ->will($this->returnValue('2'));
42
43
        $stub->expects($this->once())
44
            ->method('Parent')
45
            ->will($this->returnValue($parent));
46
47
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
48
        $this->assertEquals(array('stub', 'parent'), $objects->column('Title'));
49
    }
50
51 View Code Duplication
    public function testObjectsToUpdateOnUnpublish()
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...
52
    {
53
        $parent = PublishablePage::create();
54
        $parent->Title = 'parent';
55
56
        $stub = $this->getMockBuilder(PublishablePage::class)
57
            ->setMethods(
58
                array(
59
                    'getParentID',
60
                    'Parent',
61
                )
62
            )->getMock();
63
64
        $stub->Title = 'stub';
65
66
        $stub->expects($this->once())
67
            ->method('getParentID')
68
            ->will($this->returnValue('2'));
69
70
        $stub->expects($this->once())
71
            ->method('Parent')
72
            ->will($this->returnValue($parent));
73
74
        $objects = $stub->objectsToUpdate(array('action' => 'unpublish'));
75
        $this->assertEquals(array('parent'), $objects->column('Title'));
76
    }
77
78
    public function testObjectsToDeleteOnPublish()
79
    {
80
        $stub = PublishablePage::create();
81
        $objects = $stub->objectsToDelete(array('action' => 'publish'));
0 ignored issues
show
Bug introduced by
The method objectsToDelete() does not exist on SilverStripe\StaticPubli...t\Model\PublishablePage. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
82
        $this->assertEquals(array(), $objects->column('Title'));
83
    }
84
85
    public function testObjectsToDeleteOnUnpublish()
86
    {
87
        $stub = PublishablePage::create();
88
        $stub->Title = 'stub';
89
        $objects = $stub->objectsToDelete(array('action' => 'unpublish'));
0 ignored issues
show
Bug introduced by
The method objectsToDelete() does not exist on SilverStripe\StaticPubli...t\Model\PublishablePage. Did you maybe mean delete()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
90
        $this->assertEquals(array('stub'), $objects->column('Title'));
91
    }
92
93 View Code Duplication
    public function testObjectsToUpdateOnPublishIfVirtualExists()
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...
94
    {
95
        $redir = PublishablePage::create();
96
        $redir->Title = 'virtual';
97
98
        $stub = $this->getMockBuilder(PublishablePage::class)
99
            ->setMethods(array('getMyVirtualPages'))
100
            ->getMock();
101
102
        $stub->Title = 'stub';
103
104
        $stub->expects($this->once())
105
            ->method('getMyVirtualPages')
106
            ->will(
107
                $this->returnValue(
108
                    new ArrayList(array($redir))
109
                )
110
            );
111
112
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
113
        $this->assertContains('virtual', $objects->column('Title'));
114
    }
115
116 View Code Duplication
    public function testObjectsToDeleteOnUnpublishIfVirtualExists()
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...
117
    {
118
        $redir = PublishablePage::create();
119
        $redir->Title = 'virtual';
120
121
        $stub = $this->getMockBuilder(PublishablePage::class)
122
            ->setMethods(array('getMyVirtualPages'))
123
            ->getMock();
124
125
        $stub->Title = 'stub';
126
127
        $stub->expects($this->once())
128
            ->method('getMyVirtualPages')
129
            ->will(
130
                $this->returnValue(
131
                    new ArrayList(array($redir))
132
                )
133
            );
134
135
        $objects = $stub->objectsToDelete(array('action' => 'unpublish'));
136
        $this->assertContains('virtual', $objects->column('Title'));
137
    }
138
}
139