/** * {@inheritDoc} * @return GuardPluginManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $config = $serviceLocator->get('Config')['zfc_rbac']['guard_manager']; $pluginManager = new GuardPluginManager(new Config($config)); $pluginManager->setServiceLocator($serviceLocator); return $pluginManager; }
public function testReturnArrayIfNoConfig() { $moduleOptions = new ModuleOptions(['guards' => []]); $pluginManager = new GuardPluginManager(); $serviceManager = new ServiceManager(); $serviceManager->setService('ZfcRbac\\Options\\ModuleOptions', $moduleOptions); $pluginManager->setServiceLocator($serviceManager); $factory = new GuardsFactory(); $guards = $factory->createService($serviceManager); $this->assertInternalType('array', $guards); $this->assertEmpty($guards); }
public function testFactory() { $options = new ModuleOptions(['identity_provider' => 'ZfcRbac\\Identity\\AuthenticationProvider', 'guards' => ['ZfcRbac\\Guard\\ControllerGuard' => ['controller' => 'MyController', 'actions' => 'edit', 'roles' => 'member']], 'protection_policy' => GuardInterface::POLICY_ALLOW]); $serviceManager = new ServiceManager(); $serviceManager->setService('ZfcRbac\\Options\\ModuleOptions', $options); $serviceManager->setService('ZfcRbac\\Service\\RoleService', $this->getMock('ZfcRbac\\Service\\RoleService', [], [], '', false)); $pluginManager = new GuardPluginManager(); $pluginManager->setServiceLocator($serviceManager); $factory = new ControllerGuardFactory(); $controllerGuard = $factory->createService($pluginManager); $this->assertInstanceOf('ZfcRbac\\Guard\\ControllerGuard', $controllerGuard); $this->assertEquals(GuardInterface::POLICY_ALLOW, $controllerGuard->getProtectionPolicy()); }
public function testFactory() { $creationOptions = ['route' => 'role']; $options = new ModuleOptions(['identity_provider' => 'ZfcRbac\\Identity\\AuthenticationProvider', 'guards' => ['ZfcRbac\\Guard\\RoutePermissionsGuard' => $creationOptions], 'protection_policy' => GuardInterface::POLICY_ALLOW]); $serviceManager = new ServiceManager(); $serviceManager->setService('ZfcRbac\\Options\\ModuleOptions', $options); $serviceManager->setService('ZfcRbac\\Service\\AuthorizationService', $this->getMock('ZfcRbac\\Service\\AuthorizationService', [], [], '', false)); $pluginManager = new GuardPluginManager(); $pluginManager->setServiceLocator($serviceManager); $factory = new RoutePermissionsGuardFactory(); $routeGuard = $factory->createService($pluginManager); $this->assertInstanceOf('ZfcRbac\\Guard\\RoutePermissionsGuard', $routeGuard); $this->assertEquals(GuardInterface::POLICY_ALLOW, $routeGuard->getProtectionPolicy()); }
public function testThrowExceptionForInvalidPlugin() { $this->setExpectedException('ZfcRbac\\Exception\\RuntimeException'); $pluginManager = new GuardPluginManager(new ServiceManager()); $pluginManager->get('stdClass'); }