Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT Use logInAs() for unit tests #2682

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions tests/php/Controllers/CMSMainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public function testCreationOfTopLevelPage()
$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(
Expand All @@ -307,8 +307,7 @@ public function testCreationOfTopLevelPage()
$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;
}
Expand All @@ -318,8 +317,7 @@ public function testCreationOfRestrictedPage()
$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');
Expand Down Expand Up @@ -393,8 +391,7 @@ public function testBreadcrumbs()
{
$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());
Expand Down
22 changes: 11 additions & 11 deletions tests/php/Model/SiteTreePermissionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function testRestrictedViewLoggedInUsers()
$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(),
Expand All @@ -225,14 +225,14 @@ public function testRestrictedViewLoggedInUsers()
$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()
Expand All @@ -244,7 +244,7 @@ public function testRestrictedViewOnlyTheseUsers()
$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(),
Expand All @@ -258,29 +258,29 @@ public function testRestrictedViewOnlyTheseUsers()
$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');
$this->assertTrue(
$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()
Expand Down Expand Up @@ -344,7 +344,7 @@ public function testRestrictedViewInheritance()
$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(),
Expand All @@ -358,14 +358,14 @@ public function testRestrictedViewInheritance()
$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()
Expand Down