1 | <?php |
||||
2 | |||||
3 | namespace SilverStripe\CMS\Tests\Model; |
||||
4 | |||||
5 | use SilverStripe\CMS\Model\SiteTree; |
||||
6 | use SilverStripe\Control\HTTPResponse_Exception; |
||||
7 | use SilverStripe\Dev\FunctionalTest; |
||||
8 | use SilverStripe\Security\Group; |
||||
9 | use SilverStripe\Security\Member; |
||||
10 | use SilverStripe\Security\Security; |
||||
11 | use SilverStripe\SiteConfig\SiteConfig; |
||||
12 | use SilverStripe\Subsites\Extensions\SiteTreeSubsites; |
||||
0 ignored issues
–
show
|
|||||
13 | use SilverStripe\Versioned\Versioned; |
||||
14 | |||||
15 | /** |
||||
16 | * @todo Test canAddChildren() |
||||
17 | * @todo Test canCreate() |
||||
18 | */ |
||||
19 | class SiteTreePermissionsTest extends FunctionalTest |
||||
20 | { |
||||
21 | protected static $fixture_file = "SiteTreePermissionsTest.yml"; |
||||
22 | |||||
23 | protected static $illegal_extensions = [ |
||||
24 | SiteTree::class => [SiteTreeSubsites::class], |
||||
25 | ]; |
||||
26 | |||||
27 | protected function setUp() : void |
||||
28 | { |
||||
29 | parent::setUp(); |
||||
30 | |||||
31 | // we're testing HTTP status codes before being redirected to login forms |
||||
32 | $this->autoFollowRedirection = false; |
||||
33 | |||||
34 | // Ensure all pages are published |
||||
35 | /** @var SiteTree $page */ |
||||
36 | foreach (SiteTree::get() as $page) { |
||||
37 | if ($page->URLSegment !== 'draft-only') { |
||||
38 | $page->publishSingle(); |
||||
39 | } |
||||
40 | } |
||||
41 | } |
||||
42 | |||||
43 | |||||
44 | public function testAccessingStageWithBlankStage() |
||||
45 | { |
||||
46 | $this->autoFollowRedirection = false; |
||||
47 | |||||
48 | /** @var SiteTree $draftOnlyPage */ |
||||
49 | $draftOnlyPage = $this->objFromFixture(SiteTree::class, 'draftOnlyPage'); |
||||
50 | $this->logOut(); |
||||
51 | |||||
52 | $response = $this->get($draftOnlyPage->URLSegment . '?stage=Live'); |
||||
53 | $this->assertEquals($response->getStatusCode(), '404'); |
||||
54 | |||||
55 | $response = $this->get($draftOnlyPage->URLSegment); |
||||
56 | $this->assertEquals($response->getStatusCode(), '404'); |
||||
57 | |||||
58 | // should be prompted for a login |
||||
59 | try { |
||||
60 | $response = $this->get($draftOnlyPage->URLSegment . '?stage=Stage'); |
||||
61 | } catch (HTTPResponse_Exception $responseException) { |
||||
62 | $response = $responseException->getResponse(); |
||||
63 | } |
||||
64 | $this->assertEquals($response->getStatusCode(), '302'); |
||||
65 | $this->assertStringContainsString( |
||||
66 | Security::config()->get('login_url'), |
||||
67 | $response->getHeader('Location') |
||||
68 | ); |
||||
69 | |||||
70 | $this->logInWithPermission('ADMIN'); |
||||
71 | |||||
72 | $response = $this->get($draftOnlyPage->URLSegment . '?stage=Live'); |
||||
73 | $this->assertEquals('404', $response->getStatusCode()); |
||||
74 | |||||
75 | $response = $this->get($draftOnlyPage->URLSegment . '?stage=Stage'); |
||||
76 | $this->assertEquals('200', $response->getStatusCode()); |
||||
77 | |||||
78 | $draftOnlyPage->publishSingle(); |
||||
79 | $response = $this->get($draftOnlyPage->URLSegment); |
||||
80 | $this->assertEquals('200', $response->getStatusCode()); |
||||
81 | } |
||||
82 | |||||
83 | public function testPermissionCheckingWorksOnDeletedPages() |
||||
84 | { |
||||
85 | // Set up fixture - a published page deleted from draft |
||||
86 | $this->logInWithPermission("ADMIN"); |
||||
87 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); |
||||
88 | $pageID = $page->ID; |
||||
89 | $this->assertTrue($page->publishRecursive()); |
||||
90 | $page->delete(); |
||||
91 | |||||
92 | // Re-fetch the page from the live site |
||||
93 | $page = Versioned::get_one_by_stage(SiteTree::class, 'Live', "\"SiteTree\".\"ID\" = $pageID"); |
||||
94 | |||||
95 | // subadmin has edit rights on that page |
||||
96 | $member = $this->objFromFixture(Member::class, 'subadmin'); |
||||
97 | Security::setCurrentUser($member); |
||||
98 | |||||
99 | // Test can_edit_multiple |
||||
100 | $this->assertEquals( |
||||
101 | [ $pageID => true ], |
||||
102 | SiteTree::getPermissionChecker()->canEditMultiple([$pageID], $member) |
||||
103 | ); |
||||
104 | |||||
105 | // Test canEdit |
||||
106 | Security::setCurrentUser($member); |
||||
107 | $this->assertTrue($page->canEdit()); |
||||
108 | } |
||||
109 | |||||
110 | public function testPermissionCheckingWorksOnUnpublishedPages() |
||||
111 | { |
||||
112 | // Set up fixture - an unpublished page |
||||
113 | $this->logInWithPermission("ADMIN"); |
||||
114 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); |
||||
115 | $pageID = $page->ID; |
||||
116 | $page->doUnpublish(); |
||||
117 | |||||
118 | // subadmin has edit rights on that page |
||||
119 | $member = $this->objFromFixture(Member::class, 'subadmin'); |
||||
120 | Security::setCurrentUser($member); |
||||
121 | |||||
122 | // Test can_edit_multiple |
||||
123 | $this->assertEquals( |
||||
124 | [ $pageID => true ], |
||||
125 | SiteTree::getPermissionChecker()->canEditMultiple([$pageID], $member) |
||||
126 | ); |
||||
127 | |||||
128 | // Test canEdit |
||||
129 | Security::setCurrentUser($member); |
||||
130 | $this->assertTrue($page->canEdit()); |
||||
131 | } |
||||
132 | |||||
133 | public function testCanEditOnPageDeletedFromStageAndLiveReturnsFalse() |
||||
134 | { |
||||
135 | // Find a page that exists and delete it from both stage and published |
||||
136 | $this->logInWithPermission("ADMIN"); |
||||
137 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); |
||||
138 | $pageID = $page->ID; |
||||
139 | $page->doUnpublish(); |
||||
140 | $page->delete(); |
||||
141 | |||||
142 | // We'll need to resurrect the page from the version cache to test this case |
||||
143 | $page = Versioned::get_latest_version(SiteTree::class, $pageID); |
||||
144 | |||||
145 | // subadmin had edit rights on that page, but now it's gone |
||||
146 | $member = $this->objFromFixture(Member::class, 'subadmin'); |
||||
147 | Security::setCurrentUser($member); |
||||
148 | |||||
149 | $this->assertFalse($page->canEdit()); |
||||
150 | } |
||||
151 | |||||
152 | public function testCanViewStage() |
||||
153 | { |
||||
154 | // Get page & make sure it exists on Live |
||||
155 | /** @var SiteTree $page */ |
||||
156 | $page = $this->objFromFixture(SiteTree::class, 'standardpage'); |
||||
157 | $page->publishSingle(); |
||||
158 | |||||
159 | // Then make sure there's a new version on Stage |
||||
160 | $page->Title = 1; |
||||
161 | $page->write(); |
||||
162 | |||||
163 | $editor = $this->objFromFixture(Member::class, 'editor'); |
||||
164 | $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
165 | |||||
166 | $this->assertTrue($page->canViewStage('Live', $websiteuser)); |
||||
167 | $this->assertFalse($page->canViewStage('Stage', $websiteuser)); |
||||
168 | |||||
169 | $this->assertTrue($page->canViewStage('Live', $editor)); |
||||
170 | $this->assertTrue($page->canViewStage('Stage', $editor)); |
||||
171 | } |
||||
172 | |||||
173 | public function testAccessTabOnlyDisplaysWithGrantAccessPermissions() |
||||
174 | { |
||||
175 | $page = $this->objFromFixture(SiteTree::class, 'standardpage'); |
||||
176 | |||||
177 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
178 | Security::setCurrentUser($subadminuser); |
||||
179 | $fields = $page->getSettingsFields(); |
||||
180 | $this->assertFalse( |
||||
181 | $fields->dataFieldByName('CanViewType')->isReadonly(), |
||||
182 | 'Users with SITETREE_GRANT_ACCESS permission can change "view" permissions in cms fields' |
||||
183 | ); |
||||
184 | $this->assertFalse( |
||||
185 | $fields->dataFieldByName('CanEditType')->isReadonly(), |
||||
186 | 'Users with SITETREE_GRANT_ACCESS permission can change "edit" permissions in cms fields' |
||||
187 | ); |
||||
188 | |||||
189 | $editoruser = $this->objFromFixture(Member::class, 'editor'); |
||||
190 | Security::setCurrentUser($editoruser); |
||||
191 | $fields = $page->getSettingsFields(); |
||||
192 | $this->assertTrue( |
||||
193 | $fields->dataFieldByName('CanViewType')->isReadonly(), |
||||
194 | 'Users without SITETREE_GRANT_ACCESS permission cannot change "view" permissions in cms fields' |
||||
195 | ); |
||||
196 | $this->assertTrue( |
||||
197 | $fields->dataFieldByName('CanEditType')->isReadonly(), |
||||
198 | 'Users without SITETREE_GRANT_ACCESS permission cannot change "edit" permissions in cms fields' |
||||
199 | ); |
||||
200 | |||||
201 | $this->session()->set('loggedInAs', null); |
||||
202 | } |
||||
203 | |||||
204 | public function testRestrictedViewLoggedInUsers() |
||||
205 | { |
||||
206 | $page = $this->objFromFixture(SiteTree::class, 'restrictedViewLoggedInUsers'); |
||||
207 | |||||
208 | // unauthenticated users |
||||
209 | $this->assertFalse( |
||||
210 | $page->canView(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canView() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
211 | 'Unauthenticated members cant view a page marked as "Viewable for any logged in users"' |
||||
212 | ); |
||||
213 | Security::setCurrentUser(null); |
||||
214 | $response = $this->get($page->RelativeLink()); |
||||
215 | $this->assertEquals( |
||||
216 | $response->getStatusCode(), |
||||
217 | 302, |
||||
218 | 'Unauthenticated members cant view a page marked as "Viewable for any logged in users"' |
||||
219 | ); |
||||
220 | |||||
221 | // website users |
||||
222 | $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
223 | $this->assertTrue( |
||||
224 | $page->canView($websiteuser), |
||||
225 | 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont ' . |
||||
226 | 'have access to the CMS' |
||||
227 | ); |
||||
228 | Security::setCurrentUser($websiteuser); |
||||
229 | $response = $this->get($page->RelativeLink()); |
||||
230 | $this->assertEquals( |
||||
231 | $response->getStatusCode(), |
||||
232 | 200, |
||||
233 | 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont ' . |
||||
234 | 'have access to the CMS' |
||||
235 | ); |
||||
236 | Security::setCurrentUser(null); |
||||
237 | } |
||||
238 | |||||
239 | public function testRestrictedViewOnlyTheseUsers() |
||||
240 | { |
||||
241 | $page = $this->objFromFixture(SiteTree::class, 'restrictedViewOnlyWebsiteUsers'); |
||||
242 | |||||
243 | // unauthenticcated users |
||||
244 | $this->assertFalse( |
||||
245 | $page->canView(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canView() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
246 | 'Unauthenticated members cant view a page marked as "Viewable by these groups"' |
||||
247 | ); |
||||
248 | Security::setCurrentUser(null); |
||||
249 | $response = $this->get($page->RelativeLink()); |
||||
250 | $this->assertEquals( |
||||
251 | $response->getStatusCode(), |
||||
252 | 302, |
||||
253 | 'Unauthenticated members cant view a page marked as "Viewable by these groups"' |
||||
254 | ); |
||||
255 | |||||
256 | // subadmin users |
||||
257 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
258 | $this->assertFalse( |
||||
259 | $page->canView($subadminuser), |
||||
260 | 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed ' . |
||||
261 | 'groups' |
||||
262 | ); |
||||
263 | Security::setCurrentUser($subadminuser); |
||||
264 | $response = $this->get($page->RelativeLink()); |
||||
265 | $this->assertEquals( |
||||
266 | $response->getStatusCode(), |
||||
267 | 403, |
||||
268 | 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed ' . |
||||
269 | 'groups' |
||||
270 | ); |
||||
271 | Security::setCurrentUser(null); |
||||
272 | |||||
273 | // website users |
||||
274 | $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
275 | $this->assertTrue( |
||||
276 | $page->canView($websiteuser), |
||||
277 | 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups' |
||||
278 | ); |
||||
279 | Security::setCurrentUser($websiteuser); |
||||
280 | $response = $this->get($page->RelativeLink()); |
||||
281 | $this->assertEquals( |
||||
282 | $response->getStatusCode(), |
||||
283 | 200, |
||||
284 | 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups' |
||||
285 | ); |
||||
286 | Security::setCurrentUser(null); |
||||
287 | } |
||||
288 | |||||
289 | public function testRestrictedEditLoggedInUsers() |
||||
290 | { |
||||
291 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers'); |
||||
292 | |||||
293 | // unauthenticcated users |
||||
294 | $this->assertFalse( |
||||
295 | $page->canEdit(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canEdit() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
296 | 'Unauthenticated members cant edit a page marked as "Editable by logged in users"' |
||||
297 | ); |
||||
298 | |||||
299 | // website users |
||||
300 | $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
301 | Security::setCurrentUser($websiteuser); |
||||
302 | $this->assertFalse( |
||||
303 | $page->canEdit($websiteuser), |
||||
304 | 'Authenticated members cant edit a page marked as "Editable by logged in users" if they dont have cms ' . |
||||
305 | 'permissions' |
||||
306 | ); |
||||
307 | |||||
308 | // subadmin users |
||||
309 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
310 | $this->assertTrue( |
||||
311 | $page->canEdit($subadminuser), |
||||
312 | 'Authenticated members can edit a page marked as "Editable by logged in users" if they have cms ' . |
||||
313 | 'permissions and belong to any of these groups' |
||||
314 | ); |
||||
315 | } |
||||
316 | |||||
317 | public function testRestrictedEditOnlySubadminGroup() |
||||
318 | { |
||||
319 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditOnlySubadminGroup'); |
||||
320 | |||||
321 | // unauthenticated users |
||||
322 | $this->assertFalse( |
||||
323 | $page->canEdit(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canEdit() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
324 | 'Unauthenticated members cant edit a page marked as "Editable by these groups"' |
||||
325 | ); |
||||
326 | |||||
327 | // subadmin users |
||||
328 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
329 | $this->assertTrue( |
||||
330 | $page->canEdit($subadminuser), |
||||
331 | 'Authenticated members can view a page marked as "Editable by these groups" if theyre in the listed groups' |
||||
332 | ); |
||||
333 | |||||
334 | // website users |
||||
335 | $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
336 | $this->assertFalse( |
||||
337 | $page->canEdit($websiteuser), |
||||
338 | 'Authenticated members cant edit a page marked as "Editable by these groups" if theyre not in the listed ' . |
||||
339 | 'groups' |
||||
340 | ); |
||||
341 | } |
||||
342 | |||||
343 | public function testRestrictedViewInheritance() |
||||
344 | { |
||||
345 | $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedViewOnlySubadminGroup'); |
||||
0 ignored issues
–
show
|
|||||
346 | $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedViewOnlySubadminGroup'); |
||||
347 | |||||
348 | // unauthenticated users |
||||
349 | $this->assertFalse( |
||||
350 | $childPage->canView(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canView() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
351 | 'Unauthenticated members cant view a page marked as "Viewable by these groups" by inherited permission' |
||||
352 | ); |
||||
353 | Security::setCurrentUser(null); |
||||
354 | $response = $this->get($childPage->RelativeLink()); |
||||
355 | $this->assertEquals( |
||||
356 | $response->getStatusCode(), |
||||
357 | 302, |
||||
358 | 'Unauthenticated members cant view a page marked as "Viewable by these groups" by inherited permission' |
||||
359 | ); |
||||
360 | |||||
361 | // subadmin users |
||||
362 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
363 | $this->assertTrue( |
||||
364 | $childPage->canView($subadminuser), |
||||
365 | 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed ' . |
||||
366 | 'groups by inherited permission' |
||||
367 | ); |
||||
368 | Security::setCurrentUser($subadminuser); |
||||
369 | $response = $this->get($childPage->RelativeLink()); |
||||
370 | $this->assertEquals( |
||||
371 | $response->getStatusCode(), |
||||
372 | 200, |
||||
373 | 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed ' . |
||||
374 | 'groups by inherited permission' |
||||
375 | ); |
||||
376 | Security::setCurrentUser(null); |
||||
377 | } |
||||
378 | |||||
379 | public function testRestrictedEditInheritance() |
||||
380 | { |
||||
381 | $parentPage = $this->objFromFixture(SiteTree::class, 'parent_restrictedEditOnlySubadminGroup'); |
||||
0 ignored issues
–
show
|
|||||
382 | $childPage = $this->objFromFixture(SiteTree::class, 'child_restrictedEditOnlySubadminGroup'); |
||||
383 | |||||
384 | // unauthenticated users |
||||
385 | $this->assertFalse( |
||||
386 | $childPage->canEdit(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canEdit() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
387 | 'Unauthenticated members cant edit a page marked as "Editable by these groups" by inherited permission' |
||||
388 | ); |
||||
389 | |||||
390 | // subadmin users |
||||
391 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
392 | $this->assertTrue( |
||||
393 | $childPage->canEdit($subadminuser), |
||||
394 | 'Authenticated members can edit a page marked as "Editable by these groups" if theyre in the listed ' . |
||||
395 | 'groups by inherited permission' |
||||
396 | ); |
||||
397 | } |
||||
398 | |||||
399 | public function testDeleteRestrictedChild() |
||||
400 | { |
||||
401 | $parentPage = $this->objFromFixture(SiteTree::class, 'deleteTestParentPage'); |
||||
402 | $childPage = $this->objFromFixture(SiteTree::class, 'deleteTestChildPage'); |
||||
403 | |||||
404 | // unauthenticated users |
||||
405 | $this->assertFalse( |
||||
406 | $parentPage->canDelete(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canDelete() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
407 | 'Unauthenticated members cant delete a page if it doesnt have delete permissions on any of its descendants' |
||||
408 | ); |
||||
409 | $this->assertFalse( |
||||
410 | $childPage->canDelete(false), |
||||
411 | 'Unauthenticated members cant delete a child page marked as "Editable by these groups"' |
||||
412 | ); |
||||
413 | } |
||||
414 | |||||
415 | public function testRestrictedEditLoggedInUsersDeletedFromStage() |
||||
416 | { |
||||
417 | $page = $this->objFromFixture(SiteTree::class, 'restrictedEditLoggedInUsers'); |
||||
418 | $pageID = $page->ID; |
||||
419 | |||||
420 | $this->logInWithPermission("ADMIN"); |
||||
421 | |||||
422 | $page->publishRecursive(); |
||||
423 | $page->deleteFromStage('Stage'); |
||||
424 | |||||
425 | // Get the live version of the page |
||||
426 | $page = Versioned::get_one_by_stage(SiteTree::class, Versioned::LIVE, "\"SiteTree\".\"ID\" = $pageID"); |
||||
427 | $this->assertTrue(is_object($page), 'Versioned::get_one_by_stage() is returning an object'); |
||||
428 | |||||
429 | // subadmin users |
||||
430 | $subadminuser = $this->objFromFixture(Member::class, 'subadmin'); |
||||
431 | $this->assertTrue( |
||||
432 | $page->canEdit($subadminuser), |
||||
433 | 'Authenticated members can edit a page that was deleted from stage and marked as "Editable by logged ' . |
||||
434 | 'in users" if they have cms permissions and belong to any of these groups' |
||||
435 | ); |
||||
436 | } |
||||
437 | |||||
438 | public function testInheritCanViewFromSiteConfig() |
||||
439 | { |
||||
440 | $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent'); |
||||
441 | $siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); |
||||
442 | $editor = $this->objFromFixture(Member::class, 'editor'); |
||||
443 | $editorGroup = $this->objFromFixture(Group::class, 'editorgroup'); |
||||
444 | |||||
445 | $siteconfig->CanViewType = 'Anyone'; |
||||
446 | $siteconfig->write(); |
||||
447 | $this->assertTrue( |
||||
448 | $page->canView(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canView() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
449 | 'Anyone can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . |
||||
450 | 'LoggedInUsers' |
||||
451 | ); |
||||
452 | |||||
453 | $siteconfig->CanViewType = 'LoggedInUsers'; |
||||
454 | $siteconfig->write(); |
||||
455 | $this->assertFalse( |
||||
456 | $page->canView(false), |
||||
457 | 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . |
||||
458 | 'LoggedInUsers' |
||||
459 | ); |
||||
460 | |||||
461 | $siteconfig->CanViewType = 'LoggedInUsers'; |
||||
462 | $siteconfig->write(); |
||||
463 | $this->assertTrue( |
||||
464 | $page->canView($editor), |
||||
465 | 'Users can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . |
||||
466 | 'LoggedInUsers' |
||||
467 | ); |
||||
468 | |||||
469 | $siteconfig->CanViewType = 'OnlyTheseUsers'; |
||||
470 | $siteconfig->ViewerGroups()->add($editorGroup); |
||||
471 | $siteconfig->write(); |
||||
472 | $this->assertTrue( |
||||
473 | $page->canView($editor), |
||||
474 | 'Editors can view a page when set to inherit from the SiteConfig, and SiteConfig has canView set to ' . |
||||
475 | 'OnlyTheseUsers' |
||||
476 | ); |
||||
477 | $this->assertFalse( |
||||
478 | $page->canView(false), |
||||
479 | 'Anonymous can\'t view a page when set to inherit from the SiteConfig, and SiteConfig has canView set ' . |
||||
480 | 'to OnlyTheseUsers' |
||||
481 | ); |
||||
482 | } |
||||
483 | |||||
484 | public function testInheritCanEditFromSiteConfig() |
||||
485 | { |
||||
486 | $page = $this->objFromFixture(SiteTree::class, 'inheritWithNoParent'); |
||||
487 | $siteconfig = $this->objFromFixture(SiteConfig::class, 'default'); |
||||
488 | $editor = $this->objFromFixture(Member::class, 'editor'); |
||||
489 | $user = $this->objFromFixture(Member::class, 'websiteuser'); |
||||
490 | $editorGroup = $this->objFromFixture(Group::class, 'editorgroup'); |
||||
491 | |||||
492 | $siteconfig->CanEditType = 'LoggedInUsers'; |
||||
493 | $siteconfig->write(); |
||||
494 | |||||
495 | $this->assertFalse( |
||||
496 | $page->canEdit(false), |
||||
0 ignored issues
–
show
false of type false is incompatible with the type SilverStripe\Security\Member expected by parameter $member of SilverStripe\ORM\DataObject::canEdit() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
497 | 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . |
||||
498 | 'to LoggedInUsers' |
||||
499 | ); |
||||
500 | Security::setCurrentUser($editor); |
||||
501 | $this->assertTrue( |
||||
502 | $page->canEdit(), |
||||
503 | 'Users can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to ' . |
||||
504 | 'LoggedInUsers' |
||||
505 | ); |
||||
506 | |||||
507 | $siteconfig->CanEditType = 'OnlyTheseUsers'; |
||||
508 | $siteconfig->EditorGroups()->add($editorGroup); |
||||
509 | $siteconfig->write(); |
||||
510 | $this->assertTrue( |
||||
511 | $page->canEdit($editor), |
||||
512 | 'Editors can edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set to ' . |
||||
513 | 'OnlyTheseUsers' |
||||
514 | ); |
||||
515 | Security::setCurrentUser(null); |
||||
516 | $this->assertFalse( |
||||
517 | $page->canEdit(false), |
||||
518 | 'Anonymous can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . |
||||
519 | 'to OnlyTheseUsers' |
||||
520 | ); |
||||
521 | Security::setCurrentUser($user); |
||||
522 | $this->assertFalse( |
||||
523 | $page->canEdit($user), |
||||
524 | 'Website user can\'t edit a page when set to inherit from the SiteConfig, and SiteConfig has canEdit set ' . |
||||
525 | 'to OnlyTheseUsers' |
||||
526 | ); |
||||
527 | } |
||||
528 | } |
||||
529 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths