public function testCreatePrivilegeRequest() { // Set up the ACL $this->acl->allow(); $em = Bootstrap::getServiceManager()->get('doctrine.entitymanager.orm_default'); /* @var $em \Doctrine\ORM\EntityManager */ $this->acl->checkPrivilegeRequest('index', 'resource01', $em); $requests = $em->getRepository('JaztecAcl\\Entity\\Monitor\\RequestedPrivilege')->findBy(array('privilege' => 'index', 'resource' => 'resource01')); /* @var $requests array */ $this->assertGreaterThan(0, count($requests), "The newly added privilege should exist in the database"); $this->assertEquals(1, count($requests), "At least 1 occurance of this requested privilege should occur in the database"); $this->acl->checkPrivilegeRequest('index', 'resource01', $em); $requestsNewRun = $em->getRepository('JaztecAcl\\Entity\\Monitor\\RequestedPrivilege')->findBy(array('privilege' => 'index', 'resource' => 'resource01')); /* @var $requestsNewRun array */ $this->assertGreaterThan(0, count($requestsNewRun), "The newly added privilege should exist in the database, also in the second run"); $this->assertEquals(1, count($requestsNewRun), "After a second run their thould only be one instance of the requested privilege"); }
<?php namespace JaztecAcl; use Zend\Cache\StorageFactory; use Zend\ServiceManager\ServiceLocatorInterface; return ['invokables' => ['jaztec_acl_service' => 'JaztecAcl\\Service\\AclService', 'jaztec_acl_installation_service' => 'JaztecAcl\\Service\\InstallationService'], 'factories' => ['jaztec_cache' => function (ServiceLocatorInterface $sm) { /* @var $config array */ $config = $sm->get('Config'); return StorageFactory::factory($config['jaztec_acl']['cache']); }, 'jaztec_acl' => function (ServiceLocatorInterface $sm) { $cache = $sm->get('jaztec_cache'); if ($cache->hasItem('jaztec_acl') && $config['jaztec_acl']['use_cache'] === true) { $acl = $cache->getItem('jaztec_acl'); } else { $acl = new Acl\Acl(); } $acl->setEntityManager($sm->get('doctrine.entitymanager.orm_default')); return $acl; }], 'initializers' => ['jaztec_acl' => function ($instance, ServiceLocatorInterface $sm) { if ($instance instanceof Acl\AclAwareInterface) { $instance->setAcl($sm->get('jaztec_acl')); } }, 'jaztec_aclservice' => function ($instance, ServiceLocatorInterface $sm) { if ($instance instanceof Service\AclServiceAwareInterface) { $instance->setAclService($sm->get('jaztec_acl_service')); } }, 'jaztec_cache' => function ($instance, ServiceLocatorInterface $sm) { if ($instance instanceof Cache\CacheAwareInterface) { $instance->setCacheStorage($sm->get('jaztec_cache')); }