|
@@ -11,6 +11,7 @@
|
|
|
|
|
|
namespace Sonata\AdminBundle\Tests\Security\Handler;
|
|
|
|
|
|
+use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
|
|
|
use Symfony\Component\Security\Core\SecurityContextInterface;
|
|
|
use Sonata\AdminBundle\Admin\AdminInterface;
|
|
|
use Sonata\AdminBundle\Security\Handler\RoleSecurityHandler;
|
|
@@ -29,13 +30,18 @@ class RoleSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
private $admin;
|
|
|
|
|
|
/**
|
|
|
- * @var SecurityContextInterface
|
|
|
+ * @var AuthorizationCheckerInterface|SecurityContextInterface
|
|
|
*/
|
|
|
- private $securityContext;
|
|
|
+ private $authorizationChecker;
|
|
|
|
|
|
public function setUp()
|
|
|
{
|
|
|
- $this->securityContext = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
+ // Set the SecurityContext for Symfony <2.6
|
|
|
+ if (interface_exists('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface')) {
|
|
|
+ $this->authorizationChecker = $this->getMock('Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface');
|
|
|
+ } else {
|
|
|
+ $this->authorizationChecker = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface');
|
|
|
+ }
|
|
|
|
|
|
$this->admin = $this->getMock('Sonata\AdminBundle\Admin\AdminInterface');
|
|
|
}
|
|
@@ -45,7 +51,7 @@ class RoleSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
public function testGetBaseRole($expected, $code)
|
|
|
{
|
|
|
- $handler = new RoleSecurityHandler($this->securityContext, array('ROLE_BATMAN', 'ROLE_IRONMAN'));
|
|
|
+ $handler = new RoleSecurityHandler($this->authorizationChecker, array('ROLE_BATMAN', 'ROLE_IRONMAN'));
|
|
|
|
|
|
$this->admin->expects($this->once())
|
|
|
->method('getCode')
|
|
@@ -75,7 +81,7 @@ class RoleSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
->method('getCode')
|
|
|
->will($this->returnValue($adminCode));
|
|
|
|
|
|
- $this->securityContext->expects($this->any())
|
|
|
+ $this->authorizationChecker->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->returnCallback(function (array $attributes, $object) {
|
|
|
|
|
@@ -179,7 +185,7 @@ class RoleSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
->method('getCode')
|
|
|
->will($this->returnValue('foo.bar'));
|
|
|
|
|
|
- $this->securityContext->expects($this->any())
|
|
|
+ $this->authorizationChecker->expects($this->any())
|
|
|
->method('isGranted')
|
|
|
->will($this->returnCallback(function (array $attributes, $object) {
|
|
|
throw new \RuntimeException('Something is wrong');
|
|
@@ -212,7 +218,7 @@ class RoleSecurityHandlerTest extends \PHPUnit_Framework_TestCase
|
|
|
*/
|
|
|
private function getRoleSecurityHandler(array $superAdminRoles)
|
|
|
{
|
|
|
- return new RoleSecurityHandler($this->securityContext, $superAdminRoles);
|
|
|
+ return new RoleSecurityHandler($this->authorizationChecker, $superAdminRoles);
|
|
|
}
|
|
|
|
|
|
/**
|