From 104f6469733265e6e0c77ad72f163d35e8066e69 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Wed, 1 Mar 2017 08:38:44 -0500 Subject: [PATCH] Code comments --- tests/User/TestAuthorization.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/User/TestAuthorization.php b/tests/User/TestAuthorization.php index 1ca0c76c..157e8e49 100644 --- a/tests/User/TestAuthorization.php +++ b/tests/User/TestAuthorization.php @@ -252,6 +252,7 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase { function testInternalExceptionLogic() { $tests = [ + // methods of User class to test, with parameters besides affected user 'exists' => [], 'remove' => [], 'add' => [''], @@ -262,8 +263,10 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase { 'rightsSet' => [User\Driver::RIGHTS_GLOBAL_ADMIN], 'list' => [], ]; + // try first with a global admin (there should be no exception) $this->data->user->auth("gadm@example.com", ""); $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->assertCount(sizeof($tests), $this->checkExceptions("user@example.org", $tests)); } @@ -275,9 +278,12 @@ class TestAuthorization extends \PHPUnit\Framework\TestCase { $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 { $err = []; 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); try { call_user_func_array(array($this->data->user, $func), $args);