示例#1
0
 public function testJoinACLWithoutEntityAliasAndClass()
 {
     $em = $this->getMock('Doctrine\\ORM\\EntityManager', [], [], '', false);
     $identity = $this->getMockForAbstractClass('MyCLabs\\ACL\\Model\\SecurityIdentityInterface');
     $qb = new QueryBuilder($em);
     $qb->select('test')->from('test', 'test');
     ACLQueryHelper::joinACL($qb, $identity, Actions::VIEW);
     $dql = 'SELECT test FROM test test INNER JOIN MyCLabs\\ACL\\Model\\Authorization authorization ' . 'WITH test.id = authorization.entityId ' . 'WHERE authorization.entityClass = :acl_entity_class ' . 'AND authorization.securityIdentity = :acl_identity ' . 'AND authorization.actions.view = true';
     $this->assertEquals($dql, $qb->getDQL());
     $this->assertSame('test', $qb->getParameter('acl_entity_class')->getValue());
     $this->assertSame($identity, $qb->getParameter('acl_identity')->getValue());
 }
示例#2
0
 /**
  * @link https://github.com/myclabs/ACL/issues/8
  * @test
  */
 public function duplicateAuthorizationShouldNotYieldEntityTwice()
 {
     $article1 = new Article();
     $this->em->persist($article1);
     $article2 = new Article();
     $this->em->persist($article2);
     $user = new User();
     $this->em->persist($user);
     $this->em->flush();
     // Add the role twice => 2 authorizations for the same resource
     $this->acl->grant($user, new ArticleEditorRole($user, $article2));
     $this->acl->grant($user, new ArticleEditorRole($user, $article2));
     // Check that there is really 2 authorizations created
     $authorizations = $this->em->getRepository('MyCLabs\\ACL\\Model\\Authorization')->findAll();
     $this->assertCount(2, $authorizations);
     $qb = $this->em->createQueryBuilder();
     $qb->select('a')->from('Tests\\MyCLabs\\ACL\\Integration\\Model\\Article', 'a');
     ACLQueryHelper::joinACL($qb, $user, Actions::VIEW);
     $articles = $qb->getQuery()->getResult();
     // Check that we get the article only once
     $this->assertCount(1, $articles);
     $this->assertSame($article2, current($articles));
 }