AuditLoggerTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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\Component\Security\Acl\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. }
  31. else {
  32. $ace
  33. ->expects($this->never())
  34. ->method('isAuditSuccess')
  35. ;
  36. $ace
  37. ->expects($this->once())
  38. ->method('isAuditFailure')
  39. ->will($this->returnValue($audit))
  40. ;
  41. }
  42. if (true === $audit) {
  43. $logger
  44. ->expects($this->once())
  45. ->method('doLog')
  46. ->with($this->equalTo($granting), $this->equalTo($ace))
  47. ;
  48. }
  49. else {
  50. $logger
  51. ->expects($this->never())
  52. ->method('doLog')
  53. ;
  54. }
  55. $logger->logIfNeeded($granting, $ace);
  56. }
  57. public function getTestLogData()
  58. {
  59. return array(
  60. array(true, false),
  61. array(true, true),
  62. array(false, false),
  63. array(false, true),
  64. );
  65. }
  66. protected function getEntry()
  67. {
  68. return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
  69. }
  70. protected function getLogger()
  71. {
  72. return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger');
  73. }
  74. }