2010-12-14 15:43:40 +00:00
|
|
|
<?php
|
|
|
|
|
2011-01-15 13:29:43 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the Symfony package.
|
|
|
|
*
|
2011-03-06 11:40:06 +00:00
|
|
|
* (c) Fabien Potencier <fabien@symfony.com>
|
2011-01-15 13:29:43 +00:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
namespace Symfony\Component\Security\Acl\Domain;
|
|
|
|
|
|
|
|
class AuditLoggerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider getTestLogData
|
|
|
|
*/
|
|
|
|
public function testLogIfNeeded($granting, $audit)
|
|
|
|
{
|
|
|
|
$logger = $this->getLogger();
|
|
|
|
$ace = $this->getEntry();
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
if (true === $granting) {
|
|
|
|
$ace
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAuditSuccess')
|
|
|
|
->will($this->returnValue($audit))
|
|
|
|
;
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
$ace
|
|
|
|
->expects($this->never())
|
|
|
|
->method('isAuditFailure')
|
|
|
|
;
|
2011-01-18 15:41:21 +00:00
|
|
|
} else {
|
2010-12-14 15:43:40 +00:00
|
|
|
$ace
|
|
|
|
->expects($this->never())
|
|
|
|
->method('isAuditSuccess')
|
|
|
|
;
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
$ace
|
|
|
|
->expects($this->once())
|
|
|
|
->method('isAuditFailure')
|
|
|
|
->will($this->returnValue($audit))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (true === $audit) {
|
|
|
|
$logger
|
|
|
|
->expects($this->once())
|
|
|
|
->method('doLog')
|
|
|
|
->with($this->equalTo($granting), $this->equalTo($ace))
|
|
|
|
;
|
2011-01-18 15:41:21 +00:00
|
|
|
} else {
|
2010-12-14 15:43:40 +00:00
|
|
|
$logger
|
|
|
|
->expects($this->never())
|
|
|
|
->method('doLog')
|
|
|
|
;
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
$logger->logIfNeeded($granting, $ace);
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
public function getTestLogData()
|
|
|
|
{
|
|
|
|
return array(
|
|
|
|
array(true, false),
|
|
|
|
array(true, true),
|
|
|
|
array(false, false),
|
|
|
|
array(false, true),
|
|
|
|
);
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
protected function getEntry()
|
|
|
|
{
|
|
|
|
return $this->getMock('Symfony\Component\Security\Acl\Model\AuditableEntryInterface');
|
|
|
|
}
|
2011-04-15 20:12:02 +01:00
|
|
|
|
2010-12-14 15:43:40 +00:00
|
|
|
protected function getLogger()
|
|
|
|
{
|
|
|
|
return $this->getMockForAbstractClass('Symfony\Component\Security\Acl\Domain\AuditLogger');
|
|
|
|
}
|
2011-01-18 15:41:21 +00:00
|
|
|
}
|