AuditLoggerTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. class AuditLoggerTest extends \PHPUnit_Framework_TestCase
  12. {
  13. /**
  14. * @dataProvider getTestLogData
  15. */
  16. public function testLogIfNeeded($granting, $audit)
  17. {
  18. $logger = $this->getLogger();
  19. $ace = $this->getEntry();
  20. if (true === $granting) {
  21. $ace
  22. ->expects($this->once())
  23. ->method('isAuditSuccess')
  24. ->will($this->returnValue($audit))
  25. ;
  26. $ace
  27. ->expects($this->never())
  28. ->method('isAuditFailure')
  29. ;
  30. } else {
  31. $ace
  32. ->expects($this->never())
  33. ->method('isAuditSuccess')
  34. ;
  35. $ace
  36. ->expects($this->once())
  37. ->method('isAuditFailure')
  38. ->will($this->returnValue($audit))
  39. ;
  40. }
  41. if (true === $audit) {
  42. $logger
  43. ->expects($this->once())
  44. ->method('doLog')
  45. ->with($this->equalTo($granting), $this->equalTo($ace))
  46. ;
  47. } else {
  48. $logger
  49. ->expects($this->never())
  50. ->method('doLog')
  51. ;
  52. }
  53. $logger->logIfNeeded($granting, $ace);
  54. }
  55. public function getTestLogData()
  56. {
  57. return array(
  58. array(true, false),
  59. array(true, true),
  60. array(false, false),
  61. array(false, true),
  62. );
  63. }
  64. protected function getEntry()
  65. {
  66. return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
  67. }
  68. protected function getLogger()
  69. {
  70. return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger');
  71. }
  72. }