Exemple #1
0
 public function testHelperIsRegistered()
 {
     $serviceManager = ServiceManagerFactory::getServiceManager();
     $config = $serviceManager->get('Config');
     $this->assertArrayHasKey('view_helpers', $config);
     $viewHelpersConfig = $config['view_helpers'];
     $this->assertEquals('ZfjRbac\\View\\Helper\\IsGranted', $viewHelpersConfig['aliases']['isGranted']);
     $this->assertEquals('ZfjRbac\\Factory\\IsGrantedViewHelperFactory', $viewHelpersConfig['factories']['ZfjRbac\\View\\Helper\\IsGranted']);
 }
 public function testAssertModuleDefaultOptions()
 {
     /** @var \ZfjRbac\Options\ModuleOptions $moduleOptions */
     $moduleOptions = ServiceManagerFactory::getServiceManager()->get('ZfjRbac\\Options\\ModuleOptions');
     $this->assertEquals('ZfjRbac\\Identity\\AuthenticationIdentityProvider', $moduleOptions->getIdentityProvider());
     $this->assertEquals('guest', $moduleOptions->getGuestRole());
     $this->assertEquals('allow', $moduleOptions->getProtectionPolicy());
     $this->assertInternalType('array', $moduleOptions->getGuards());
     $this->assertInternalType('array', $moduleOptions->getRoleProvider());
     $this->assertInternalType('array', $moduleOptions->getAssertionMap());
     $this->assertInstanceOf('ZfjRbac\\Options\\UnauthorizedStrategyOptions', $moduleOptions->getUnauthorizedStrategy());
     $this->assertInstanceOf('ZfjRbac\\Options\\RedirectStrategyOptions', $moduleOptions->getRedirectStrategy());
 }
 public function testDelegatorThrowExceptionWhenBadInterface()
 {
     $serviceManager = ServiceManagerFactory::getServiceManager();
     $serviceManager->setAllowOverride(true);
     $authorizationService = $this->getMock('ZfjRbac\\Service\\AuthorizationService', [], [], '', false);
     $serviceManager->setService('ZfjRbac\\Service\\AuthorizationService', $authorizationService);
     $serviceManager->setAllowOverride(false);
     $serviceManager->setFactory('ZfjRbacTest\\AuthorizationAware', function () {
         return new \StdClass();
     });
     $serviceManager->addDelegator('ZfjRbacTest\\AuthorizationAware', 'ZfjRbac\\Factory\\AuthorizationServiceDelegatorFactory');
     $this->setExpectedException('ZfjRbac\\Exception\\RuntimeException', 'The service ZfjRbacTest\\AuthorizationAware must implement AuthorizationServiceAwareInterface.');
     $serviceManager->get('ZfjRbacTest\\AuthorizationAware');
 }
Exemple #4
0
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
 * and is licensed under the MIT license.
 */
use ZfjRbacTest\Util\ServiceManagerFactory;
ini_set('error_reporting', E_ALL);
$files = [__DIR__ . '/../vendor/autoload.php', __DIR__ . '/../../../autoload.php'];
foreach ($files as $file) {
    if (file_exists($file)) {
        $loader = (require $file);
        break;
    }
}
if (!isset($loader)) {
    throw new RuntimeException('vendor/autoload.php could not be found. Did you install via composer?');
}
$loader->add('ZfjRbacTest\\', __DIR__);
$configFiles = [__DIR__ . '/TestConfiguration.php', __DIR__ . '/TestConfiguration.php.dist'];
foreach ($configFiles as $configFile) {
    if (file_exists($configFile)) {
        $config = (require $configFile);
        break;
    }
}
ServiceManagerFactory::setApplicationConfig($config);
unset($files, $file, $loader, $configFiles, $configFile, $config);
 public function testThrowExceptionIfAskedRoleIsNotFound()
 {
     $this->serviceManager = ServiceManagerFactory::getServiceManager();
     $objectManager = $this->getObjectManager();
     $objectRepository = $objectManager->getRepository('ZfjRbacTest\\Asset\\FlatRole');
     $objectRepositoryRoleProvider = new ObjectRepositoryRoleProvider($objectRepository, 'name');
     $this->setExpectedException('ZfjRbac\\Exception\\RoleNotFoundException', 'Some roles were asked but could not be loaded from database: guest, admin');
     $objectRepositoryRoleProvider->getRoles(['guest', 'admin']);
 }