1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class PublishableSiteTreeTest extends SapphireTest { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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() { |
|
|
|
|
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 { |
|
|
|
|
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.