AuditLoggerTest.php 1.9 KB

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