Completed
Pull Request — master (#70)
by Daniel
04:09
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
    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(array(
31
                'getParentID',
32
                'Parent',
33
            ))->getMock();
34
35
        $stub->Title = 'stub';
36
37
        $stub->expects($this->once())
38
            ->method('getParentID')
39
            ->will($this->returnValue('2'));
40
41
        $stub->expects($this->once())
42
            ->method('Parent')
43
            ->will($this->returnValue($parent));
44
45
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
46
        $this->assertEquals(array('stub', 'parent'), $objects->column('Title'));
47
48
    }
49
50 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...
51
    {
52
        $parent = PublishablePage::create();
53
        $parent->Title = 'parent';
54
55
        $stub = $this->getMockBuilder(PublishablePage::class)
56
            ->setMethods(array(
57
                'getParentID',
58
                'Parent',
59
            ))->getMock();
60
61
        $stub->Title = 'stub';
62
63
        $stub->expects($this->once())
64
            ->method('getParentID')
65
            ->will($this->returnValue('2'));
66
67
        $stub->expects($this->once())
68
            ->method('Parent')
69
            ->will($this->returnValue($parent));
70
71
        $objects = $stub->objectsToUpdate(array('action' => 'unpublish'));
72
        $this->assertEquals(array('parent'), $objects->column('Title'));
73
74
    }
75
76 View Code Duplication
    public function testObjectsToDeleteOnPublish()
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...
77
    {
78
        $stub = PublishablePage::create();
79
        $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...
80
        $this->assertEquals(array(), $objects->column('Title'));
81
82
    }
83
84 View Code Duplication
    public function testObjectsToDeleteOnUnpublish()
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...
85
    {
86
        $stub = PublishablePage::create();
87
        $stub->Title = 'stub';
88
        $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...
89
        $this->assertEquals(array('stub'), $objects->column('Title'));
90
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($this->returnValue(
107
                new ArrayList(array($redir))
108
            ));
109
110
        $objects = $stub->objectsToUpdate(array('action' => 'publish'));
111
        $this->assertContains('virtual', $objects->column('Title'));
112
    }
113
114 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...
115
    {
116
        $redir = PublishablePage::create();
117
        $redir->Title = 'virtual';
118
119
        $stub = $this->getMockBuilder(PublishablePage::class)
120
            ->setMethods(array('getMyVirtualPages'))
121
            ->getMock();
122
123
        $stub->Title = 'stub';
124
125
        $stub->expects($this->once())
126
            ->method('getMyVirtualPages')
127
            ->will($this->returnValue(
128
                new ArrayList(array($redir))
129
            ));
130
131
        $objects = $stub->objectsToDelete(array('action' => 'unpublish'));
132
        $this->assertContains('virtual', $objects->column('Title'));
133
    }
134
}
135