These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @mixin PHPUnit_Framework_TestCase |
||
5 | */ |
||
6 | class SiteTreeContentReviewTest extends ContentReviewBaseTest |
||
7 | { |
||
8 | /** |
||
9 | * @var string |
||
10 | */ |
||
11 | public static $fixture_file = "contentreview/tests/ContentReviewTest.yml"; |
||
12 | |||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | protected $requiredExtensions = array( |
||
17 | "SiteTree" => array("SiteTreeContentReview"), |
||
18 | "Group" => array("ContentReviewOwner"), |
||
19 | "Member" => array("ContentReviewOwner"), |
||
20 | "CMSPageEditController" => array("ContentReviewCMSExtension"), |
||
21 | "SiteConfig" => array("ContentReviewDefaultSettings"), |
||
22 | ); |
||
23 | |||
24 | public function testOwnerNames() |
||
25 | { |
||
26 | /** @var Member $editor */ |
||
27 | $editor = $this->objFromFixture("Member", "editor"); |
||
28 | |||
29 | $this->logInAs($editor); |
||
30 | |||
31 | /** @var Page|SiteTreeContentReview $page */ |
||
32 | $page = new Page(); |
||
33 | $page->ReviewPeriodDays = 10; |
||
34 | $page->ContentReviewType = "Custom"; |
||
35 | |||
36 | $page->ContentReviewUsers()->push($editor); |
||
37 | $page->write(); |
||
38 | |||
39 | $this->assertTrue($page->canPublish()); |
||
40 | $this->assertTrue($page->doPublish()); |
||
41 | $this->assertEquals($page->OwnerNames, "Test Editor", "Test Editor should be the owner"); |
||
42 | |||
43 | /** @var Page|SiteTreeContentReview $page */ |
||
44 | $page = $this->objFromFixture("Page", "about"); |
||
45 | |||
46 | $page->OwnerUsers()->removeAll(); |
||
47 | $page->write(); |
||
48 | |||
49 | $this->assertTrue($page->canPublish()); |
||
50 | $this->assertTrue($page->doPublish()); |
||
51 | $this->assertEquals("", $page->OwnerNames); |
||
52 | } |
||
53 | |||
54 | public function testPermissionsExists() |
||
55 | { |
||
56 | $perms = singleton("SiteTreeContentReview")->providePermissions(); |
||
57 | |||
58 | $this->assertTrue(isset($perms["EDIT_CONTENT_REVIEW_FIELDS"])); |
||
59 | } |
||
60 | |||
61 | View Code Duplication | public function testUserWithPermissionCanEdit() |
|
0 ignored issues
–
show
|
|||
62 | { |
||
63 | /** @var Member $editor */ |
||
64 | $editor = $this->objFromFixture("Member", "editor"); |
||
65 | |||
66 | $this->logInAs($editor); |
||
67 | |||
68 | /** @var Page|SiteTreeContentReview $page */ |
||
69 | $page = new Page(); |
||
70 | |||
71 | $fields = $page->getSettingsFields(); |
||
72 | |||
73 | $this->assertNotNull($fields->dataFieldByName("NextReviewDate")); |
||
74 | } |
||
75 | |||
76 | View Code Duplication | public function testUserWithoutPermissionCannotEdit() |
|
0 ignored issues
–
show
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 | /** @var Member $author */ |
||
79 | $author = $this->objFromFixture("Member", "author"); |
||
80 | |||
81 | $this->logInAs($author); |
||
82 | |||
83 | /** @var Page|SiteTreeContentReview $page */ |
||
84 | $page = new Page(); |
||
85 | |||
86 | $fields = $page->getSettingsFields(); |
||
87 | |||
88 | $this->assertNull($fields->dataFieldByName("NextReviewDate")); |
||
89 | } |
||
90 | |||
91 | public function testAutomaticallyToNotSetReviewDate() |
||
92 | { |
||
93 | /** @var Member $editor */ |
||
94 | $editor = $this->objFromFixture("Member", "editor"); |
||
95 | |||
96 | $this->logInAs($editor); |
||
97 | |||
98 | /** @var Page|SiteTreeContentReview $page */ |
||
99 | $page = new Page(); |
||
100 | |||
101 | $page->ReviewPeriodDays = 10; |
||
102 | $page->write(); |
||
103 | |||
104 | $this->assertTrue($page->doPublish()); |
||
105 | $this->assertEquals(null, $page->NextReviewDate); |
||
106 | } |
||
107 | |||
108 | public function testAddReviewNote() |
||
109 | { |
||
110 | /** @var Member $author */ |
||
111 | $author = $this->objFromFixture("Member", "author"); |
||
112 | |||
113 | /** @var Page|SiteTreeContentReview $page */ |
||
114 | $page = $this->objFromFixture("Page", "home"); |
||
115 | |||
116 | $page->addReviewNote($author, "This is a message"); |
||
117 | |||
118 | /** @var Page|SiteTreeContentReview $page */ |
||
119 | $homepage = $this->objFromFixture("Page", "home"); |
||
120 | |||
121 | $this->assertEquals(1, $homepage->ReviewLogs()->count()); |
||
122 | $this->assertEquals("This is a message", $homepage->ReviewLogs()->first()->Note); |
||
123 | } |
||
124 | |||
125 | public function testGetContentReviewOwners() |
||
126 | { |
||
127 | /** @var Page|SiteTreeContentReview $page */ |
||
128 | $page = $this->objFromFixture("Page", "group-owned"); |
||
129 | |||
130 | $owners = $page->ContentReviewOwners(); |
||
131 | |||
132 | $this->assertEquals(1, $owners->count()); |
||
133 | $this->assertEquals("[email protected]", $owners->first()->Email); |
||
134 | } |
||
135 | |||
136 | View Code Duplication | public function testCanNotBeReviewBecauseNoReviewDate() |
|
0 ignored issues
–
show
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...
|
|||
137 | { |
||
138 | SS_Datetime::set_mock_now("2010-01-01 12:00:00"); |
||
139 | |||
140 | /** @var Member $author */ |
||
141 | $author = $this->objFromFixture("Member", "author"); |
||
142 | |||
143 | /** @var Page|SiteTreeContentReview $page */ |
||
144 | $page = $this->objFromFixture("Page", "no-review"); |
||
145 | |||
146 | $this->assertFalse($page->canBeReviewedBy($author)); |
||
147 | |||
148 | SS_Datetime::clear_mock_now(); |
||
149 | } |
||
150 | |||
151 | View Code Duplication | public function testCanNotBeReviewedBecauseInFuture() |
|
0 ignored issues
–
show
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...
|
|||
152 | { |
||
153 | SS_Datetime::set_mock_now("2010-01-01 12:00:00"); |
||
154 | |||
155 | /** @var Member $author */ |
||
156 | $author = $this->objFromFixture("Member", "author"); |
||
157 | |||
158 | /** @var Page|SiteTreeContentReview $page */ |
||
159 | $page = $this->objFromFixture("Page", "staff"); |
||
160 | |||
161 | $this->assertFalse($page->canBeReviewedBy($author)); |
||
162 | |||
163 | SS_Datetime::clear_mock_now(); |
||
164 | } |
||
165 | |||
166 | View Code Duplication | public function testCanNotBeReviewedByUser() |
|
0 ignored issues
–
show
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...
|
|||
167 | { |
||
168 | SS_Datetime::set_mock_now("2010-03-01 12:00:00"); |
||
169 | |||
170 | /** @var Member $author */ |
||
171 | $author = $this->objFromFixture("Member", "author"); |
||
172 | |||
173 | /** @var Page|SiteTreeContentReview $page */ |
||
174 | $page = $this->objFromFixture("Page", "home"); |
||
175 | |||
176 | $this->assertFalse($page->canBeReviewedBy($author)); |
||
177 | |||
178 | SS_Datetime::clear_mock_now(); |
||
179 | } |
||
180 | |||
181 | View Code Duplication | public function testCanBeReviewedByUser() |
|
0 ignored issues
–
show
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...
|
|||
182 | { |
||
183 | SS_Datetime::set_mock_now("2010-03-01 12:00:00"); |
||
184 | |||
185 | /** @var Member $author */ |
||
186 | $author = $this->objFromFixture("Member", "author"); |
||
187 | |||
188 | /** @var Page|SiteTreeContentReview $page */ |
||
189 | $page = $this->objFromFixture("Page", "staff"); |
||
190 | |||
191 | $this->assertTrue($page->canBeReviewedBy($author)); |
||
192 | |||
193 | SS_Datetime::clear_mock_now(); |
||
194 | } |
||
195 | |||
196 | View Code Duplication | public function testCanNotBeReviewedByGroup() |
|
0 ignored issues
–
show
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...
|
|||
197 | { |
||
198 | SS_Datetime::set_mock_now("2010-03-01 12:00:00"); |
||
199 | |||
200 | /** @var Member $author */ |
||
201 | $author = $this->objFromFixture("Member", "editor"); |
||
202 | |||
203 | /** @var Page|SiteTreeContentReview $page */ |
||
204 | $page = $this->objFromFixture("Page", "contact"); |
||
205 | |||
206 | $this->assertFalse($page->canBeReviewedBy($author)); |
||
207 | |||
208 | SS_Datetime::clear_mock_now(); |
||
209 | } |
||
210 | |||
211 | View Code Duplication | public function testCanBeReviewedByGroup() |
|
0 ignored issues
–
show
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...
|
|||
212 | { |
||
213 | SS_Datetime::set_mock_now("2010-03-01 12:00:00"); |
||
214 | |||
215 | /** @var Member $author */ |
||
216 | $author = $this->objFromFixture("Member", "author"); |
||
217 | |||
218 | /** @var Page|SiteTreeContentReview $page */ |
||
219 | $page = $this->objFromFixture("Page", "contact"); |
||
220 | |||
221 | $this->assertTrue($page->canBeReviewedBy($author)); |
||
222 | |||
223 | SS_Datetime::clear_mock_now(); |
||
224 | } |
||
225 | |||
226 | public function testCanBeReviewedFromInheritedSetting() |
||
227 | { |
||
228 | SS_Datetime::set_mock_now("2013-03-01 12:00:00"); |
||
229 | |||
230 | /** @var Member $author */ |
||
231 | $author = $this->objFromFixture("Member", "author"); |
||
232 | |||
233 | /** @var Page|SiteTreeContentReview $parentPage */ |
||
234 | $parentPage = $this->objFromFixture("Page", "contact"); |
||
235 | |||
236 | $parentPage->NextReviewDate = "2013-01-01"; |
||
237 | $parentPage->write(); |
||
238 | |||
239 | /** @var Page|SiteTreeContentReview $page */ |
||
240 | $page = $this->objFromFixture("Page", "contact-child"); |
||
241 | |||
242 | $this->assertTrue($page->canBeReviewedBy($author)); |
||
243 | |||
244 | SS_Datetime::clear_mock_now(); |
||
245 | } |
||
246 | |||
247 | public function testUnModifiedPagesDontChangeEditor() { |
||
248 | SS_Datetime::set_mock_now("2013-03-01 12:00:00"); |
||
249 | |||
250 | /** @var Member $author */ |
||
251 | $author = $this->objFromFixture("Member", "author"); |
||
252 | $this->logInAs($author); |
||
253 | |||
254 | // Page which is un-modified doesn't advance version of have an editor assigned |
||
255 | $contactPage = $this->objFromFixture("Page", "contact"); |
||
256 | $contactPageVersion = $contactPage->Version; |
||
257 | $contactPage->write(); |
||
258 | $this->assertEmpty($contactPage->LastEditedByName); |
||
259 | $this->assertEquals( |
||
260 | $contactPageVersion, |
||
261 | Versioned::get_versionnumber_by_stage('SiteTree', 'Stage', $contactPage->ID, false) |
||
262 | ); |
||
263 | |||
264 | // Page with modifications gets marked |
||
265 | $homePage = $this->objFromFixture("Page", "home"); |
||
266 | $homePageVersion = $homePage->Version; |
||
267 | $homePage->Content = '<p>Welcome!</p>'; |
||
268 | $homePage->write(); |
||
269 | $this->assertNotEmpty($homePage->LastEditedByName); |
||
270 | $this->assertEquals($author->getTitle(), $homePage->LastEditedByName); |
||
271 | $this->assertGreaterThan( |
||
272 | $homePageVersion, |
||
273 | Versioned::get_versionnumber_by_stage('SiteTree', 'Stage', $homePage->ID, false) |
||
274 | ); |
||
275 | |||
276 | SS_Datetime::clear_mock_now(); |
||
277 | } |
||
278 | |||
279 | View Code Duplication | public function testReviewActionVisibleForAuthor() |
|
0 ignored issues
–
show
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...
|
|||
280 | { |
||
281 | SS_Datetime::set_mock_now("2020-03-01 12:00:00"); |
||
282 | |||
283 | /** @var Page|SiteTreeContentReview $page */ |
||
284 | $page = $this->objFromFixture("Page", "contact"); |
||
285 | |||
286 | /** @var Member $author */ |
||
287 | $author = $this->objFromFixture("Member", "author"); |
||
288 | |||
289 | $this->logInAs($author); |
||
290 | |||
291 | $fields = $page->getCMSActions(); |
||
292 | |||
293 | $this->assertNotNull($fields->fieldByName("ActionMenus.ReviewContent")); |
||
294 | |||
295 | SS_Datetime::clear_mock_now(); |
||
296 | } |
||
297 | |||
298 | View Code Duplication | public function testReviewActionNotVisibleForEditor() |
|
0 ignored issues
–
show
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...
|
|||
299 | { |
||
300 | SS_Datetime::set_mock_now("2020-03-01 12:00:00"); |
||
301 | |||
302 | /** @var Page|SiteTreeContentReview $page */ |
||
303 | $page = $this->objFromFixture("Page", "contact"); |
||
304 | |||
305 | /** @var Member $author */ |
||
306 | $author = $this->objFromFixture("Member", "editor"); |
||
307 | |||
308 | $this->logInAs($author); |
||
309 | |||
310 | $fields = $page->getCMSActions(); |
||
311 | |||
312 | $this->assertNull($fields->fieldByName("ActionMenus.ReviewContent")); |
||
313 | |||
314 | SS_Datetime::clear_mock_now(); |
||
315 | } |
||
316 | } |
||
317 |
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.