2010-12-14 15:43:40 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
namespace Symfony\Tests\Component\Security\Acl\Domain;
|
|
|
|
|
|
|
|
use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
|
|
|
|
use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
|
|
|
|
|
|
|
|
class UserSecurityIdentityTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
public function testConstructor()
|
|
|
|
{
|
2011-01-02 01:33:00 +00:00
|
|
|
$id = new UserSecurityIdentity('foo', 'Foo');
|
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
$this->assertEquals('foo', $id->getUsername());
|
2011-01-02 01:33:00 +00:00
|
|
|
$this->assertEquals('Foo', $id->getClass());
|
2010-12-14 15:43:40 +00:00
|
|
|
}
|
2011-01-02 01:33:00 +00:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
/**
|
|
|
|
* @dataProvider getCompareData
|
|
|
|
*/
|
|
|
|
public function testEquals($id1, $id2, $equal)
|
|
|
|
{
|
2011-01-25 19:28:26 +00:00
|
|
|
$this->assertSame($equal, $id1->equals($id2));
|
2010-12-14 15:43:40 +00:00
|
|
|
}
|
2011-01-02 01:33:00 +00:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
public function getCompareData()
|
|
|
|
{
|
2011-03-07 17:17:46 +00:00
|
|
|
$account = $this->getMockBuilder('Symfony\Component\Security\Core\User\UserInterface')
|
2011-01-25 19:28:26 +00:00
|
|
|
->setMockClassName('USI_AccountImpl')
|
|
|
|
->getMock();
|
2011-01-02 01:33:00 +00:00
|
|
|
$account
|
2011-01-25 19:28:26 +00:00
|
|
|
->expects($this->any())
|
|
|
|
->method('getUsername')
|
2010-12-14 15:43:40 +00:00
|
|
|
->will($this->returnValue('foo'))
|
|
|
|
;
|
2011-01-02 01:33:00 +00:00
|
|
|
|
2011-01-26 20:34:11 +00:00
|
|
|
$token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
|
2011-01-25 19:28:26 +00:00
|
|
|
$token
|
|
|
|
->expects($this->any())
|
|
|
|
->method('getUser')
|
|
|
|
->will($this->returnValue($account))
|
|
|
|
;
|
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
return array(
|
2011-01-02 01:33:00 +00:00
|
|
|
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('foo', 'Foo'), true),
|
|
|
|
array(new UserSecurityIdentity('foo', 'Bar'), new UserSecurityIdentity('foo', 'Foo'), false),
|
|
|
|
array(new UserSecurityIdentity('foo', 'Foo'), new UserSecurityIdentity('bar', 'Foo'), false),
|
|
|
|
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromAccount($account), false),
|
|
|
|
array(new UserSecurityIdentity('bla', 'Foo'), new UserSecurityIdentity('blub', 'Foo'), false),
|
|
|
|
array(new UserSecurityIdentity('foo', 'Foo'), new RoleSecurityIdentity('foo'), false),
|
2011-01-25 19:28:26 +00:00
|
|
|
array(new UserSecurityIdentity('foo', 'Foo'), UserSecurityIdentity::fromToken($token), false),
|
|
|
|
array(new UserSecurityIdentity('foo', 'USI_AccountImpl'), UserSecurityIdentity::fromToken($token), true),
|
2010-12-14 15:43:40 +00:00
|
|
|
);
|
|
|
|
}
|
2011-01-18 15:41:21 +00:00
|
|
|
}
|