RoleSecurityIdentityTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.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\Tests\Component\Security\Acl\Domain;
  11. use Symfony\Component\Security\Acl\Domain\UserSecurityIdentity;
  12. use Symfony\Component\Security\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. }
  34. else {
  35. $this->assertFalse($id1->equals($id2));
  36. }
  37. }
  38. public function getCompareData()
  39. {
  40. return array(
  41. array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity('ROLE_FOO'), true),
  42. array(new RoleSecurityIdentity('ROLE_FOO'), new RoleSecurityIdentity(new Role('ROLE_FOO')), true),
  43. array(new RoleSecurityIdentity('ROLE_USER'), new RoleSecurityIdentity('ROLE_FOO'), false),
  44. array(new RoleSecurityIdentity('ROLE_FOO'), new UserSecurityIdentity('ROLE_FOO', 'Foo'), false),
  45. );
  46. }
  47. }