|
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
|
|
|
namespace spec\SWP\MultiTenancyBundle\EventListener; |
|
15
|
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
|
17
|
|
|
use SWP\Component\MultiTenancy\Model\Tenant; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\HttpKernel\KernelEvents; |
|
20
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
21
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
|
22
|
|
|
use Symfony\Component\HttpKernel\Event\GetResponseEvent; |
|
23
|
|
|
|
|
24
|
|
|
class TenantableListenerSpec extends ObjectBehavior |
|
25
|
|
|
{ |
|
26
|
|
|
public function let( |
|
27
|
|
|
EntityManagerInterface $entityManager, |
|
28
|
|
|
TenantContextInterface $tenantContext |
|
29
|
|
|
) { |
|
30
|
|
|
$this->beConstructedWith($entityManager, $tenantContext); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function it_is_initializable() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->shouldHaveType('SWP\MultiTenancyBundle\EventListener\TenantableListener'); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function it_implements_event_subscriber_interface() |
|
39
|
|
|
{ |
|
40
|
|
|
$this->shouldImplement('Symfony\Component\EventDispatcher\EventSubscriberInterface'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function it_subscribes_to_event() |
|
44
|
|
|
{ |
|
45
|
|
|
$this::getSubscribedEvents()->shouldReturn([ |
|
46
|
|
|
KernelEvents::REQUEST => 'onKernelRequest', |
|
47
|
|
|
]); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function it_skips_tenantable_filter_on_kernel_request( |
|
51
|
|
|
GetResponseEvent $event, |
|
52
|
|
|
$tenantContext, |
|
53
|
|
|
$entityManager |
|
54
|
|
|
) { |
|
55
|
|
|
$tenantContext->getTenant()->shouldBeCalled()->willReturn(new Tenant()); |
|
56
|
|
|
$entityManager->getFilters()->shouldNotBeCalled(); |
|
57
|
|
|
|
|
58
|
|
|
$this->onKernelRequest($event)->shouldBeNull(); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|