1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the EzPublishCoreExtensionTest class. |
5
|
|
|
* |
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Common; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Content; |
13
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension; |
14
|
|
|
use eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Stub\StubPolicyProvider; |
15
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase; |
16
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
17
|
|
|
use Symfony\Component\Yaml\Yaml; |
18
|
|
|
use ReflectionObject; |
19
|
|
|
|
20
|
|
|
class EzPublishCoreExtensionTest extends AbstractExtensionTestCase |
21
|
|
|
{ |
22
|
|
|
private $minimalConfig = array(); |
23
|
|
|
|
24
|
|
|
private $siteaccessConfig = array(); |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension |
28
|
|
|
*/ |
29
|
|
|
private $extension; |
30
|
|
|
|
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->extension = new EzPublishCoreExtension(); |
34
|
|
|
$this->siteaccessConfig = array( |
35
|
|
|
'siteaccess' => array( |
36
|
|
|
'default_siteaccess' => 'ezdemo_site', |
37
|
|
|
'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'), |
38
|
|
|
'groups' => array( |
39
|
|
|
'ezdemo_group' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'), |
40
|
|
|
'ezdemo_frontend_group' => array('ezdemo_site', 'eng', 'fre'), |
41
|
|
|
), |
42
|
|
|
'match' => array( |
43
|
|
|
'URILElement' => 1, |
44
|
|
|
'Map\URI' => array('the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin'), |
45
|
|
|
), |
46
|
|
|
), |
47
|
|
|
'system' => array( |
48
|
|
|
'ezdemo_site' => array(), |
49
|
|
|
'eng' => array(), |
50
|
|
|
'fre' => array(), |
51
|
|
|
'ezdemo_site_admin' => array(), |
52
|
|
|
), |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
parent::setUp(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
protected function getContainerExtensions() |
59
|
|
|
{ |
60
|
|
|
return array($this->extension); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getMinimalConfiguration() |
64
|
|
|
{ |
65
|
|
|
return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml')); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function testSiteAccessConfiguration() |
69
|
|
|
{ |
70
|
|
|
// Injecting needed config parsers. |
71
|
|
|
$refExtension = new ReflectionObject($this->extension); |
72
|
|
|
$refMethod = $refExtension->getMethod('getMainConfigParser'); |
73
|
|
|
$refMethod->setAccessible(true); |
74
|
|
|
$refMethod->invoke($this->extension); |
75
|
|
|
$refParser = $refExtension->getProperty('mainConfigParser'); |
76
|
|
|
$refParser->setAccessible(true); |
77
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */ |
78
|
|
|
$parser = $refParser->getValue($this->extension); |
79
|
|
|
$parser->setConfigParsers(array(new Common(), new Content())); |
80
|
|
|
|
81
|
|
|
$this->load($this->siteaccessConfig); |
82
|
|
|
$this->assertContainerBuilderHasParameter( |
83
|
|
|
'ezpublish.siteaccess.list', |
84
|
|
|
$this->siteaccessConfig['siteaccess']['list'] |
85
|
|
|
); |
86
|
|
|
$this->assertContainerBuilderHasParameter( |
87
|
|
|
'ezpublish.siteaccess.default', |
88
|
|
|
$this->siteaccessConfig['siteaccess']['default_siteaccess'] |
89
|
|
|
); |
90
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', $this->siteaccessConfig['siteaccess']['groups']); |
91
|
|
|
|
92
|
|
|
$expectedMatchingConfig = array(); |
93
|
|
|
foreach ($this->siteaccessConfig['siteaccess']['match'] as $key => $val) { |
94
|
|
|
// Value is expected to always be an array (transformed by semantic configuration parser). |
95
|
|
|
$expectedMatchingConfig[$key] = is_array($val) ? $val : array('value' => $val); |
96
|
|
|
} |
97
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', $expectedMatchingConfig); |
98
|
|
|
|
99
|
|
|
$groupsBySiteaccess = array(); |
100
|
|
View Code Duplication |
foreach ($this->siteaccessConfig['siteaccess']['groups'] as $groupName => $groupMembers) { |
|
|
|
|
101
|
|
|
foreach ($groupMembers as $member) { |
102
|
|
|
if (!isset($groupsBySiteaccess[$member])) { |
103
|
|
|
$groupsBySiteaccess[$member] = array(); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
$groupsBySiteaccess[$member][] = $groupName; |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess); |
110
|
|
|
|
111
|
|
|
$relatedSiteAccesses = array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'); |
112
|
|
|
$this->assertContainerBuilderHasParameter( |
113
|
|
|
'ezpublish.siteaccess.relation_map', |
114
|
|
|
array( |
115
|
|
|
// Empty string is the default repository name |
116
|
|
|
'' => array( |
117
|
|
|
// 2 is the default rootLocationId |
118
|
|
|
2 => $relatedSiteAccesses, |
119
|
|
|
), |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
|
123
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses); |
124
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses); |
125
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testSiteAccessNoConfiguration() |
129
|
|
|
{ |
130
|
|
|
$this->load(); |
131
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.list', array('setup')); |
132
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.default', 'setup'); |
133
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', array()); |
134
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', array()); |
135
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', null); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function testImageMagickConfigurationBasic() |
139
|
|
|
{ |
140
|
|
View Code Duplication |
if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { |
|
|
|
|
141
|
|
|
$this->markTestSkipped('Missing or mis-configured Imagemagick convert path.'); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$this->load( |
145
|
|
|
array( |
146
|
|
|
'imagemagick' => array( |
147
|
|
|
'enabled' => true, |
148
|
|
|
'path' => $_ENV['imagemagickConvertPath'], |
149
|
|
|
), |
150
|
|
|
) |
151
|
|
|
); |
152
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.enabled', true); |
153
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable_path', dirname($_ENV['imagemagickConvertPath'])); |
154
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable', basename($_ENV['imagemagickConvertPath'])); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function testImageMagickConfigurationFilters() |
158
|
|
|
{ |
159
|
|
View Code Duplication |
if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { |
|
|
|
|
160
|
|
|
$this->markTestSkipped('Missing or mis-configured Imagemagick convert path.'); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
$customFilters = array( |
164
|
|
|
'foobar' => '-foobar', |
165
|
|
|
'wow' => '-amazing', |
166
|
|
|
); |
167
|
|
|
$this->load( |
168
|
|
|
array( |
169
|
|
|
'imagemagick' => array( |
170
|
|
|
'enabled' => true, |
171
|
|
|
'path' => $_ENV['imagemagickConvertPath'], |
172
|
|
|
'filters' => $customFilters, |
173
|
|
|
), |
174
|
|
|
) |
175
|
|
|
); |
176
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.image.imagemagick.filters')); |
177
|
|
|
$filters = $this->container->getParameter('ezpublish.image.imagemagick.filters'); |
178
|
|
|
$this->assertArrayHasKey('foobar', $filters); |
179
|
|
|
$this->assertSame($customFilters['foobar'], $filters['foobar']); |
180
|
|
|
$this->assertArrayHasKey('wow', $filters); |
181
|
|
|
$this->assertSame($customFilters['wow'], $filters['wow']); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
public function testEzPageConfiguration() |
185
|
|
|
{ |
186
|
|
|
$customLayouts = array( |
187
|
|
|
'FoobarLayout' => array('name' => 'Foo layout', 'template' => 'foolayout.html.twig'), |
188
|
|
|
); |
189
|
|
|
$enabledLayouts = array('FoobarLayout', 'GlobalZoneLayout'); |
190
|
|
|
$customBlocks = array( |
191
|
|
|
'FoobarBlock' => array('name' => 'Foo block'), |
192
|
|
|
); |
193
|
|
|
$enabledBlocks = array('FoobarBlock', 'DemoBlock'); |
194
|
|
|
$this->load( |
195
|
|
|
array( |
196
|
|
|
'ezpage' => array( |
197
|
|
|
'layouts' => $customLayouts, |
198
|
|
|
'blocks' => $customBlocks, |
199
|
|
|
'enabledLayouts' => $enabledLayouts, |
200
|
|
|
'enabledBlocks' => $enabledBlocks, |
201
|
|
|
), |
202
|
|
|
) |
203
|
|
|
); |
204
|
|
|
|
205
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.ezpage.layouts')); |
206
|
|
|
$layouts = $this->container->getParameter('ezpublish.ezpage.layouts'); |
207
|
|
|
$this->assertArrayHasKey('FoobarLayout', $layouts); |
208
|
|
|
$this->assertSame($customLayouts['FoobarLayout'], $layouts['FoobarLayout']); |
209
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledLayouts', $enabledLayouts); |
210
|
|
|
|
211
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.ezpage.blocks')); |
212
|
|
|
$blocks = $this->container->getParameter('ezpublish.ezpage.blocks'); |
213
|
|
|
$this->assertArrayHasKey('FoobarBlock', $blocks); |
214
|
|
|
$this->assertSame($customBlocks['FoobarBlock'], $blocks['FoobarBlock']); |
215
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledBlocks', $enabledBlocks); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
public function testRoutingConfiguration() |
219
|
|
|
{ |
220
|
|
|
$this->load(); |
221
|
|
|
$this->assertContainerBuilderHasAlias('router', 'ezpublish.chain_router'); |
222
|
|
|
|
223
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.default_router.non_siteaccess_aware_routes')); |
224
|
|
|
$nonSiteaccessAwareRoutes = $this->container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'); |
225
|
|
|
// See ezpublish_minimal_no_siteaccess.yml fixture |
226
|
|
|
$this->assertContains('foo_route', $nonSiteaccessAwareRoutes); |
227
|
|
|
$this->assertContains('my_prefix_', $nonSiteaccessAwareRoutes); |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @dataProvider cacheConfigurationProvider |
232
|
|
|
* |
233
|
|
|
* @param array $customCacheConfig |
234
|
|
|
* @param string $expectedPurgeService |
235
|
|
|
* @param int $expectedTimeout |
|
|
|
|
236
|
|
|
*/ |
237
|
|
|
public function testCacheConfiguration(array $customCacheConfig, $expectedPurgeService) |
238
|
|
|
{ |
239
|
|
|
$this->load($customCacheConfig); |
240
|
|
|
|
241
|
|
|
$this->assertContainerBuilderHasAlias('ezpublish.http_cache.purge_client', $expectedPurgeService); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function cacheConfigurationProvider() |
245
|
|
|
{ |
246
|
|
|
return array( |
247
|
|
|
array(array(), 'ezpublish.http_cache.purge_client.local', 1), |
248
|
|
|
array( |
249
|
|
|
array( |
250
|
|
|
'http_cache' => array('purge_type' => 'local'), |
251
|
|
|
), |
252
|
|
|
'ezpublish.http_cache.purge_client.local', |
253
|
|
|
), |
254
|
|
|
array( |
255
|
|
|
array( |
256
|
|
|
'http_cache' => array('purge_type' => 'multiple_http'), |
257
|
|
|
), |
258
|
|
|
'ezpublish.http_cache.purge_client.fos', |
259
|
|
|
), |
260
|
|
|
array( |
261
|
|
|
array( |
262
|
|
|
'http_cache' => array('purge_type' => 'single_http'), |
263
|
|
|
), |
264
|
|
|
'ezpublish.http_cache.purge_client.fos', |
265
|
|
|
), |
266
|
|
|
array( |
267
|
|
|
array( |
268
|
|
|
'http_cache' => array('purge_type' => 'http'), |
269
|
|
|
), |
270
|
|
|
'ezpublish.http_cache.purge_client.fos', |
271
|
|
|
), |
272
|
|
|
); |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
/** |
276
|
|
|
* @expectedException \InvalidArgumentException |
277
|
|
|
*/ |
278
|
|
|
public function testCacheConfigurationWrongPurgeType() |
279
|
|
|
{ |
280
|
|
|
$this->load( |
281
|
|
|
array( |
282
|
|
|
'http_cache' => array('purge_type' => 'foobar', 'timeout' => 12), |
283
|
|
|
) |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
public function testCacheConfigurationCustomPurgeService() |
288
|
|
|
{ |
289
|
|
|
$serviceId = 'foobar'; |
290
|
|
|
$this->setDefinition($serviceId, new Definition()); |
291
|
|
|
$this->load( |
292
|
|
|
array( |
293
|
|
|
'http_cache' => array('purge_type' => 'foobar', 'timeout' => 12), |
294
|
|
|
) |
295
|
|
|
); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function testLocaleConfiguration() |
299
|
|
|
{ |
300
|
|
|
$this->load(array('locale_conversion' => array('foo' => 'bar'))); |
301
|
|
|
$conversionMap = $this->container->getParameter('ezpublish.locale.conversion_map'); |
302
|
|
|
$this->assertArrayHasKey('foo', $conversionMap); |
303
|
|
|
$this->assertSame('bar', $conversionMap['foo']); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
public function testRepositoriesConfiguration() |
307
|
|
|
{ |
308
|
|
|
$repositories = array( |
309
|
|
|
'main' => array( |
310
|
|
|
'storage' => array( |
311
|
|
|
'engine' => 'legacy', |
312
|
|
|
'connection' => 'default', |
313
|
|
|
), |
314
|
|
|
'search' => array( |
315
|
|
|
'engine' => 'elasticsearch', |
316
|
|
|
'connection' => 'blabla', |
317
|
|
|
), |
318
|
|
|
'fields_groups' => array( |
319
|
|
|
'list' => ['content'], |
320
|
|
|
'default' => 'content', |
321
|
|
|
), |
322
|
|
|
'options' => [ |
323
|
|
|
'default_version_archive_limit' => 5, |
324
|
|
|
], |
325
|
|
|
), |
326
|
|
|
'foo' => array( |
327
|
|
|
'storage' => array( |
328
|
|
|
'engine' => 'sqlng', |
329
|
|
|
'connection' => 'default', |
330
|
|
|
), |
331
|
|
|
'search' => array( |
332
|
|
|
'engine' => 'solr', |
333
|
|
|
'connection' => 'lalala', |
334
|
|
|
), |
335
|
|
|
'fields_groups' => array( |
336
|
|
|
'list' => ['content'], |
337
|
|
|
'default' => 'content', |
338
|
|
|
), |
339
|
|
|
'options' => [ |
340
|
|
|
'default_version_archive_limit' => 5, |
341
|
|
|
], |
342
|
|
|
), |
343
|
|
|
); |
344
|
|
|
$this->load(array('repositories' => $repositories)); |
345
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
346
|
|
|
|
347
|
|
|
foreach ($repositories as &$repositoryConfig) { |
348
|
|
|
$repositoryConfig['storage']['config'] = array(); |
349
|
|
|
$repositoryConfig['search']['config'] = array(); |
350
|
|
|
} |
351
|
|
|
$this->assertSame($repositories, $this->container->getParameter('ezpublish.repositories')); |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
public function testRepositoriesConfigurationEmpty() |
355
|
|
|
{ |
356
|
|
|
$repositories = array( |
357
|
|
|
'main' => null, |
358
|
|
|
); |
359
|
|
|
$expectedRepositories = array( |
360
|
|
|
'main' => array( |
361
|
|
|
'storage' => array( |
362
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
363
|
|
|
'connection' => null, |
364
|
|
|
'config' => array(), |
365
|
|
|
), |
366
|
|
|
'search' => array( |
367
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
368
|
|
|
'connection' => null, |
369
|
|
|
'config' => array(), |
370
|
|
|
), |
371
|
|
|
'fields_groups' => array( |
372
|
|
|
'list' => ['content'], |
373
|
|
|
'default' => 'content', |
374
|
|
|
), |
375
|
|
|
'options' => [ |
376
|
|
|
'default_version_archive_limit' => 5, |
377
|
|
|
], |
378
|
|
|
), |
379
|
|
|
); |
380
|
|
|
$this->load(array('repositories' => $repositories)); |
381
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
382
|
|
|
|
383
|
|
|
$this->assertSame( |
384
|
|
|
$expectedRepositories, |
385
|
|
|
$this->container->getParameter('ezpublish.repositories') |
386
|
|
|
); |
387
|
|
|
} |
388
|
|
|
|
389
|
|
View Code Duplication |
public function testRepositoriesConfigurationStorageEmpty() |
390
|
|
|
{ |
391
|
|
|
$repositories = array( |
392
|
|
|
'main' => array( |
393
|
|
|
'search' => array( |
394
|
|
|
'engine' => 'fantasticfind', |
395
|
|
|
'connection' => 'french', |
396
|
|
|
), |
397
|
|
|
), |
398
|
|
|
); |
399
|
|
|
$expectedRepositories = array( |
400
|
|
|
'main' => array( |
401
|
|
|
'search' => array( |
402
|
|
|
'engine' => 'fantasticfind', |
403
|
|
|
'connection' => 'french', |
404
|
|
|
'config' => array(), |
405
|
|
|
), |
406
|
|
|
'storage' => array( |
407
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
408
|
|
|
'connection' => null, |
409
|
|
|
'config' => array(), |
410
|
|
|
), |
411
|
|
|
'fields_groups' => array( |
412
|
|
|
'list' => ['content'], |
413
|
|
|
'default' => 'content', |
414
|
|
|
), |
415
|
|
|
'options' => [ |
416
|
|
|
'default_version_archive_limit' => 5, |
417
|
|
|
], |
418
|
|
|
), |
419
|
|
|
); |
420
|
|
|
$this->load(array('repositories' => $repositories)); |
421
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
422
|
|
|
|
423
|
|
|
$this->assertSame( |
424
|
|
|
$expectedRepositories, |
425
|
|
|
$this->container->getParameter('ezpublish.repositories') |
426
|
|
|
); |
427
|
|
|
} |
428
|
|
|
|
429
|
|
View Code Duplication |
public function testRepositoriesConfigurationSearchEmpty() |
430
|
|
|
{ |
431
|
|
|
$repositories = array( |
432
|
|
|
'main' => array( |
433
|
|
|
'storage' => array( |
434
|
|
|
'engine' => 'persistentprudence', |
435
|
|
|
'connection' => 'yes', |
436
|
|
|
), |
437
|
|
|
), |
438
|
|
|
); |
439
|
|
|
$expectedRepositories = array( |
440
|
|
|
'main' => array( |
441
|
|
|
'storage' => array( |
442
|
|
|
'engine' => 'persistentprudence', |
443
|
|
|
'connection' => 'yes', |
444
|
|
|
'config' => array(), |
445
|
|
|
), |
446
|
|
|
'search' => array( |
447
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
448
|
|
|
'connection' => null, |
449
|
|
|
'config' => array(), |
450
|
|
|
), |
451
|
|
|
'fields_groups' => array( |
452
|
|
|
'list' => ['content'], |
453
|
|
|
'default' => 'content', |
454
|
|
|
), |
455
|
|
|
'options' => [ |
456
|
|
|
'default_version_archive_limit' => 5, |
457
|
|
|
], |
458
|
|
|
), |
459
|
|
|
); |
460
|
|
|
$this->load(array('repositories' => $repositories)); |
461
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
462
|
|
|
|
463
|
|
|
$this->assertSame( |
464
|
|
|
$expectedRepositories, |
465
|
|
|
$this->container->getParameter('ezpublish.repositories') |
466
|
|
|
); |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
public function testRepositoriesConfigurationCompatibility() |
470
|
|
|
{ |
471
|
|
|
$repositories = array( |
472
|
|
|
'main' => array( |
473
|
|
|
'engine' => 'legacy', |
474
|
|
|
'connection' => 'default', |
475
|
|
|
'search' => array( |
476
|
|
|
'engine' => 'elasticsearch', |
477
|
|
|
'connection' => 'blabla', |
478
|
|
|
), |
479
|
|
|
), |
480
|
|
|
'foo' => array( |
481
|
|
|
'engine' => 'sqlng', |
482
|
|
|
'connection' => 'default', |
483
|
|
|
'search' => array( |
484
|
|
|
'engine' => 'solr', |
485
|
|
|
'connection' => 'lalala', |
486
|
|
|
), |
487
|
|
|
), |
488
|
|
|
); |
489
|
|
|
$expectedRepositories = array( |
490
|
|
|
'main' => array( |
491
|
|
|
'search' => array( |
492
|
|
|
'engine' => 'elasticsearch', |
493
|
|
|
'connection' => 'blabla', |
494
|
|
|
'config' => array(), |
495
|
|
|
), |
496
|
|
|
'storage' => array( |
497
|
|
|
'engine' => 'legacy', |
498
|
|
|
'connection' => 'default', |
499
|
|
|
'config' => array(), |
500
|
|
|
), |
501
|
|
|
'fields_groups' => array( |
502
|
|
|
'list' => ['content'], |
503
|
|
|
'default' => 'content', |
504
|
|
|
), |
505
|
|
|
'options' => [ |
506
|
|
|
'default_version_archive_limit' => 5, |
507
|
|
|
], |
508
|
|
|
), |
509
|
|
|
'foo' => array( |
510
|
|
|
'search' => array( |
511
|
|
|
'engine' => 'solr', |
512
|
|
|
'connection' => 'lalala', |
513
|
|
|
'config' => array(), |
514
|
|
|
), |
515
|
|
|
'storage' => array( |
516
|
|
|
'engine' => 'sqlng', |
517
|
|
|
'connection' => 'default', |
518
|
|
|
'config' => array(), |
519
|
|
|
), |
520
|
|
|
'fields_groups' => array( |
521
|
|
|
'list' => ['content'], |
522
|
|
|
'default' => 'content', |
523
|
|
|
), |
524
|
|
|
'options' => [ |
525
|
|
|
'default_version_archive_limit' => 5, |
526
|
|
|
], |
527
|
|
|
), |
528
|
|
|
); |
529
|
|
|
$this->load(array('repositories' => $repositories)); |
530
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
531
|
|
|
|
532
|
|
|
$this->assertSame( |
533
|
|
|
$expectedRepositories, |
534
|
|
|
$this->container->getParameter('ezpublish.repositories') |
535
|
|
|
); |
536
|
|
|
} |
537
|
|
|
|
538
|
|
View Code Duplication |
public function testRepositoriesConfigurationCompatibility2() |
539
|
|
|
{ |
540
|
|
|
$repositories = array( |
541
|
|
|
'main' => array( |
542
|
|
|
'engine' => 'legacy', |
543
|
|
|
'connection' => 'default', |
544
|
|
|
), |
545
|
|
|
); |
546
|
|
|
$expectedRepositories = array( |
547
|
|
|
'main' => array( |
548
|
|
|
'storage' => array( |
549
|
|
|
'engine' => 'legacy', |
550
|
|
|
'connection' => 'default', |
551
|
|
|
'config' => array(), |
552
|
|
|
), |
553
|
|
|
'search' => array( |
554
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
555
|
|
|
'connection' => null, |
556
|
|
|
'config' => array(), |
557
|
|
|
), |
558
|
|
|
'fields_groups' => array( |
559
|
|
|
'list' => ['content'], |
560
|
|
|
'default' => 'content', |
561
|
|
|
), |
562
|
|
|
'options' => [ |
563
|
|
|
'default_version_archive_limit' => 5, |
564
|
|
|
], |
565
|
|
|
), |
566
|
|
|
); |
567
|
|
|
$this->load(array('repositories' => $repositories)); |
568
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
569
|
|
|
|
570
|
|
|
$this->assertSame( |
571
|
|
|
$expectedRepositories, |
572
|
|
|
$this->container->getParameter('ezpublish.repositories') |
573
|
|
|
); |
574
|
|
|
} |
575
|
|
|
|
576
|
|
|
public function testRelatedSiteAccesses() |
577
|
|
|
{ |
578
|
|
|
$mainRepo = 'main'; |
579
|
|
|
$fooRepo = 'foo'; |
580
|
|
|
$rootLocationId1 = 123; |
581
|
|
|
$rootLocationId2 = 456; |
582
|
|
|
$rootLocationId3 = 2; |
583
|
|
|
$config = array( |
584
|
|
|
'siteaccess' => array( |
585
|
|
|
'default_siteaccess' => 'ezdemo_site', |
586
|
|
|
'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site2', 'eng2', 'ezdemo_site3', 'fre3'), |
587
|
|
|
'groups' => array( |
588
|
|
|
'ezdemo_group' => array('ezdemo_site', 'eng', 'fre'), |
589
|
|
|
'ezdemo_group2' => array('ezdemo_site2', 'eng2'), |
590
|
|
|
'ezdemo_group3' => array('ezdemo_site3', 'fre3'), |
591
|
|
|
), |
592
|
|
|
'match' => array(), |
593
|
|
|
), |
594
|
|
|
'repositories' => array( |
595
|
|
|
$mainRepo => array('engine' => 'legacy', 'connection' => 'default'), |
596
|
|
|
$fooRepo => array('engine' => 'bar', 'connection' => 'blabla'), |
597
|
|
|
), |
598
|
|
|
'system' => array( |
599
|
|
|
'ezdemo_group' => array( |
600
|
|
|
'repository' => $mainRepo, |
601
|
|
|
'content' => array( |
602
|
|
|
'tree_root' => array('location_id' => $rootLocationId1), |
603
|
|
|
), |
604
|
|
|
), |
605
|
|
|
'ezdemo_group2' => array( |
606
|
|
|
'repository' => $mainRepo, |
607
|
|
|
'content' => array( |
608
|
|
|
'tree_root' => array('location_id' => $rootLocationId2), |
609
|
|
|
), |
610
|
|
|
), |
611
|
|
|
'ezdemo_group3' => array( |
612
|
|
|
'repository' => $fooRepo, |
613
|
|
|
), |
614
|
|
|
), |
615
|
|
|
) + $this->siteaccessConfig; |
616
|
|
|
|
617
|
|
|
// Injecting needed config parsers. |
618
|
|
|
$refExtension = new ReflectionObject($this->extension); |
619
|
|
|
$refMethod = $refExtension->getMethod('getMainConfigParser'); |
620
|
|
|
$refMethod->setAccessible(true); |
621
|
|
|
$refMethod->invoke($this->extension); |
622
|
|
|
$refParser = $refExtension->getProperty('mainConfigParser'); |
623
|
|
|
$refParser->setAccessible(true); |
624
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */ |
625
|
|
|
$parser = $refParser->getValue($this->extension); |
626
|
|
|
$parser->setConfigParsers(array(new Common(), new Content())); |
627
|
|
|
|
628
|
|
|
$this->load($config); |
629
|
|
|
|
630
|
|
|
$relatedSiteAccesses1 = array('ezdemo_site', 'eng', 'fre'); |
631
|
|
|
$relatedSiteAccesses2 = array('ezdemo_site2', 'eng2'); |
632
|
|
|
$relatedSiteAccesses3 = array('ezdemo_site3', 'fre3'); |
633
|
|
|
$expectedRelationMap = array( |
634
|
|
|
$mainRepo => array( |
635
|
|
|
$rootLocationId1 => $relatedSiteAccesses1, |
636
|
|
|
$rootLocationId2 => $relatedSiteAccesses2, |
637
|
|
|
), |
638
|
|
|
$fooRepo => array( |
639
|
|
|
$rootLocationId3 => $relatedSiteAccesses3, |
640
|
|
|
), |
641
|
|
|
); |
642
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.relation_map', $expectedRelationMap); |
643
|
|
|
|
644
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses1); |
645
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses1); |
646
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses1); |
647
|
|
|
|
648
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site2.related_siteaccesses', $relatedSiteAccesses2); |
649
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng2.related_siteaccesses', $relatedSiteAccesses2); |
650
|
|
|
|
651
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site3.related_siteaccesses', $relatedSiteAccesses3); |
652
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre3.related_siteaccesses', $relatedSiteAccesses3); |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
public function testRegisteredPolicies() |
656
|
|
|
{ |
657
|
|
|
$policies1 = [ |
658
|
|
|
'custom_module' => [ |
659
|
|
|
'custom_function_1' => null, |
660
|
|
|
'custom_function_2' => ['CustomLimitation'], |
661
|
|
|
], |
662
|
|
|
'helloworld' => [ |
663
|
|
|
'foo' => ['bar'], |
664
|
|
|
'baz' => null, |
665
|
|
|
], |
666
|
|
|
]; |
667
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies1)); |
668
|
|
|
|
669
|
|
|
$policies2 = [ |
670
|
|
|
'custom_module2' => [ |
671
|
|
|
'custom_function_3' => null, |
672
|
|
|
'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'], |
673
|
|
|
], |
674
|
|
|
'helloworld' => [ |
675
|
|
|
'foo' => ['additional_limitation'], |
676
|
|
|
'some' => ['thingy', 'thing', 'but', 'wait'], |
677
|
|
|
], |
678
|
|
|
]; |
679
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies2)); |
680
|
|
|
|
681
|
|
|
$expectedPolicies = [ |
682
|
|
|
'custom_module' => [ |
683
|
|
|
'custom_function_1' => [], |
684
|
|
|
'custom_function_2' => ['CustomLimitation' => true], |
685
|
|
|
], |
686
|
|
|
'helloworld' => [ |
687
|
|
|
'foo' => ['bar' => true, 'additional_limitation' => true], |
688
|
|
|
'baz' => [], |
689
|
|
|
'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true], |
690
|
|
|
], |
691
|
|
|
'custom_module2' => [ |
692
|
|
|
'custom_function_3' => [], |
693
|
|
|
'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true], |
694
|
|
|
], |
695
|
|
|
]; |
696
|
|
|
|
697
|
|
|
$this->load(); |
698
|
|
|
|
699
|
|
|
self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map'); |
700
|
|
|
self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map')); |
701
|
|
|
} |
702
|
|
|
} |
703
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.