Instance can be transformed to a hash and used as an identity token.
사용 중단: since 5.4. Will be removed in 6.0. Use FOSHttpCacheBundle user context feature instead.
상속: implements eZ\Publish\SPI\User\Identity
예제 #1
0
 /**
  * @covers eZ\Publish\Core\MVC\Symfony\Security\User\Identity::__construct
  * @covers eZ\Publish\Core\MVC\Symfony\Security\User\Identity::setInformation
  * @covers eZ\Publish\Core\MVC\Symfony\Security\User\Identity::getHash
  */
 public function testGetHash()
 {
     $identity = new Identity();
     $identity->setInformation('foo', 'bar');
     $hash1 = $identity->getHash();
     $this->assertInternalType('string', $hash1);
     $identity->setInformation('truc', 'muche');
     $hash2 = $identity->getHash();
     $this->assertInternalType('string', $hash2);
     $this->assertTrue($hash1 !== $hash2);
     $identity->setInformation('number', 123);
     $hash3 = $identity->getHash();
     $this->assertInternalType('string', $hash3);
     $this->assertTrue($hash3 !== $hash1);
     $this->assertTrue($hash3 !== $hash2);
     $identity->replaceInformation(array('foo' => 'bar'));
     $this->assertSame($hash1, $identity->getHash());
 }
예제 #2
0
 /**
  * @covers eZ\Publish\Core\MVC\Symfony\Security\User\IdentityDefiner\Role::__construct
  * @covers eZ\Publish\Core\MVC\Symfony\Security\User\IdentityDefiner\Role::setIdentity
  */
 public function testSetIdentity()
 {
     $user = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\User\\User');
     $identity = new Identity();
     $this->repositoryMock->expects($this->once())->method('getCurrentUser')->will($this->returnValue($user));
     $roleId1 = 123;
     $roleId2 = 456;
     $roleId3 = 789;
     $limitationForRole2 = $this->generateLimitationMock(array('limitationValues' => array('/1/2', '/1/2/43')));
     $limitationForRole3 = $this->generateLimitationMock(array('limitationValues' => array('foo', 'bar')));
     $returnedRoleAssignments = array($this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId1)))), $this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId2)), 'limitation' => $limitationForRole2)), $this->generateRoleAssignmentMock(array('role' => $this->generateRoleMock(array('id' => $roleId3)), 'limitation' => $limitationForRole3)));
     $this->roleServiceMock->expects($this->once())->method('getRoleAssignmentsForUser')->with($user, true)->will($this->returnValue($returnedRoleAssignments));
     $this->assertSame(array(), $identity->getInformation());
     $definer = new RoleDefiner($this->repositoryMock);
     $definer->setIdentity($identity);
     $identityInfo = $identity->getInformation();
     $this->assertArrayHasKey('roleIdList', $identityInfo);
     $this->assertSame("{$roleId1}|{$roleId2}|{$roleId3}", $identityInfo['roleIdList']);
     $this->assertArrayHasKey('roleLimitationList', $identityInfo);
     $limitationIdentifierForRole2 = get_class($limitationForRole2);
     $limitationIdentifierForRole3 = get_class($limitationForRole3);
     $this->assertSame("{$roleId2}-{$limitationIdentifierForRole2}:/1/2|/1/2/43,{$roleId3}-{$limitationIdentifierForRole3}:foo|bar", $identityInfo['roleLimitationList']);
 }