Merge pull request #10066 from creative-commoners/pull/4/more-login-as

MNT Update unit tests to use logInAs()
This commit is contained in:
Maxime Rainville 2021-08-26 11:16:20 +12:00 committed by GitHub
commit cbed904b5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 27 deletions

View File

@ -94,8 +94,6 @@ class ControllerTest extends FunctionalTest
public function testAllowedActions()
{
$adminUser = $this->objFromFixture(Member::class, 'admin');
$response = $this->get("UnsecuredController/");
$this->assertEquals(
200,
@ -180,14 +178,14 @@ class ControllerTest extends FunctionalTest
'Access denied on action with $allowed_actions on defining controller, ' . 'if action is not a method but rather a template discovered by naming convention'
);
Member::actAs($adminUser, function () {
$this->logInAs('admin');
$response = $this->get("AccessSecuredController/templateaction");
$this->assertEquals(
200,
$response->getStatusCode(),
'Access granted for logged in admin on action with $allowed_actions on defining controller, ' . 'if action is not a method but rather a template discovered by naming convention'
);
});
$this->logOut();
$response = $this->get("AccessSecuredController/adminonly");
$this->assertEquals(
@ -210,14 +208,14 @@ class ControllerTest extends FunctionalTest
"Access denied to protected method even if its listed in allowed_actions"
);
Member::actAs($adminUser, function () {
$this->logInAs('admin');
$response = $this->get("AccessSecuredController/adminonly");
$this->assertEquals(
200,
$response->getStatusCode(),
"Permission codes are respected when set in \$allowed_actions"
);
});
$this->logOut();
$response = $this->get('AccessBaseController/extensionmethod1');
$this->assertEquals(
@ -254,14 +252,14 @@ class ControllerTest extends FunctionalTest
"Access denied when index action is limited through allowed_actions, " . "and doesn't satisfy checks"
);
Member::actAs($adminUser, function () {
$this->logInAs('admin');
$response = $this->get('IndexSecuredController/');
$this->assertEquals(
200,
$response->getStatusCode(),
"Access granted when index action is limited through allowed_actions, " . "and does satisfy checks"
);
});
$this->logOut();
}
/**

View File

@ -326,7 +326,7 @@ class SecurityTest extends FunctionalTest
$member = DataObject::get_one(Member::class);
/* Log in with any user that we can find */
Security::setCurrentUser($member);
$this->logInAs($member);
/* Visit the Security/logout page with a test referer, but without a security token */
$this->get(