RoleSecurityIdentityTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Security\Acl\Tests\Domain;
  11. use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
  12. use Symfony\Component\Security\Core\Role\Role;
  13. use Symfony\Component\Security\Acl\Domain\RoleSecurityIdentity;
  14. class RoleSecurityIdentityTest extends \PHPUnit_Framework_TestCase
  15. {
  16. public function testConstructor()
  17. {
  18. $id = new RoleSecurityIdentity('ROLE_FOO');
  19. $this->assertEquals('ROLE_FOO', $id->getRole());
  20. }
  21. public function testConstructorWithRoleInstance()
  22. {
  23. $id = new RoleSecurityIdentity(new Role('ROLE_FOO'));
  24. $this->assertEquals('ROLE_FOO', $id->getRole());
  25. }
  26. /**
  27. * @dataProvider getCompareData
  28. */
  29. public function testEquals($id1, $id2, $equal)
  30. {
  31. if ($equal) {
  32. $this->assertTrue($id1->equals($id2));
  33. } else {
  34. $this->assertFalse($id1->equals($id2));
  35. }
  36. }
  37. public function getCompareData()
  38. {
  39. return array(
  40. array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true),
  41. array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true),
  42. array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false),
  43. array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false),
  44. );
  45. }
  46. }