Exemplo n.º 1
0
 function it_checks_if_permission_is_in_the_cached_array($cache, RoleInterface $role)
 {
     $role->getCode()->shouldBeCalled()->willReturn('catalog_manager');
     $cache->contains('rbac_role:catalog_manager')->shouldBeCalled()->willReturn(true);
     $cache->fetch('rbac_role:catalog_manager')->shouldBeCalled()->willReturn(['can_eat_bananas', 'can_smash_bananas']);
     $this->hasPermission($role, 'can_eat_bananas')->shouldReturn(true);
     $this->hasPermission($role, 'can_eat_oranges')->shouldReturn(false);
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function getPermissions(RoleInterface $role)
 {
     $permissions = new ArrayCollection();
     $iterator = new \RecursiveIteratorIterator(new RecursivePermissionIterator($role->getPermissions()), \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $permission) {
         if (!$permissions->contains($permission)) {
             $permissions->add($permission);
         }
     }
     return $permissions;
 }
 /**
  * {@inheritdoc}
  */
 public function getPermissions(RoleInterface $role)
 {
     $permissions = new ArrayCollection();
     foreach ($role->getPermissions() as $permission) {
         $permissions->add($permission);
         foreach ($this->getChildPermissions($permission) as $childPermission) {
             if (!$permissions->contains($childPermission)) {
                 $permissions->add($childPermission);
             }
         }
     }
     return $permissions;
 }
Exemplo n.º 4
0
 function it_gets_chield_roles($em, $builder, RoleInterface $role, QueryBuilder $builder, AbstractQuery $query, Expr $expr)
 {
     $role->getRight()->shouldBeCalled()->willReturn(1);
     $role->getLeft()->shouldBeCalled()->willReturn(2);
     $builder->expr()->shouldBeCalled()->willReturn($expr);
     $expr->lt('o.left', 1)->shouldBeCalled()->willReturn($expr);
     $expr->gt('o.left', 2)->shouldBeCalled()->willReturn($expr);
     $em->createQueryBuilder()->shouldBeCalled()->willReturn($builder);
     $builder->select('o')->shouldBeCalled()->willReturn($builder);
     $builder->from(Argument::any(), 'o', Argument::cetera())->shouldBeCalled()->willReturn($builder);
     $builder->where(Argument::type('Doctrine\\ORM\\Query\\Expr'))->shouldBeCalled()->willReturn($builder);
     $builder->andWhere(Argument::type('Doctrine\\ORM\\Query\\Expr'))->shouldBeCalled()->willReturn($builder);
     $builder->getQuery()->shouldBeCalled()->willReturn($query);
     $query->execute()->shouldBeCalled();
     $this->getChildRoles($role);
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function getChildRoles(RoleInterface $role)
 {
     $queryBuilder = $this->createQueryBuilder('o');
     return $queryBuilder->where($queryBuilder->expr()->lt('o.left', $role->getRight()))->andWhere($queryBuilder->expr()->gt('o.left', $role->getLeft()))->getQuery()->execute();
 }
Exemplo n.º 6
0
 /**
  * @param RoleInterface $role
  *
  * @return string
  */
 private function getCacheKey(RoleInterface $role)
 {
     return self::CACHE_KEY_PREFIX . $role->getCode();
 }
Exemplo n.º 7
0
 /**
  * @param RoleInterface $role
  *
  * @return string
  */
 private function getCacheKey(RoleInterface $role)
 {
     return $role->getCode();
 }