/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclNativeHelper::apply */ public function testApplyAnonymous() { $queryBuilder = new QueryBuilder($this->conn); $queryBuilder->add('from', array(array('table' => 'myTable', 'alias' => 'n'))); $roles = array(); $this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles)); $this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($roles)); $this->token->expects($this->any())->method('getUser')->will($this->returnValue('anon.')); $permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node', 'n'); /* @var $qb QueryBuilder */ $qb = $this->object->apply($queryBuilder, $permissionDef); $query = $qb->getSQL(); $this->assertContains('"IS_AUTHENTICATED_ANONYMOUSLY"', $query); }
/** * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getAllowedEntityIds * @covers Kunstmaan\AdminBundle\Helper\Security\Acl\AclHelper::getPermittedAclIdsSQLForUser */ public function testGetAllowedEntityIds() { $roles = array(new Role('ROLE_KING')); $allRoles = array($roles[0], new Role('ROLE_SUBJECT')); $this->token->expects($this->once())->method('getRoles')->will($this->returnValue($roles)); $this->rh->expects($this->once())->method('getReachableRoles')->with($roles)->will($this->returnValue($allRoles)); $user = $this->getMockBuilder('FOS\\UserBundle\\Model\\UserInterface')->getMock(); $user->expects($this->any())->method('getUsername')->will($this->returnValue('MyUser')); $this->token->expects($this->any())->method('getUser')->will($this->returnValue($user)); $hydrator = $this->getMockBuilder('Doctrine\\ORM\\Internal\\Hydration\\ScalarHydrator')->disableOriginalConstructor()->getMock(); $rows = array(array('id' => 1), array('id' => 9)); $hydrator->expects($this->once())->method('hydrateAll')->will($this->returnValue($rows)); $this->em->expects($this->any())->method('newHydrator')->will($this->returnValue($hydrator)); /* @var $query NativeQuery */ $query = new NativeQuery($this->em); $this->em->expects($this->once())->method('createNativeQuery')->will($this->returnValue($query)); $permissionDef = new PermissionDefinition(array('view'), 'Kunstmaan\\NodeBundle\\Entity\\Node', 'n'); /* @var $result array */ $result = $this->object->getAllowedEntityIds($permissionDef); $this->assertEquals(array(1, 9), $result); }