|
@@ -17,25 +17,30 @@ class AclSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
{
|
|
|
public function testAcl()
|
|
|
{
|
|
|
+ $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
|
|
|
+ $admin->expects($this->any())
|
|
|
+ ->method('getCode')
|
|
|
+ ->will($this->returnValue('test'));
|
|
|
+
|
|
|
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
$securityContext->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->returnValue(true));
|
|
|
|
|
|
- $handler = new AclSecurityHandler($securityContext);
|
|
|
+ $handler = new AclSecurityHandler($securityContext, array());
|
|
|
|
|
|
- $this->assertTrue($handler->isGranted(array('TOTO')));
|
|
|
- $this->assertTrue($handler->isGranted('TOTO'));
|
|
|
+ $this->assertTrue($handler->isGranted($admin, array('TOTO')));
|
|
|
+ $this->assertTrue($handler->isGranted($admin, 'TOTO'));
|
|
|
|
|
|
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
$securityContext->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->returnValue(false));
|
|
|
|
|
|
- $handler = new AclSecurityHandler($securityContext);
|
|
|
+ $handler = new AclSecurityHandler($securityContext, array());
|
|
|
|
|
|
- $this->assertFalse($handler->isGranted(array('TOTO')));
|
|
|
- $this->assertFalse($handler->isGranted('TOTO'));
|
|
|
+ $this->assertFalse($handler->isGranted($admin, array('TOTO')));
|
|
|
+ $this->assertFalse($handler->isGranted($admin, 'TOTO'));
|
|
|
}
|
|
|
|
|
|
public function testBuildInformation()
|
|
@@ -54,7 +59,7 @@ class AclSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
->method('getSecurityInformation')
|
|
|
->will($this->returnValue($informations));
|
|
|
|
|
|
- $handler = new AclSecurityHandler($securityContext);
|
|
|
+ $handler = new AclSecurityHandler($securityContext, array());
|
|
|
|
|
|
$results = $handler->buildSecurityInformation($admin);
|
|
|
|
|
@@ -63,14 +68,19 @@ class AclSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
|
|
|
public function testWithAuthenticationCredentialsNotFoundException()
|
|
|
{
|
|
|
+ $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
|
|
|
+ $admin->expects($this->once())
|
|
|
+ ->method('getCode')
|
|
|
+ ->will($this->returnValue('test'));
|
|
|
+
|
|
|
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
$securityContext->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->throwException(new AuthenticationCredentialsNotFoundException('FAIL')));
|
|
|
|
|
|
- $handler = new AclSecurityHandler($securityContext);
|
|
|
+ $handler = new AclSecurityHandler($securityContext, array());
|
|
|
|
|
|
- $this->assertFalse($handler->isGranted('raise exception'));
|
|
|
+ $this->assertFalse($handler->isGranted($admin, 'raise exception', $admin));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -78,13 +88,18 @@ class AclSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
public function testWithNonAuthenticationCredentialsNotFoundException()
|
|
|
{
|
|
|
+ $admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
|
|
|
+ $admin->expects($this->once())
|
|
|
+ ->method('getCode')
|
|
|
+ ->will($this->returnValue('test'));
|
|
|
+
|
|
|
$securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
$securityContext->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->throwException(new \RunTimeException('FAIL')));
|
|
|
|
|
|
- $handler = new AclSecurityHandler($securityContext);
|
|
|
+ $handler = new AclSecurityHandler($securityContext, array());
|
|
|
|
|
|
- $this->assertFalse($handler->isGranted('raise exception'));
|
|
|
+ $this->assertFalse($handler->isGranted($admin, 'raise exception', $admin));
|
|
|
}
|
|
|
}
|