Completed
Pull Request — master (#70)
by Andrew
02:16
created

PublishableSiteTreeTest::setUp()   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
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 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...
19
    {
20
        $parent = PublishablePage::create();
21
        $parent->Title = 'parent';
22
23
        $stub = $this->getMockBuilder(PublishablePage::class)
24
            ->setMethods(
25
                array(
26
                    'getParentID',
27
                    'Parent',
28
                )
29
            )->getMock();
30
31
        $stub->Title = 'stub';
32
33
        $stub->expects($this->once())
34
            ->method('getParentID')
35
            ->will($this->returnValue('2'));
36
37
        $stub->expects($this->once())
38
            ->method('Parent')
39
            ->will($this->returnValue($parent));
40
41
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
42
        $this->assertEquals(array('stub', 'parent'), $objects->column('Title'));
43
    }
44
45 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...
46
    {
47
        $parent = PublishablePage::create();
48
        $parent->Title = 'parent';
49
50
        $stub = $this->getMockBuilder(PublishablePage::class)
51
            ->setMethods(
52
                array(
53
                    'getParentID',
54
                    'Parent',
55
                )
56
            )->getMock();
57
58
        $stub->Title = 'stub';
59
60
        $stub->expects($this->once())
61
            ->method('getParentID')
62
            ->will($this->returnValue('2'));
63
64
        $stub->expects($this->once())
65
            ->method('Parent')
66
            ->will($this->returnValue($parent));
67
68
        $objects = $stub->objectsToUpdate(array('action' => 'unpublish'));
69
        $this->assertEquals(array('parent'), $objects->column('Title'));
70
    }
71
72
    public function testObjectsToDeleteOnPublish()
73
    {
74
        $stub = PublishablePage::create();
75
        $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...
76
        $this->assertEquals(array(), $objects->column('Title'));
77
    }
78
79
    public function testObjectsToDeleteOnUnpublish()
80
    {
81
        $stub = PublishablePage::create();
82
        $stub->Title = 'stub';
83
        $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...
84
        $this->assertEquals(array('stub'), $objects->column('Title'));
85
    }
86
87 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...
88
    {
89
        $redir = PublishablePage::create();
90
        $redir->Title = 'virtual';
91
92
        $stub = $this->getMockBuilder(PublishablePage::class)
93
            ->setMethods(array('getMyVirtualPages'))
94
            ->getMock();
95
96
        $stub->Title = 'stub';
97
98
        $stub->expects($this->once())
99
            ->method('getMyVirtualPages')
100
            ->will(
101
                $this->returnValue(
102
                    new ArrayList(array($redir))
103
                )
104
            );
105
106
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
107
        $this->assertContains('virtual', $objects->column('Title'));
108
    }
109
110 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...
111
    {
112
        $redir = PublishablePage::create();
113
        $redir->Title = 'virtual';
114
115
        $stub = $this->getMockBuilder(PublishablePage::class)
116
            ->setMethods(array('getMyVirtualPages'))
117
            ->getMock();
118
119
        $stub->Title = 'stub';
120
121
        $stub->expects($this->once())
122
            ->method('getMyVirtualPages')
123
            ->will(
124
                $this->returnValue(
125
                    new ArrayList(array($redir))
126
                )
127
            );
128
129
        $objects = $stub->objectsToDelete(array('action' => 'unpublish'));
130
        $this->assertContains('virtual', $objects->column('Title'));
131
    }
132
}
133