diff --git a/tests/php/Controllers/CMSMainTest.php b/tests/php/Controllers/CMSMainTest.php index e66cbc7b..4a0e71a3 100644 --- a/tests/php/Controllers/CMSMainTest.php +++ b/tests/php/Controllers/CMSMainTest.php @@ -287,7 +287,7 @@ class CMSMainTest extends FunctionalTest $this->assertEquals(403, $response->getStatusCode(), 'Add TopLevel page must fail for normal user'); // with correct permissions - Security::setCurrentUser($rootEditUser); + $this->logInAs($rootEditUser); $response = $this->get('admin/pages/add'); $response = $this->post( @@ -307,8 +307,7 @@ class CMSMainTest extends FunctionalTest $location = $response->getHeader('X-ControllerURL'); $this->assertNotEmpty($location, 'Must be a redirect on success'); $this->assertContains('/show/', $location, 'Must redirect to /show/ the new page'); - // TODO Logout - Security::setCurrentUser(null); + $this->logOut(); $this->autoFollowRedirection = $origFollow; } @@ -318,8 +317,7 @@ class CMSMainTest extends FunctionalTest $origFollow = $this->autoFollowRedirection; $this->autoFollowRedirection = false; - $adminUser = $this->objFromFixture(Member::class, 'admin'); - Security::setCurrentUser($adminUser); + $this->logInAs('admin'); // Create toplevel page $this->get('admin/pages/add'); @@ -393,8 +391,7 @@ class CMSMainTest extends FunctionalTest { $page3 = $this->objFromFixture(Page::class, 'page3'); $page31 = $this->objFromFixture(Page::class, 'page31'); - $adminuser = $this->objFromFixture(Member::class, 'admin'); - Security::setCurrentUser($adminuser); + $this->logInAs('admin'); $response = $this->get('admin/pages/edit/show/' . $page31->ID); $parser = new CSSContentParser($response->getBody()); diff --git a/tests/php/Model/SiteTreePermissionsTest.php b/tests/php/Model/SiteTreePermissionsTest.php index 6db4b78d..ee436571 100644 --- a/tests/php/Model/SiteTreePermissionsTest.php +++ b/tests/php/Model/SiteTreePermissionsTest.php @@ -211,7 +211,7 @@ class SiteTreePermissionsTest extends FunctionalTest $page->canView(false), 'Unauthenticated members cant view a page marked as "Viewable for any logged in users"' ); - Security::setCurrentUser(null); + $this->logOut(); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), @@ -225,14 +225,14 @@ class SiteTreePermissionsTest extends FunctionalTest $page->canView($websiteuser), 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont have access to the CMS' ); - Security::setCurrentUser($websiteuser); + $this->logInAs($websiteuser); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 200, 'Authenticated members can view a page marked as "Viewable for any logged in users" even if they dont have access to the CMS' ); - Security::setCurrentUser(null); + $this->logOut(); } public function testRestrictedViewOnlyTheseUsers() @@ -244,7 +244,7 @@ class SiteTreePermissionsTest extends FunctionalTest $page->canView(false), 'Unauthenticated members cant view a page marked as "Viewable by these groups"' ); - Security::setCurrentUser(null); + $this->logOut(); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), @@ -258,14 +258,14 @@ class SiteTreePermissionsTest extends FunctionalTest $page->canView($subadminuser), 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed groups' ); - Security::setCurrentUser($subadminuser); + $this->LogInAs($subadminuser); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 403, 'Authenticated members cant view a page marked as "Viewable by these groups" if theyre not in the listed groups' ); - Security::setCurrentUser(null); + $this->logOut(); // website users $websiteuser = $this->objFromFixture(Member::class, 'websiteuser'); @@ -273,14 +273,14 @@ class SiteTreePermissionsTest extends FunctionalTest $page->canView($websiteuser), 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups' ); - Security::setCurrentUser($websiteuser); + $this->logInAs($websiteuser); $response = $this->get($page->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 200, 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups' ); - Security::setCurrentUser(null); + $this->logOut(); } public function testRestrictedEditLoggedInUsers() @@ -344,7 +344,7 @@ class SiteTreePermissionsTest extends FunctionalTest $childPage->canView(false), 'Unauthenticated members cant view a page marked as "Viewable by these groups" by inherited permission' ); - Security::setCurrentUser(null); + $this->logOut(); $response = $this->get($childPage->RelativeLink()); $this->assertEquals( $response->getStatusCode(), @@ -358,14 +358,14 @@ class SiteTreePermissionsTest extends FunctionalTest $childPage->canView($subadminuser), 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission' ); - Security::setCurrentUser($subadminuser); + $this->logInAs($subadminuser); $response = $this->get($childPage->RelativeLink()); $this->assertEquals( $response->getStatusCode(), 200, 'Authenticated members can view a page marked as "Viewable by these groups" if theyre in the listed groups by inherited permission' ); - Security::setCurrentUser(null); + $this->logOut(); } public function testRestrictedEditInheritance()