Use Member::actAs rather than setting and unsetting member

This commit is contained in:
Dan Hensby 2018-09-26 00:37:16 +01:00
parent 6b618b44c9
commit fe5b431200
No known key found for this signature in database
GPG Key ID: 3906B235643EF10B

View File

@ -179,15 +179,15 @@ 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'
);
Security::setCurrentUser($adminUser);
$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'
);
Member::actAs($adminUser, function () {
$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'
);
});
Security::setCurrentUser(null);
$response = $this->get("AccessSecuredController/adminonly");
$this->assertEquals(
403,
@ -209,15 +209,15 @@ class ControllerTest extends FunctionalTest
"Access denied to protected method even if its listed in allowed_actions"
);
Security::setCurrentUser($adminUser);
$response = $this->get("AccessSecuredController/adminonly");
$this->assertEquals(
200,
$response->getStatusCode(),
"Permission codes are respected when set in \$allowed_actions"
);
Member::actAs($adminUser, function () {
$response = $this->get("AccessSecuredController/adminonly");
$this->assertEquals(
200,
$response->getStatusCode(),
"Permission codes are respected when set in \$allowed_actions"
);
});
Security::setCurrentUser(null);
$response = $this->get('AccessBaseController/extensionmethod1');
$this->assertEquals(
200,
@ -253,14 +253,14 @@ class ControllerTest extends FunctionalTest
"Access denied when index action is limited through allowed_actions, " . "and doesn't satisfy checks"
);
Security::setCurrentUser($adminUser);
$response = $this->get('IndexSecuredController/');
$this->assertEquals(
200,
$response->getStatusCode(),
"Access granted when index action is limited through allowed_actions, " . "and does satisfy checks"
);
Security::setCurrentUser(null);
Member::actAs($adminUser, function () {
$response = $this->get('IndexSecuredController/');
$this->assertEquals(
200,
$response->getStatusCode(),
"Access granted when index action is limited through allowed_actions, " . "and does satisfy checks"
);
});
}
/**