EntryTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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\Entry;
  12. class EntryTest extends \PHPUnit_Framework_TestCase
  13. {
  14. public function testConstructor()
  15. {
  16. $ace = $this->getAce($acl = $this->getAcl(), $sid = $this->getSid());
  17. $this->assertEquals(123, $ace->getId());
  18. $this->assertSame($acl, $ace->getAcl());
  19. $this->assertSame($sid, $ace->getSecurityIdentity());
  20. $this->assertEquals('foostrat', $ace->getStrategy());
  21. $this->assertEquals(123456, $ace->getMask());
  22. $this->assertTrue($ace->isGranting());
  23. $this->assertTrue($ace->isAuditSuccess());
  24. $this->assertFalse($ace->isAuditFailure());
  25. }
  26. public function testSetAuditSuccess()
  27. {
  28. $ace = $this->getAce();
  29. $this->assertTrue($ace->isAuditSuccess());
  30. $ace->setAuditSuccess(false);
  31. $this->assertFalse($ace->isAuditSuccess());
  32. $ace->setAuditSuccess(true);
  33. $this->assertTrue($ace->isAuditSuccess());
  34. }
  35. public function testSetAuditFailure()
  36. {
  37. $ace = $this->getAce();
  38. $this->assertFalse($ace->isAuditFailure());
  39. $ace->setAuditFailure(true);
  40. $this->assertTrue($ace->isAuditFailure());
  41. $ace->setAuditFailure(false);
  42. $this->assertFalse($ace->isAuditFailure());
  43. }
  44. public function testSetMask()
  45. {
  46. $ace = $this->getAce();
  47. $this->assertEquals(123456, $ace->getMask());
  48. $ace->setMask(4321);
  49. $this->assertEquals(4321, $ace->getMask());
  50. }
  51. public function testSetStrategy()
  52. {
  53. $ace = $this->getAce();
  54. $this->assertEquals('foostrat', $ace->getStrategy());
  55. $ace->setStrategy('foo');
  56. $this->assertEquals('foo', $ace->getStrategy());
  57. }
  58. public function testSerializeUnserialize()
  59. {
  60. $ace = $this->getAce();
  61. $serialized = serialize($ace);
  62. $uAce = unserialize($serialized);
  63. $this->assertNull($uAce->getAcl());
  64. $this->assertInstanceOf('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface', $uAce->getSecurityIdentity());
  65. $this->assertEquals($ace->getId(), $uAce->getId());
  66. $this->assertEquals($ace->getMask(), $uAce->getMask());
  67. $this->assertEquals($ace->getStrategy(), $uAce->getStrategy());
  68. $this->assertEquals($ace->isGranting(), $uAce->isGranting());
  69. $this->assertEquals($ace->isAuditSuccess(), $uAce->isAuditSuccess());
  70. $this->assertEquals($ace->isAuditFailure(), $uAce->isAuditFailure());
  71. }
  72. protected function getAce($acl = null, $sid = null)
  73. {
  74. if (null === $acl) {
  75. $acl = $this->getAcl();
  76. }
  77. if (null === $sid) {
  78. $sid = $this->getSid();
  79. }
  80. return new Entry(
  81. 123,
  82. $acl,
  83. $sid,
  84. 'foostrat',
  85. 123456,
  86. true,
  87. false,
  88. true
  89. );
  90. }
  91. protected function getAcl()
  92. {
  93. return $this->getMock('Symfony\Component\Security\Acl\Model\AclInterface');
  94. }
  95. protected function getSid()
  96. {
  97. return $this->getMock('Symfony\Component\Security\Acl\Model\SecurityIdentityInterface');
  98. }
  99. }