/** * @covers \BjyAuthorize\Service\Authorize::load */ public function testLoadWritesAclToCacheIfCacheIsEnabledButAclIsNotStoredInCache() { $cache = $this->getMockBuilder('Zend\\Cache\\Storage\\Adapter\\Filesystem')->disableOriginalConstructor()->getMock(); $cache->expects($this->once())->method('getItem'); $cache->expects($this->once())->method('setItem'); $serviceLocator = new ServiceManager(); $serviceLocator->setService('BjyAuthorize\\Cache', $cache); $serviceLocator->setService('BjyAuthorize\\Provider\\Identity\\ProviderInterface', $this->getMock('BjyAuthorize\\Provider\\Identity\\ProviderInterface')); $serviceLocator->setService('BjyAuthorize\\RoleProviders', $this->getMock('BjyAuthorize\\Service\\RoleProvidersServiceFactory')); $serviceLocator->setService('BjyAuthorize\\ResourceProviders', $this->getMock('BjyAuthorize\\Service\\ResourceProvidersServiceFactory')); $serviceLocator->setService('BjyAuthorize\\RuleProviders', $this->getMock('BjyAuthorize\\Service\\RuleProvidersServiceFactory')); $serviceLocator->setService('BjyAuthorize\\Guards', $this->getMock('BjyAuthorize\\Service\\GuardsServiceFactory')); $authorize = new Authorize(array('cache_key' => 'acl'), $serviceLocator); $authorize->load(); }
/** * @group bjyoungblood/BjyAuthorize#258 */ public function testCanAddTraversableRoleToLoadRole() { $serviceLocator = $this->serviceLocator; $serviceLocator->setAllowOverride(true); $roleProviderMock = $this->getMockBuilder('BjyAuthorize\\Provider\\Role\\Config')->disableOriginalConstructor()->getMock(); $roleProviderMock->expects($this->once())->method('getRoles')->will($this->returnValue(new \Zend\Stdlib\ArrayObject(array(new \BjyAuthorize\Acl\Role('test'))))); $serviceLocator->setService('BjyAuthorize\\Provider\\Role\\Config', $roleProviderMock); $roleMock = $this->getMockBuilder('BjyAuthorize\\Service\\RoleProvidersServiceFactory')->disableOriginalConstructor()->getMock(); $roleMock->expects($this->any())->method('createService')->will($this->returnValue(array($roleProviderMock))); $serviceLocator->setFactory('BjyAuthorize\\RoleProviders', $roleMock); $authorize = new Authorize(array('cache_key' => 'acl'), $this->serviceLocator); $authorize->load(); $acl = $authorize->getAcl(); $this->assertTrue($acl->hasRole('test')); }