1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Refector authorization exception tests

This commit is contained in:
J. King 2017-02-28 13:10:04 -05:00
parent 8841da9cbb
commit 447fec993f

View file

@ -251,21 +251,21 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase {
} }
function testInternalExceptionLogic() { function testInternalExceptionLogic() {
$test = [ $tests = [
'userExists', 'exists' => [],
'userRemove', 'remove' => [],
'userAdd', 'add' => [],
'userPasswordSet', 'passwordSet' => [''],
'userPropertiesGet', 'propertiesGet' => [],
'userPropertiesSet', 'propertiesSet' => [[]],
'userRightsGet', 'rightsGet' => [],
'userRightsSet', 'rightsSet' => [User\Driver::RIGHTS_GLOBAL_ADMIN],
'userList', 'list' => [],
]; ];
$this->data->user->auth("gadm@example.com", ""); $this->data->user->auth("gadm@example.com", "");
$this->assertCount(0, $this->checkExceptions("user@example.org")); $this->assertCount(0, $this->checkExceptions("user@example.org", $tests));
$this->data->user->auth("user@example.com", ""); $this->data->user->auth("user@example.com", "");
$this->assertCount(sizeof($test), $this->checkExceptions("user@example.org")); $this->assertCount(sizeof($tests), $this->checkExceptions("user@example.org", $tests));
} }
function testExternalExceptionLogic() { function testExternalExceptionLogic() {
@ -275,52 +275,15 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase {
$this->testInternalExceptionLogic(); $this->testInternalExceptionLogic();
} }
protected function checkExceptions(string $user): array { protected function checkExceptions(string $user, $tests): array {
$err = []; $err = [];
try { foreach($tests as $func => $args) {
$this->data->user->exists($user); array_unshift($args, $user);
} catch(User\ExceptionAuthz $e) { try {
$err[] = "userExists"; call_user_func_array(array($this->data->user, $func), $args);
} } catch(User\ExceptionAuthz $e) {
try { $err[] = $func;
$this->data->user->remove($user); }
} catch(User\ExceptionAuthz $e) {
$err[] = "userRemove";
}
try {
$this->data->user->add($user, "");
} catch(User\ExceptionAuthz $e) {
$err[] = "userAdd";
}
try {
$this->data->user->passwordSet($user, "");
} catch(User\ExceptionAuthz $e) {
$err[] = "userPasswordSet";
}
try {
$this->data->user->propertiesGet($user);
} catch(User\ExceptionAuthz $e) {
$err[] = "userPropertiesGet";
}
try {
$this->data->user->propertiesSet($user, []);
} catch(User\ExceptionAuthz $e) {
$err[] = "userPropertiesSet";
}
try {
$this->data->user->rightsGet($user);
} catch(User\ExceptionAuthz $e) {
$err[] = "userRightsGet";
}
try {
$this->data->user->rightsSet($user, User\Driver::RIGHTS_GLOBAL_ADMIN);
} catch(User\ExceptionAuthz $e) {
$err[] = "userRightsSet";
}
try {
$this->data->user->list();
} catch(User\ExceptionAuthz $e) {
$err[] = "userList";
} }
return $err; return $err;
} }