/** * Execute a test instance * @param $test array */ private function executeHandlerValidatorRolesTest($test, $testNumber) { $someUserId = $test[0]; $roles = array(); foreach ($test[1] as $roleType) { $roles[] = $this->getTestRoleId($roleType); } $userHasRoleInContext = $test[2]; // Mock a handler. $userRoles = array(); if ($someUserId == null) { // Testing logged out user. No user roles in context then. $userRoles = null; } // Testing contexts where user don't have a role. if (!$userHasRoleInContext) { $userRoles = null; } // Testing multiple roles. if (is_array($userHasRoleInContext)) { foreach ($userHasRoleInContext as $key => $hasRole) { if ($hasRole) { $userRoles[] = $roles[$key]; } } } // Other tests. if (!is_null($userRoles) && empty($userRoles)) { $userRoles = $roles; } $mockHandler = $this->getMockHandler($userRoles); // Run the test $validator = new HandlerValidatorRoles($mockHandler, true, null, array(), $roles, $test[3]); self::assertEquals($test[4], $validator->isValid(), "Test number {$testNumber} failed."); }
/** * Execute a test instance * @param $test array */ private function executeHandlerValidatorRolesTest($test, $testNumber) { $contextIds = $test[0]; $someUserId = $test[1]; $roles = array(); foreach ($test[2] as $roleType) { $roles[] = $this->getTestRoleId($roleType); } $userHasRoleInContext = $test[3]; // Mock a fully qualified context $application = PKPApplication::getApplication(); $this->mockContext($contextIds, $someUserId); // Mock the role DAO if (count($roles) == 1) { // Only test expected arguments when testing a single role $roleExistsExpectedArgs = array_merge($test[5], array($someUserId, $roles[0])); } else { $roleExistsExpectedArgs = null; } $roleDao = $this->getMockRoleDao($roleExistsExpectedArgs, $userHasRoleInContext); // Run the test $validator = new HandlerValidatorRoles($handler = null, true, null, array(), $roles, $test[4]); self::assertEquals($test[6], $validator->isValid(), "Test number {$testNumber} failed."); }