mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10066 from creative-commoners/pull/4/more-login-as
MNT Update unit tests to use logInAs()
This commit is contained in:
commit
cbed904b5b
@ -94,8 +94,6 @@ class ControllerTest extends FunctionalTest
|
|||||||
|
|
||||||
public function testAllowedActions()
|
public function testAllowedActions()
|
||||||
{
|
{
|
||||||
$adminUser = $this->objFromFixture(Member::class, 'admin');
|
|
||||||
|
|
||||||
$response = $this->get("UnsecuredController/");
|
$response = $this->get("UnsecuredController/");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
200,
|
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'
|
'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");
|
$response = $this->get("AccessSecuredController/templateaction");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
200,
|
200,
|
||||||
$response->getStatusCode(),
|
$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'
|
'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");
|
$response = $this->get("AccessSecuredController/adminonly");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -210,14 +208,14 @@ class ControllerTest extends FunctionalTest
|
|||||||
"Access denied to protected method even if its listed in allowed_actions"
|
"Access denied to protected method even if its listed in allowed_actions"
|
||||||
);
|
);
|
||||||
|
|
||||||
Member::actAs($adminUser, function () {
|
$this->logInAs('admin');
|
||||||
$response = $this->get("AccessSecuredController/adminonly");
|
$response = $this->get("AccessSecuredController/adminonly");
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
200,
|
200,
|
||||||
$response->getStatusCode(),
|
$response->getStatusCode(),
|
||||||
"Permission codes are respected when set in \$allowed_actions"
|
"Permission codes are respected when set in \$allowed_actions"
|
||||||
);
|
);
|
||||||
});
|
$this->logOut();
|
||||||
|
|
||||||
$response = $this->get('AccessBaseController/extensionmethod1');
|
$response = $this->get('AccessBaseController/extensionmethod1');
|
||||||
$this->assertEquals(
|
$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"
|
"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/');
|
$response = $this->get('IndexSecuredController/');
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
200,
|
200,
|
||||||
$response->getStatusCode(),
|
$response->getStatusCode(),
|
||||||
"Access granted when index action is limited through allowed_actions, " . "and does satisfy checks"
|
"Access granted when index action is limited through allowed_actions, " . "and does satisfy checks"
|
||||||
);
|
);
|
||||||
});
|
$this->logOut();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -326,7 +326,7 @@ class SecurityTest extends FunctionalTest
|
|||||||
$member = DataObject::get_one(Member::class);
|
$member = DataObject::get_one(Member::class);
|
||||||
|
|
||||||
/* Log in with any user that we can find */
|
/* 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 */
|
/* Visit the Security/logout page with a test referer, but without a security token */
|
||||||
$this->get(
|
$this->get(
|
||||||
|
Loading…
Reference in New Issue
Block a user