/** * {@inheritDoc} * @return ControllerGuard */ public function createService(ServiceLocatorInterface $serviceLocator) { $parentLocator = $serviceLocator->getServiceLocator(); /* @var \ZfjRbac\Options\ModuleOptions $moduleOptions */ $moduleOptions = $parentLocator->get('ZfjRbac\\Options\\ModuleOptions'); /* @var \ZfjRbac\Service\RoleService $roleService */ $roleService = $parentLocator->get('ZfjRbac\\Service\\RoleService'); $controllerGuard = new ControllerGuard($roleService, $this->options); $controllerGuard->setProtectionPolicy($moduleOptions->getProtectionPolicy()); return $controllerGuard; }
/** * @dataProvider controllerDataProvider */ public function testControllerGranted(array $rules, $controller, $action, array $rolesConfig, $identityRole, $isGranted, $protectionPolicy) { $event = new MvcEvent(); $routeMatch = new RouteMatch([]); $routeMatch->setParam('controller', $controller); $routeMatch->setParam('action', $action); $event->setRouteMatch($routeMatch); $identity = $this->getMock('ZfjRbac\\Identity\\IdentityInterface'); $identity->expects($this->any())->method('getRoles')->will($this->returnValue($identityRole)); $identityProvider = $this->getMock('ZfjRbac\\Identity\\IdentityProviderInterface'); $identityProvider->expects($this->any())->method('getIdentity')->will($this->returnValue($identity)); $roleProvider = new InMemoryRoleProvider($rolesConfig); $roleService = new RoleService($identityProvider, $roleProvider, new RecursiveRoleIteratorStrategy()); $controllerGuard = new ControllerGuard($roleService, $rules); $controllerGuard->setProtectionPolicy($protectionPolicy); $this->assertEquals($isGranted, $controllerGuard->isGranted($event)); }