Completed
Pull Request — master (#53)
by Helpful
02:20
created

testObjectsToUpdateOnUnpublish()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 23
Ratio 100 %
Metric Value
dl 23
loc 23
rs 9.0856
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
class PublishableSiteTreeTest 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 $requiredExtensions = array(
6
		'PublishableSiteTreeTest_Publishable' => array('PublishableSiteTree')
7
	);
8
9
	public function setUp() {
10
		parent::setUp();
11
		Config::inst()->nest();
12
		Config::inst()->update('StaticPagesQueue', 'realtime', true);
13
	}
14
15
	public function tearDown() {
16
		Config::inst()->unnest();
17
		parent::tearDown();
18
	}
19
20 View Code Duplication
	function testObjectsToUpdateOnPublish() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
21
22
		$parent = Object::create('PublishableSiteTreeTest_Publishable');
23
		$parent->Title = 'parent';
24
25
		$stub = $this->getMock(
26
			'PublishableSiteTreeTest_Publishable',
27
			array('getParentID', 'Parent')
28
		);
29
		$stub->Title = 'stub';
30
31
		$stub->expects($this->once())
32
			->method('getParentID')
33
			->will($this->returnValue('2'));
34
35
		$stub->expects($this->once())
36
			->method('Parent')
37
			->will($this->returnValue($parent));
38
39
		$objects = $stub->objectsToUpdate(array('action' => 'publish'));
40
		$this->assertEquals($objects->column('Title'), array('stub', 'parent'), 'Updates itself and parent on publish');
41
42
	}
43
44 View Code Duplication
	function testObjectsToUpdateOnUnpublish() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
45
46
		$parent = Object::create('PublishableSiteTreeTest_Publishable');
47
		$parent->Title = 'parent';
48
49
		$stub = $this->getMock(
50
			'PublishableSiteTreeTest_Publishable',
51
			array('getParentID', 'Parent')
52
		);
53
		$stub->Title = 'stub';
54
55
		$stub->expects($this->once())
56
			->method('getParentID')
57
			->will($this->returnValue('2'));
58
59
		$stub->expects($this->once())
60
			->method('Parent')
61
			->will($this->returnValue($parent));
62
63
		$objects = $stub->objectsToUpdate(array('action' => 'unpublish'));
64
		$this->assertEquals($objects->column('Title'), array('parent'), 'Updates parent on unpublish');
65
66
	}
67
68 View Code Duplication
	function testObjectsToDeleteOnPublish() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
69
70
		$stub = Object::create('PublishableSiteTreeTest_Publishable');
71
		$objects = $stub->objectsToDelete(array('action' => 'publish'));
72
		$this->assertEquals($objects->column('Title'), array(), 'Deletes nothing on publish');
73
74
	}
75
76 View Code Duplication
	function testObjectsToDeleteOnUnpublish() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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 = Object::create('PublishableSiteTreeTest_Publishable');
79
		$stub->Title = 'stub';
80
		$objects = $stub->objectsToDelete(array('action' => 'unpublish'));
81
		$this->assertEquals($objects->column('Title'), array('stub'), 'Deletes itself on unpublish');
82
83
	}
84
85 View Code Duplication
	function testObjectsToUpdateOnPublishIfVirtualExists() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
86
87
		$redir = Object::create('PublishableSiteTreeTest_Publishable');
88
		$redir->Title = 'virtual';
89
90
		$stub = $this->getMock(
91
			'PublishableSiteTreeTest_Publishable',
92
			array('getMyVirtualPages')
93
		);
94
		$stub->Title = 'stub';
95
96
		$stub->expects($this->once())
97
			->method('getMyVirtualPages')
98
			->will($this->returnValue(
99
				new ArrayList(array($redir))
100
			));
101
102
		$objects = $stub->objectsToUpdate(array('action' => 'publish'));
103
		$this->assertTrue(in_array('virtual', $objects->column('Title'), 'Updates related virtual page'));
104
105
	}
106
107 View Code Duplication
	function testObjectsToDeleteOnUnpublishIfVirtualExists() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
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...
108
109
		$redir = Object::create('PublishableSiteTreeTest_Publishable');
110
		$redir->Title = 'virtual';
111
112
		$stub = $this->getMock(
113
			'PublishableSiteTreeTest_Publishable',
114
			array('getMyVirtualPages')
115
		);
116
		$stub->Title = 'stub';
117
118
		$stub->expects($this->once())
119
			->method('getMyVirtualPages')
120
			->will($this->returnValue(
121
				new ArrayList(array($redir))
122
			));
123
124
		$objects = $stub->objectsToDelete(array('action' => 'unpublish'));
125
		$this->assertTrue(in_array('virtual', $objects->column('Title'), 'Deletes related virtual page'));
126
127
	}
128
129
}
130
131
class PublishableSiteTreeTest_Publishable extends SiteTree implements TestOnly {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
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...
132
133
}
134