mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Code comments
This commit is contained in:
parent
13c17f5dd4
commit
104f646973
1 changed files with 6 additions and 0 deletions
|
@ -252,6 +252,7 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase {
|
||||||
|
|
||||||
function testInternalExceptionLogic() {
|
function testInternalExceptionLogic() {
|
||||||
$tests = [
|
$tests = [
|
||||||
|
// methods of User class to test, with parameters besides affected user
|
||||||
'exists' => [],
|
'exists' => [],
|
||||||
'remove' => [],
|
'remove' => [],
|
||||||
'add' => [''],
|
'add' => [''],
|
||||||
|
@ -262,8 +263,10 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase {
|
||||||
'rightsSet' => [User\Driver::RIGHTS_GLOBAL_ADMIN],
|
'rightsSet' => [User\Driver::RIGHTS_GLOBAL_ADMIN],
|
||||||
'list' => [],
|
'list' => [],
|
||||||
];
|
];
|
||||||
|
// try first with a global admin (there should be no exception)
|
||||||
$this->data->user->auth("gadm@example.com", "");
|
$this->data->user->auth("gadm@example.com", "");
|
||||||
$this->assertCount(0, $this->checkExceptions("user@example.org", $tests));
|
$this->assertCount(0, $this->checkExceptions("user@example.org", $tests));
|
||||||
|
// next try with a regular user acting on another user (everything should fail)
|
||||||
$this->data->user->auth("user@example.com", "");
|
$this->data->user->auth("user@example.com", "");
|
||||||
$this->assertCount(sizeof($tests), $this->checkExceptions("user@example.org", $tests));
|
$this->assertCount(sizeof($tests), $this->checkExceptions("user@example.org", $tests));
|
||||||
}
|
}
|
||||||
|
@ -275,9 +278,12 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase {
|
||||||
$this->testInternalExceptionLogic();
|
$this->testInternalExceptionLogic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// meat of testInternalExceptionLogic and testExternalExceptionLogic
|
||||||
|
// calls each requested function with supplied arguments, catches authorization exceptions, and returns an array of caught failed calls
|
||||||
protected function checkExceptions(string $user, $tests): array {
|
protected function checkExceptions(string $user, $tests): array {
|
||||||
$err = [];
|
$err = [];
|
||||||
foreach($tests as $func => $args) {
|
foreach($tests as $func => $args) {
|
||||||
|
// list method does not take an affected user, so do not unshift for that one
|
||||||
if($func != "list") array_unshift($args, $user);
|
if($func != "list") array_unshift($args, $user);
|
||||||
try {
|
try {
|
||||||
call_user_func_array(array($this->data->user, $func), $args);
|
call_user_func_array(array($this->data->user, $func), $args);
|
||||||
|
|
Loading…
Reference in a new issue