18 import(
'lib.pkp.tests.PKPTestCase');
19 import(
'lib.pkp.classes.security.UserGroup');
20 import(
'lib.pkp.classes.core.PKPRequest');
22 define(
'ROLE_ID_TEST', 0x9999);
26 private $contextObjects;
29 private $authorizationContextManipulationPolicy;
42 private function getContextObjects() {
43 return $this->contextObjects;
50 private function setContextObjects($contextObjects) {
51 $this->contextObjects = $contextObjects;
62 if (is_null($this->authorizationContextManipulationPolicy)) {
65 $policy = $this->getMockBuilder(AuthorizationPolicy::class)
66 ->setMethods(array(
'effect'))
68 $policy->expects($this->any())
70 ->will($this->returnCallback(array($this,
'mockEffect')));
71 $this->authorizationContextManipulationPolicy = $policy;
73 return $this->authorizationContextManipulationPolicy;
86 $userGroup->setRoleId(ROLE_ID_TEST);
87 $policy->addAuthorizedContextObject(ASSOC_TYPE_USER_GROUP, $userGroup);
90 $userRoles = array(ROLE_ID_TEST, ROLE_ID_SITE_ADMIN);
91 $policy->addAuthorizedContextObject(ASSOC_TYPE_USER_ROLES, $userRoles);
92 return AUTHORIZATION_PERMIT;
103 protected function getMockRequest($requestedOp, $context =
null, $user =
null) {
107 $this->setContextObjects($context);
110 $router = $this->getMockBuilder(PKPRouter::class)
111 ->setMethods(array(
'getHandler',
'getRequestedOp',
'getContext'))
114 $router->expects($this->any())
115 ->method(
'getHandler')
119 $router->expects($this->any())
120 ->method(
'getRequestedOp')
121 ->will($this->returnValue($requestedOp));
124 $router->expects($this->any())
125 ->method(
'getContext')
126 ->will($this->returnCallback(array($this,
'mockGetContext')));
130 if ($user instanceof
User) {
134 $request->setRouter($router);
145 $functionArgs = func_get_args();
146 $contextLevel = $functionArgs[1];
148 $contextObjects = $this->getContextObjects();
149 if (!empty($contextObjects[$contextLevel - 1])) {
150 return $contextObjects[$contextLevel - 1];