1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace spec\Sylius\Bundle\RbacBundle\Authorization; |
13
|
|
|
|
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\AuthorizationCheckerInterface as ResourceBundleAuthorizationCheckerInterface; |
16
|
|
|
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration; |
17
|
|
|
use Sylius\Component\Rbac\Authorization\AuthorizationCheckerInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Paweł Jędrzejewski <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class RbacAuthorizationCheckerSpec extends ObjectBehavior |
23
|
|
|
{ |
24
|
|
|
function let(AuthorizationCheckerInterface $rbacAuthorizationChecker) |
25
|
|
|
{ |
26
|
|
|
$this->beConstructedWith($rbacAuthorizationChecker); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
function it_is_initializable() |
30
|
|
|
{ |
31
|
|
|
$this->shouldHaveType('Sylius\Bundle\RbacBundle\Authorization\RbacAuthorizationChecker'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_implements_resource_controller_authorization_checker_interface() |
35
|
|
|
{ |
36
|
|
|
$this->shouldImplement(ResourceBundleAuthorizationCheckerInterface::class); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_grants_access_if_permission_is_not_required(RequestConfiguration $requestConfiguration) |
40
|
|
|
{ |
41
|
|
|
$requestConfiguration->hasPermission()->willReturn(false); |
42
|
|
|
$this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(true); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_uses_rbac_authorization_checker( |
46
|
|
|
RequestConfiguration $requestConfiguration, |
47
|
|
|
AuthorizationCheckerInterface $rbacAuthorizationChecker |
48
|
|
|
) { |
49
|
|
|
$requestConfiguration->hasPermission()->willReturn(true); |
50
|
|
|
$requestConfiguration->getPermission('sylius.product.foo')->willReturn('sylius.product.foo'); |
51
|
|
|
$rbacAuthorizationChecker->isGranted('sylius.product.foo')->willReturn(false); |
52
|
|
|
$this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(false); |
53
|
|
|
|
54
|
|
|
$rbacAuthorizationChecker->isGranted('sylius.product.foo')->willReturn(true); |
55
|
|
|
$this->isGranted($requestConfiguration, 'sylius.product.foo')->shouldReturn(true); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
|