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', 'metadata'], |
320
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
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', 'metadata'], |
337
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
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
|
|
|
/** |
355
|
|
|
* @dataProvider repositoriesConfigurationFieldGroupsProvider |
356
|
|
|
*/ |
357
|
|
|
public function testRepositoriesConfigurationFieldGroups($repositories, $expectedRepositories) |
358
|
|
|
{ |
359
|
|
|
$this->load(['repositories' => $repositories]); |
360
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
361
|
|
|
|
362
|
|
|
$repositoriesPar = $this->container->getParameter('ezpublish.repositories'); |
363
|
|
|
$this->assertEquals(count($repositories), count($repositoriesPar)); |
364
|
|
|
|
365
|
|
|
foreach ($repositoriesPar as $key => $repo) { |
366
|
|
|
$this->assertArrayHasKey($key, $expectedRepositories); |
367
|
|
|
$this->assertArrayHasKey('fields_groups', $repo); |
368
|
|
|
$this->assertEquals($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element', 0.0, 10, true); |
369
|
|
|
} |
370
|
|
|
} |
371
|
|
|
|
372
|
|
|
public function repositoriesConfigurationFieldGroupsProvider() |
373
|
|
|
{ |
374
|
|
|
return [ |
375
|
|
|
//empty config |
376
|
|
|
[ |
377
|
|
|
['main' => null], |
378
|
|
|
['main' => [ |
379
|
|
|
'fields_groups' => [ |
380
|
|
|
'list' => ['content', 'metadata'], |
381
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
382
|
|
|
], |
383
|
|
|
], |
384
|
|
|
], |
385
|
|
|
], |
386
|
|
|
//single item with custom fields |
387
|
|
|
[ |
388
|
|
|
['foo' => [ |
389
|
|
|
'fields_groups' => [ |
390
|
|
|
'list' => ['bar', 'baz', 'john'], |
391
|
|
|
'default' => 'bar', |
392
|
|
|
], |
393
|
|
|
], |
394
|
|
|
], |
395
|
|
|
['foo' => [ |
396
|
|
|
'fields_groups' => [ |
397
|
|
|
'list' => ['bar', 'baz', 'john'], |
398
|
|
|
'default' => 'bar', |
399
|
|
|
], |
400
|
|
|
], |
401
|
|
|
], |
402
|
|
|
], |
403
|
|
|
//mixed item with custom config and empty item |
404
|
|
|
[ |
405
|
|
|
[ |
406
|
|
|
'foo' => [ |
407
|
|
|
'fields_groups' => [ |
408
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
409
|
|
|
'default' => 'bar', |
410
|
|
|
], |
411
|
|
|
], |
412
|
|
|
'anotherone' => null, |
413
|
|
|
], |
414
|
|
|
[ |
415
|
|
|
'foo' => [ |
416
|
|
|
'fields_groups' => [ |
417
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
418
|
|
|
'default' => 'bar', |
419
|
|
|
], |
420
|
|
|
], |
421
|
|
|
'anotherone' => [ |
422
|
|
|
'fields_groups' => [ |
423
|
|
|
'list' => ['content', 'metadata'], |
424
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
425
|
|
|
], |
426
|
|
|
], |
427
|
|
|
], |
428
|
|
|
], |
429
|
|
|
//items with only one field configured |
430
|
|
|
[ |
431
|
|
|
[ |
432
|
|
|
'foo' => [ |
433
|
|
|
'fields_groups' => [ |
434
|
|
|
'list' => ['bar', 'baz', 'john'], |
435
|
|
|
], |
436
|
|
|
], |
437
|
|
|
'bar' => [ |
438
|
|
|
'fields_groups' => [ |
439
|
|
|
'default' => 'metadata', |
440
|
|
|
], |
441
|
|
|
], |
442
|
|
|
], |
443
|
|
|
[ |
444
|
|
|
'foo' => [ |
445
|
|
|
'fields_groups' => [ |
446
|
|
|
'list' => ['bar', 'baz', 'john'], |
447
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
448
|
|
|
], |
449
|
|
|
], |
450
|
|
|
'bar' => [ |
451
|
|
|
'fields_groups' => [ |
452
|
|
|
'list' => ['content', 'metadata'], |
453
|
|
|
'default' => 'metadata', |
454
|
|
|
], |
455
|
|
|
], |
456
|
|
|
], |
457
|
|
|
], |
458
|
|
|
//two different repositories |
459
|
|
|
[ |
460
|
|
|
[ |
461
|
|
|
'foo' => [ |
462
|
|
|
'fields_groups' => [ |
463
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
464
|
|
|
'default' => 'bar', |
465
|
|
|
], |
466
|
|
|
], |
467
|
|
|
'bar' => [ |
468
|
|
|
'fields_groups' => [ |
469
|
|
|
'list' => ['lorem', 'ipsum'], |
470
|
|
|
'default' => 'lorem', |
471
|
|
|
], |
472
|
|
|
], |
473
|
|
|
], |
474
|
|
|
[ |
475
|
|
|
'foo' => [ |
476
|
|
|
'fields_groups' => [ |
477
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
478
|
|
|
'default' => 'bar', |
479
|
|
|
], |
480
|
|
|
], |
481
|
|
|
'bar' => [ |
482
|
|
|
'fields_groups' => [ |
483
|
|
|
'list' => ['lorem', 'ipsum'], |
484
|
|
|
'default' => 'lorem', |
485
|
|
|
], |
486
|
|
|
], |
487
|
|
|
], |
488
|
|
|
], |
489
|
|
|
]; |
490
|
|
|
} |
491
|
|
|
|
492
|
|
|
public function testRepositoriesConfigurationEmpty() |
493
|
|
|
{ |
494
|
|
|
$repositories = array( |
495
|
|
|
'main' => null, |
496
|
|
|
); |
497
|
|
|
$expectedRepositories = array( |
498
|
|
|
'main' => array( |
499
|
|
|
'storage' => array( |
500
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
501
|
|
|
'connection' => null, |
502
|
|
|
'config' => array(), |
503
|
|
|
), |
504
|
|
|
'search' => array( |
505
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
506
|
|
|
'connection' => null, |
507
|
|
|
'config' => array(), |
508
|
|
|
), |
509
|
|
|
'fields_groups' => array( |
510
|
|
|
'list' => ['content', 'metadata'], |
511
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
512
|
|
|
), |
513
|
|
|
'options' => [ |
514
|
|
|
'default_version_archive_limit' => 5, |
515
|
|
|
], |
516
|
|
|
), |
517
|
|
|
); |
518
|
|
|
$this->load(array('repositories' => $repositories)); |
519
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
520
|
|
|
|
521
|
|
|
$this->assertSame( |
522
|
|
|
$expectedRepositories, |
523
|
|
|
$this->container->getParameter('ezpublish.repositories') |
524
|
|
|
); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
View Code Duplication |
public function testRepositoriesConfigurationStorageEmpty() |
528
|
|
|
{ |
529
|
|
|
$repositories = array( |
530
|
|
|
'main' => array( |
531
|
|
|
'search' => array( |
532
|
|
|
'engine' => 'fantasticfind', |
533
|
|
|
'connection' => 'french', |
534
|
|
|
), |
535
|
|
|
), |
536
|
|
|
); |
537
|
|
|
$expectedRepositories = array( |
538
|
|
|
'main' => array( |
539
|
|
|
'search' => array( |
540
|
|
|
'engine' => 'fantasticfind', |
541
|
|
|
'connection' => 'french', |
542
|
|
|
'config' => array(), |
543
|
|
|
), |
544
|
|
|
'storage' => array( |
545
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
546
|
|
|
'connection' => null, |
547
|
|
|
'config' => array(), |
548
|
|
|
), |
549
|
|
|
'fields_groups' => array( |
550
|
|
|
'list' => ['content', 'metadata'], |
551
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
552
|
|
|
), |
553
|
|
|
'options' => [ |
554
|
|
|
'default_version_archive_limit' => 5, |
555
|
|
|
], |
556
|
|
|
), |
557
|
|
|
); |
558
|
|
|
$this->load(array('repositories' => $repositories)); |
559
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
560
|
|
|
|
561
|
|
|
$this->assertSame( |
562
|
|
|
$expectedRepositories, |
563
|
|
|
$this->container->getParameter('ezpublish.repositories') |
564
|
|
|
); |
565
|
|
|
} |
566
|
|
|
|
567
|
|
View Code Duplication |
public function testRepositoriesConfigurationSearchEmpty() |
568
|
|
|
{ |
569
|
|
|
$repositories = array( |
570
|
|
|
'main' => array( |
571
|
|
|
'storage' => array( |
572
|
|
|
'engine' => 'persistentprudence', |
573
|
|
|
'connection' => 'yes', |
574
|
|
|
), |
575
|
|
|
), |
576
|
|
|
); |
577
|
|
|
$expectedRepositories = array( |
578
|
|
|
'main' => array( |
579
|
|
|
'storage' => array( |
580
|
|
|
'engine' => 'persistentprudence', |
581
|
|
|
'connection' => 'yes', |
582
|
|
|
'config' => array(), |
583
|
|
|
), |
584
|
|
|
'search' => array( |
585
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
586
|
|
|
'connection' => null, |
587
|
|
|
'config' => array(), |
588
|
|
|
), |
589
|
|
|
'fields_groups' => array( |
590
|
|
|
'list' => ['content', 'metadata'], |
591
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
592
|
|
|
), |
593
|
|
|
'options' => [ |
594
|
|
|
'default_version_archive_limit' => 5, |
595
|
|
|
], |
596
|
|
|
), |
597
|
|
|
); |
598
|
|
|
$this->load(array('repositories' => $repositories)); |
599
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
600
|
|
|
|
601
|
|
|
$this->assertSame( |
602
|
|
|
$expectedRepositories, |
603
|
|
|
$this->container->getParameter('ezpublish.repositories') |
604
|
|
|
); |
605
|
|
|
} |
606
|
|
|
|
607
|
|
|
public function testRepositoriesConfigurationCompatibility() |
608
|
|
|
{ |
609
|
|
|
$repositories = array( |
610
|
|
|
'main' => array( |
611
|
|
|
'engine' => 'legacy', |
612
|
|
|
'connection' => 'default', |
613
|
|
|
'search' => array( |
614
|
|
|
'engine' => 'elasticsearch', |
615
|
|
|
'connection' => 'blabla', |
616
|
|
|
), |
617
|
|
|
), |
618
|
|
|
'foo' => array( |
619
|
|
|
'engine' => 'sqlng', |
620
|
|
|
'connection' => 'default', |
621
|
|
|
'search' => array( |
622
|
|
|
'engine' => 'solr', |
623
|
|
|
'connection' => 'lalala', |
624
|
|
|
), |
625
|
|
|
), |
626
|
|
|
); |
627
|
|
|
$expectedRepositories = array( |
628
|
|
|
'main' => array( |
629
|
|
|
'search' => array( |
630
|
|
|
'engine' => 'elasticsearch', |
631
|
|
|
'connection' => 'blabla', |
632
|
|
|
'config' => array(), |
633
|
|
|
), |
634
|
|
|
'storage' => array( |
635
|
|
|
'engine' => 'legacy', |
636
|
|
|
'connection' => 'default', |
637
|
|
|
'config' => array(), |
638
|
|
|
), |
639
|
|
|
'fields_groups' => array( |
640
|
|
|
'list' => ['content', 'metadata'], |
641
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
642
|
|
|
), |
643
|
|
|
'options' => [ |
644
|
|
|
'default_version_archive_limit' => 5, |
645
|
|
|
], |
646
|
|
|
), |
647
|
|
|
'foo' => array( |
648
|
|
|
'search' => array( |
649
|
|
|
'engine' => 'solr', |
650
|
|
|
'connection' => 'lalala', |
651
|
|
|
'config' => array(), |
652
|
|
|
), |
653
|
|
|
'storage' => array( |
654
|
|
|
'engine' => 'sqlng', |
655
|
|
|
'connection' => 'default', |
656
|
|
|
'config' => array(), |
657
|
|
|
), |
658
|
|
|
'fields_groups' => array( |
659
|
|
|
'list' => ['content', 'metadata'], |
660
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
661
|
|
|
), |
662
|
|
|
'options' => [ |
663
|
|
|
'default_version_archive_limit' => 5, |
664
|
|
|
], |
665
|
|
|
), |
666
|
|
|
); |
667
|
|
|
$this->load(array('repositories' => $repositories)); |
668
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
669
|
|
|
|
670
|
|
|
$this->assertSame( |
671
|
|
|
$expectedRepositories, |
672
|
|
|
$this->container->getParameter('ezpublish.repositories') |
673
|
|
|
); |
674
|
|
|
} |
675
|
|
|
|
676
|
|
View Code Duplication |
public function testRepositoriesConfigurationCompatibility2() |
677
|
|
|
{ |
678
|
|
|
$repositories = array( |
679
|
|
|
'main' => array( |
680
|
|
|
'engine' => 'legacy', |
681
|
|
|
'connection' => 'default', |
682
|
|
|
), |
683
|
|
|
); |
684
|
|
|
$expectedRepositories = array( |
685
|
|
|
'main' => array( |
686
|
|
|
'storage' => array( |
687
|
|
|
'engine' => 'legacy', |
688
|
|
|
'connection' => 'default', |
689
|
|
|
'config' => array(), |
690
|
|
|
), |
691
|
|
|
'search' => array( |
692
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
693
|
|
|
'connection' => null, |
694
|
|
|
'config' => array(), |
695
|
|
|
), |
696
|
|
|
'fields_groups' => array( |
697
|
|
|
'list' => ['content', 'metadata'], |
698
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
699
|
|
|
), |
700
|
|
|
'options' => [ |
701
|
|
|
'default_version_archive_limit' => 5, |
702
|
|
|
], |
703
|
|
|
), |
704
|
|
|
); |
705
|
|
|
$this->load(array('repositories' => $repositories)); |
706
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
707
|
|
|
|
708
|
|
|
$this->assertSame( |
709
|
|
|
$expectedRepositories, |
710
|
|
|
$this->container->getParameter('ezpublish.repositories') |
711
|
|
|
); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
public function testRelatedSiteAccesses() |
715
|
|
|
{ |
716
|
|
|
$mainRepo = 'main'; |
717
|
|
|
$fooRepo = 'foo'; |
718
|
|
|
$rootLocationId1 = 123; |
719
|
|
|
$rootLocationId2 = 456; |
720
|
|
|
$rootLocationId3 = 2; |
721
|
|
|
$config = array( |
722
|
|
|
'siteaccess' => array( |
723
|
|
|
'default_siteaccess' => 'ezdemo_site', |
724
|
|
|
'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site2', 'eng2', 'ezdemo_site3', 'fre3'), |
725
|
|
|
'groups' => array( |
726
|
|
|
'ezdemo_group' => array('ezdemo_site', 'eng', 'fre'), |
727
|
|
|
'ezdemo_group2' => array('ezdemo_site2', 'eng2'), |
728
|
|
|
'ezdemo_group3' => array('ezdemo_site3', 'fre3'), |
729
|
|
|
), |
730
|
|
|
'match' => array(), |
731
|
|
|
), |
732
|
|
|
'repositories' => array( |
733
|
|
|
$mainRepo => array('engine' => 'legacy', 'connection' => 'default'), |
734
|
|
|
$fooRepo => array('engine' => 'bar', 'connection' => 'blabla'), |
735
|
|
|
), |
736
|
|
|
'system' => array( |
737
|
|
|
'ezdemo_group' => array( |
738
|
|
|
'repository' => $mainRepo, |
739
|
|
|
'content' => array( |
740
|
|
|
'tree_root' => array('location_id' => $rootLocationId1), |
741
|
|
|
), |
742
|
|
|
), |
743
|
|
|
'ezdemo_group2' => array( |
744
|
|
|
'repository' => $mainRepo, |
745
|
|
|
'content' => array( |
746
|
|
|
'tree_root' => array('location_id' => $rootLocationId2), |
747
|
|
|
), |
748
|
|
|
), |
749
|
|
|
'ezdemo_group3' => array( |
750
|
|
|
'repository' => $fooRepo, |
751
|
|
|
), |
752
|
|
|
), |
753
|
|
|
) + $this->siteaccessConfig; |
754
|
|
|
|
755
|
|
|
// Injecting needed config parsers. |
756
|
|
|
$refExtension = new ReflectionObject($this->extension); |
757
|
|
|
$refMethod = $refExtension->getMethod('getMainConfigParser'); |
758
|
|
|
$refMethod->setAccessible(true); |
759
|
|
|
$refMethod->invoke($this->extension); |
760
|
|
|
$refParser = $refExtension->getProperty('mainConfigParser'); |
761
|
|
|
$refParser->setAccessible(true); |
762
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */ |
763
|
|
|
$parser = $refParser->getValue($this->extension); |
764
|
|
|
$parser->setConfigParsers(array(new Common(), new Content())); |
765
|
|
|
|
766
|
|
|
$this->load($config); |
767
|
|
|
|
768
|
|
|
$relatedSiteAccesses1 = array('ezdemo_site', 'eng', 'fre'); |
769
|
|
|
$relatedSiteAccesses2 = array('ezdemo_site2', 'eng2'); |
770
|
|
|
$relatedSiteAccesses3 = array('ezdemo_site3', 'fre3'); |
771
|
|
|
$expectedRelationMap = array( |
772
|
|
|
$mainRepo => array( |
773
|
|
|
$rootLocationId1 => $relatedSiteAccesses1, |
774
|
|
|
$rootLocationId2 => $relatedSiteAccesses2, |
775
|
|
|
), |
776
|
|
|
$fooRepo => array( |
777
|
|
|
$rootLocationId3 => $relatedSiteAccesses3, |
778
|
|
|
), |
779
|
|
|
); |
780
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.relation_map', $expectedRelationMap); |
781
|
|
|
|
782
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses1); |
783
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses1); |
784
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses1); |
785
|
|
|
|
786
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site2.related_siteaccesses', $relatedSiteAccesses2); |
787
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng2.related_siteaccesses', $relatedSiteAccesses2); |
788
|
|
|
|
789
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site3.related_siteaccesses', $relatedSiteAccesses3); |
790
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre3.related_siteaccesses', $relatedSiteAccesses3); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
public function testRegisteredPolicies() |
794
|
|
|
{ |
795
|
|
|
$policies1 = [ |
796
|
|
|
'custom_module' => [ |
797
|
|
|
'custom_function_1' => null, |
798
|
|
|
'custom_function_2' => ['CustomLimitation'], |
799
|
|
|
], |
800
|
|
|
'helloworld' => [ |
801
|
|
|
'foo' => ['bar'], |
802
|
|
|
'baz' => null, |
803
|
|
|
], |
804
|
|
|
]; |
805
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies1)); |
806
|
|
|
|
807
|
|
|
$policies2 = [ |
808
|
|
|
'custom_module2' => [ |
809
|
|
|
'custom_function_3' => null, |
810
|
|
|
'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'], |
811
|
|
|
], |
812
|
|
|
'helloworld' => [ |
813
|
|
|
'foo' => ['additional_limitation'], |
814
|
|
|
'some' => ['thingy', 'thing', 'but', 'wait'], |
815
|
|
|
], |
816
|
|
|
]; |
817
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies2)); |
818
|
|
|
|
819
|
|
|
$expectedPolicies = [ |
820
|
|
|
'custom_module' => [ |
821
|
|
|
'custom_function_1' => [], |
822
|
|
|
'custom_function_2' => ['CustomLimitation' => true], |
823
|
|
|
], |
824
|
|
|
'helloworld' => [ |
825
|
|
|
'foo' => ['bar' => true, 'additional_limitation' => true], |
826
|
|
|
'baz' => [], |
827
|
|
|
'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true], |
828
|
|
|
], |
829
|
|
|
'custom_module2' => [ |
830
|
|
|
'custom_function_3' => [], |
831
|
|
|
'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true], |
832
|
|
|
], |
833
|
|
|
]; |
834
|
|
|
|
835
|
|
|
$this->load(); |
836
|
|
|
|
837
|
|
|
self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map'); |
838
|
|
|
self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map')); |
839
|
|
|
} |
840
|
|
|
} |
841
|
|
|
|
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.