Merge pull request #2682 from creative-commoners/pulls/4/fix-unit-tests

MNT Use logInAs() for unit tests
This commit is contained in:
Maxime Rainville 2021-08-19 13:49:13 +12:00 committed by GitHub
commit 5634173d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -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());

View File

@ -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()