1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2015 Sourcefabric z.u. and contributors. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please see the |
9
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @copyright 2015 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace spec\SWP\Bundle\MultiTenancyBundle\EventListener; |
16
|
|
|
|
17
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
18
|
|
|
use PhpSpec\ObjectBehavior; |
19
|
|
|
use SWP\Bundle\MultiTenancyBundle\EventListener\TenantableListener; |
20
|
|
|
use SWP\Bundle\MultiTenancyBundle\MultiTenancyEvents; |
21
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
22
|
|
|
use SWP\Component\MultiTenancy\Model\Tenant; |
23
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
24
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
25
|
|
|
use Symfony\Component\HttpFoundation\Request; |
26
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
27
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @mixin TenantableListener |
31
|
|
|
*/ |
32
|
|
|
class TenantableListenerSpec extends ObjectBehavior |
33
|
|
|
{ |
34
|
|
|
public function let( |
35
|
|
|
RegistryInterface $doctrine, |
36
|
|
|
TenantContextInterface $tenantContext |
37
|
|
|
) { |
38
|
|
|
$this->beConstructedWith($doctrine, $tenantContext); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function it_is_initializable() |
42
|
|
|
{ |
43
|
|
|
$this->shouldHaveType(TenantableListener::class); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function it_implements_event_subscriber_interface() |
47
|
|
|
{ |
48
|
|
|
$this->shouldImplement(EventSubscriberInterface::class); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function it_subscribes_to_event() |
52
|
|
|
{ |
53
|
|
|
$this::getSubscribedEvents()->shouldReturn([ |
54
|
|
|
KernelEvents::REQUEST => 'enable', |
55
|
|
|
MultiTenancyEvents::TENANTABLE_ENABLE => 'enable', |
56
|
|
|
MultiTenancyEvents::TENANTABLE_DISABLE => 'disable', |
57
|
|
|
]); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function it_skips_tenantable_filter_on_kernel_request( |
61
|
|
|
GetResponseEvent $event, |
62
|
|
|
$tenantContext, |
63
|
|
|
EntityManagerInterface $entityManager |
64
|
|
|
) { |
65
|
|
|
$tenantContext->getTenant()->shouldBeCalled()->willReturn(new Tenant()); |
66
|
|
|
$entityManager->getFilters()->shouldNotBeCalled(); |
67
|
|
|
|
68
|
|
|
$this->enable($event)->shouldBeNull(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|