1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 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 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace SWP\Bundle\MultiTenancyBundle\Tests\DependencyInjection; |
16
|
|
|
|
17
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
18
|
|
|
use SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension; |
19
|
|
|
use SWP\Bundle\MultiTenancyBundle\Doctrine\PHPCR\TenantRepository; |
20
|
|
|
use SWP\Component\MultiTenancy\Factory\TenantFactory; |
21
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
22
|
|
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; |
23
|
|
|
|
24
|
|
|
class SWPMultiTenancyExtensionTest extends AbstractExtensionTestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @covers \SWP\Bundle\MultiTenancyBundle\SWPMultiTenancyBundle |
28
|
|
|
* @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension::load |
29
|
|
|
* @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\Configuration::getConfigTreeBuilder |
30
|
|
|
* @covers \SWP\Bundle\MultiTenancyBundle\DependencyInjection\SWPMultiTenancyExtension::loadPhpcr |
31
|
|
|
*/ |
32
|
|
|
public function testLoad() |
33
|
|
|
{ |
34
|
|
|
$container = $this->createContainer(); |
35
|
|
|
$loader = $this->createLoader(); |
36
|
|
|
$config = $this->getConfig(); |
37
|
|
|
|
38
|
|
|
$loader->load([$config], $container); |
39
|
|
|
|
40
|
|
|
$this->assertTrue($container->getParameter('swp_multi_tenancy.backend_type_phpcr')); |
41
|
|
|
$this->assertEquals('/swp', $container->getParameter('swp_multi_tenancy.persistence.phpcr.basepath')); |
42
|
|
|
|
43
|
|
|
$this->assertEquals('content', $container->getParameter('swp_multi_tenancy.persistence.phpcr.content_basepath')); |
44
|
|
|
$this->assertEquals( |
45
|
|
|
'SWP\Bundle\MultiTenancyBundle\Routing\TenantAwareRouter', |
46
|
|
|
$container->getParameter('swp_multi_tenancy.persistence.phpcr.router.class') |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
$this->assertEquals( |
50
|
|
|
['routes1', 'routes2'], |
51
|
|
|
$container->getParameter('swp_multi_tenancy.persistence.phpcr.route_basepaths') |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
$this->assertEquals( |
55
|
|
|
['routes1', 'routes2', 'content', 'menu', 'media'], |
56
|
|
|
$container->getParameter('swp_multi_tenancy.persistence.phpcr.base_paths') |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$this->assertEquals( |
60
|
|
|
'SWP\Component\MultiTenancy\Model\Tenant', |
61
|
|
|
$container->getParameter('swp.model.tenant.class') |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
'SWP\Component\MultiTenancy\Factory\TenantFactory', |
66
|
|
|
$container->getParameter('swp.factory.tenant.class') |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
$this->assertTrue($container->hasParameter('swp_multi_tenancy.backend_type_phpcr')); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
protected function createLoader() |
73
|
|
|
{ |
74
|
|
|
return new SWPMultiTenancyExtension(); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
protected function getConfig() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'persistence' => [ |
81
|
|
|
'phpcr' => [ |
82
|
|
|
'enabled' => true, |
83
|
|
|
'content_basepath' => 'content', |
84
|
|
|
'route_basepaths' => ['routes1', 'routes2'], |
85
|
|
|
], |
86
|
|
|
], |
87
|
|
|
]; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
protected function createContainer(array $data = []) |
91
|
|
|
{ |
92
|
|
|
return new ContainerBuilder(new ParameterBag($data)); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @test |
97
|
|
|
*/ |
98
|
|
|
public function if_orm_backend_is_enabled() |
99
|
|
|
{ |
100
|
|
|
$this->load(['persistence' => ['orm' => ['enabled' => true]]]); |
101
|
|
|
|
102
|
|
|
$this->assertContainerBuilderHasParameter('swp_multi_tenancy.backend_type_orm', true); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @test |
107
|
|
|
*/ |
108
|
|
|
public function if_phpcr_backend_is_enabled() |
109
|
|
|
{ |
110
|
|
|
$this->load(['persistence' => ['phpcr' => ['enabled' => true]]]); |
111
|
|
|
|
112
|
|
|
$this->assertContainerBuilderHasParameter('swp_multi_tenancy.backend_type_phpcr', true); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @test |
117
|
|
|
* @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException |
118
|
|
|
*/ |
119
|
|
|
public function if_persistence_backend_is_not_enabled() |
120
|
|
|
{ |
121
|
|
|
$this->load(); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @test |
126
|
|
|
*/ |
127
|
|
|
public function the_orm_listeners_are_disabled_by_default() |
128
|
|
|
{ |
129
|
|
|
$this->load(['persistence' => ['phpcr' => ['enabled' => true]]]); |
130
|
|
|
|
131
|
|
|
$this->assertContainerBuilderNotHasService('swp_multi_tenancy.tenant_listener'); |
132
|
|
|
$this->assertContainerBuilderNotHasService('swp_multi_tenancy.tenant_subscriber'); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @test |
137
|
|
|
*/ |
138
|
|
|
public function the_orm_listeners_are_enabled() |
139
|
|
|
{ |
140
|
|
|
$this->load(['use_orm_listeners' => true, 'persistence' => ['phpcr' => ['enabled' => true]]]); |
141
|
|
|
|
142
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.tenant_listener'); |
143
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.tenant_subscriber'); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @test |
148
|
|
|
*/ |
149
|
|
|
public function if_loads_all_needed_services_by_default() |
150
|
|
|
{ |
151
|
|
|
$this->load(['persistence' => ['phpcr' => ['enabled' => true]]]); |
152
|
|
|
|
153
|
|
|
$this->assertContainerBuilderHasService('swp.repository.tenant', TenantRepository::class); |
154
|
|
|
$this->assertContainerBuilderHasService('swp.factory.tenant', TenantFactory::class); |
155
|
|
|
$this->assertContainerBuilderHasService('swp.object_manager.tenant'); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @test |
160
|
|
|
*/ |
161
|
|
|
public function when_phpcr_backend_enabeled() |
162
|
|
|
{ |
163
|
|
|
$this->load(['persistence' => ['phpcr' => ['enabled' => true]]]); |
164
|
|
|
|
165
|
|
|
$this->assertContainerBuilderHasService('swp.repository.tenant', TenantRepository::class); |
166
|
|
|
$this->assertContainerBuilderHasService('swp.factory.tenant', TenantFactory::class); |
167
|
|
|
$this->assertContainerBuilderHasService('swp.object_manager.tenant'); |
168
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.phpcr.generic_initializer'); |
169
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.phpcr.initializer'); |
170
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.path_builder'); |
171
|
|
|
$this->assertContainerBuilderHasService('swp_multi_tenancy.tenant_aware_router'); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* {@inheritdoc} |
176
|
|
|
*/ |
177
|
|
|
protected function getContainerExtensions() |
178
|
|
|
{ |
179
|
|
|
return [ |
180
|
|
|
new SWPMultiTenancyExtension(), |
181
|
|
|
]; |
182
|
|
|
} |
183
|
|
|
} |
184
|
|
|
|