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 = []; |
23
|
|
|
|
24
|
|
|
private $siteaccessConfig = []; |
25
|
|
|
|
26
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension */ |
27
|
|
|
private $extension; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Cached RichText default settings. |
31
|
|
|
* |
32
|
|
|
* @var array |
33
|
|
|
*/ |
34
|
|
|
private static $richTextDefaultSettings; |
35
|
|
|
|
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->extension = new EzPublishCoreExtension(); |
39
|
|
|
$this->siteaccessConfig = [ |
40
|
|
|
'siteaccess' => [ |
41
|
|
|
'default_siteaccess' => 'ezdemo_site', |
42
|
|
|
'list' => ['ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'], |
43
|
|
|
'groups' => [ |
44
|
|
|
'ezdemo_group' => ['ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'], |
45
|
|
|
'ezdemo_frontend_group' => ['ezdemo_site', 'eng', 'fre'], |
46
|
|
|
], |
47
|
|
|
'match' => [ |
48
|
|
|
'URILElement' => 1, |
49
|
|
|
'Map\URI' => ['the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin'], |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
'system' => [ |
53
|
|
|
'ezdemo_site' => [], |
54
|
|
|
'eng' => [], |
55
|
|
|
'fre' => [], |
56
|
|
|
'ezdemo_site_admin' => [], |
57
|
|
|
], |
58
|
|
|
]; |
59
|
|
|
|
60
|
|
|
parent::setUp(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
protected function getContainerExtensions() |
64
|
|
|
{ |
65
|
|
|
return [$this->extension]; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
protected function getMinimalConfiguration() |
69
|
|
|
{ |
70
|
|
|
return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml')); |
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public function testSiteAccessConfiguration() |
74
|
|
|
{ |
75
|
|
|
// Injecting needed config parsers. |
76
|
|
|
$refExtension = new ReflectionObject($this->extension); |
77
|
|
|
$refMethod = $refExtension->getMethod('getMainConfigParser'); |
78
|
|
|
$refMethod->setAccessible(true); |
79
|
|
|
$refMethod->invoke($this->extension); |
80
|
|
|
$refParser = $refExtension->getProperty('mainConfigParser'); |
81
|
|
|
$refParser->setAccessible(true); |
82
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */ |
83
|
|
|
$parser = $refParser->getValue($this->extension); |
84
|
|
|
$parser->setConfigParsers([new Common(), new Content()]); |
85
|
|
|
|
86
|
|
|
$this->load($this->siteaccessConfig); |
87
|
|
|
$this->assertContainerBuilderHasParameter( |
88
|
|
|
'ezpublish.siteaccess.list', |
89
|
|
|
$this->siteaccessConfig['siteaccess']['list'] |
90
|
|
|
); |
91
|
|
|
$this->assertContainerBuilderHasParameter( |
92
|
|
|
'ezpublish.siteaccess.default', |
93
|
|
|
$this->siteaccessConfig['siteaccess']['default_siteaccess'] |
94
|
|
|
); |
95
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', $this->siteaccessConfig['siteaccess']['groups']); |
96
|
|
|
|
97
|
|
|
$expectedMatchingConfig = []; |
98
|
|
|
foreach ($this->siteaccessConfig['siteaccess']['match'] as $key => $val) { |
99
|
|
|
// Value is expected to always be an array (transformed by semantic configuration parser). |
100
|
|
|
$expectedMatchingConfig[$key] = is_array($val) ? $val : ['value' => $val]; |
101
|
|
|
} |
102
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', $expectedMatchingConfig); |
103
|
|
|
|
104
|
|
|
$groupsBySiteaccess = []; |
105
|
|
View Code Duplication |
foreach ($this->siteaccessConfig['siteaccess']['groups'] as $groupName => $groupMembers) { |
|
|
|
|
106
|
|
|
foreach ($groupMembers as $member) { |
107
|
|
|
if (!isset($groupsBySiteaccess[$member])) { |
108
|
|
|
$groupsBySiteaccess[$member] = []; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
$groupsBySiteaccess[$member][] = $groupName; |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess); |
115
|
|
|
|
116
|
|
|
$relatedSiteAccesses = ['ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin']; |
117
|
|
|
$this->assertContainerBuilderHasParameter( |
118
|
|
|
'ezpublish.siteaccess.relation_map', |
119
|
|
|
[ |
120
|
|
|
// Empty string is the default repository name |
121
|
|
|
'' => [ |
122
|
|
|
// 2 is the default rootLocationId |
123
|
|
|
2 => $relatedSiteAccesses, |
124
|
|
|
], |
125
|
|
|
] |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses); |
129
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses); |
130
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testSiteAccessNoConfiguration() |
134
|
|
|
{ |
135
|
|
|
$this->load(); |
136
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.list', ['setup']); |
137
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.default', 'setup'); |
138
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', []); |
139
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', []); |
140
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', null); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
public function testLoadWithoutRichTextPackage() |
144
|
|
|
{ |
145
|
|
|
$this->load(); |
146
|
|
|
|
147
|
|
|
$expectedParameters = $this->loadRichTextDefaultSettings()['parameters']; |
148
|
|
|
foreach ($expectedParameters as $parameterName => $parameterValue) { |
149
|
|
|
$this->assertContainerBuilderHasParameter($parameterName, $parameterValue); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
$this->assertContainerBuilderHasServiceDefinitionWithTag( |
153
|
|
|
'ezpublish.fieldType.ezrichtext', |
154
|
|
|
'ezpublish.fieldType', |
155
|
|
|
['alias' => 'ezrichtext'] |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
$this->testRichTextConfiguration(); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function testLoadWithRichTextPackage() |
162
|
|
|
{ |
163
|
|
|
// mock existence of RichText package |
164
|
|
|
$this->container->setParameter('kernel.bundles', ['EzPlatformRichTextBundle' => null]); |
165
|
|
|
|
166
|
|
|
$this->load(); |
167
|
|
|
|
168
|
|
|
$unexpectedParameters = $this->loadRichTextDefaultSettings()['parameters']; |
169
|
|
|
foreach ($unexpectedParameters as $parameterName => $parameterValue) { |
170
|
|
|
self::assertFalse( |
171
|
|
|
$this->container->hasParameter($parameterName), |
172
|
|
|
"Container has '{$parameterName}' parameter" |
173
|
|
|
); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$this->assertContainerBuilderNotHasService('ezpublish.fieldType.ezrichtext'); |
177
|
|
|
|
178
|
|
|
$this->testRichTextConfiguration(); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function testImageMagickConfigurationBasic() |
182
|
|
|
{ |
183
|
|
View Code Duplication |
if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { |
|
|
|
|
184
|
|
|
$this->markTestSkipped('Missing or mis-configured Imagemagick convert path.'); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$this->load( |
188
|
|
|
[ |
189
|
|
|
'imagemagick' => [ |
190
|
|
|
'enabled' => true, |
191
|
|
|
'path' => $_ENV['imagemagickConvertPath'], |
192
|
|
|
], |
193
|
|
|
] |
194
|
|
|
); |
195
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.enabled', true); |
196
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable_path', dirname($_ENV['imagemagickConvertPath'])); |
197
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable', basename($_ENV['imagemagickConvertPath'])); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function testImageMagickConfigurationFilters() |
201
|
|
|
{ |
202
|
|
View Code Duplication |
if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) { |
|
|
|
|
203
|
|
|
$this->markTestSkipped('Missing or mis-configured Imagemagick convert path.'); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
$customFilters = [ |
207
|
|
|
'foobar' => '-foobar', |
208
|
|
|
'wow' => '-amazing', |
209
|
|
|
]; |
210
|
|
|
$this->load( |
211
|
|
|
[ |
212
|
|
|
'imagemagick' => [ |
213
|
|
|
'enabled' => true, |
214
|
|
|
'path' => $_ENV['imagemagickConvertPath'], |
215
|
|
|
'filters' => $customFilters, |
216
|
|
|
], |
217
|
|
|
] |
218
|
|
|
); |
219
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.image.imagemagick.filters')); |
220
|
|
|
$filters = $this->container->getParameter('ezpublish.image.imagemagick.filters'); |
221
|
|
|
$this->assertArrayHasKey('foobar', $filters); |
222
|
|
|
$this->assertSame($customFilters['foobar'], $filters['foobar']); |
223
|
|
|
$this->assertArrayHasKey('wow', $filters); |
224
|
|
|
$this->assertSame($customFilters['wow'], $filters['wow']); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public function testImagePlaceholderConfiguration() |
228
|
|
|
{ |
229
|
|
|
$this->load([ |
230
|
|
|
'image_placeholder' => [ |
231
|
|
|
'default' => [ |
232
|
|
|
'provider' => 'generic', |
233
|
|
|
'options' => [ |
234
|
|
|
'foo' => 'Foo', |
235
|
|
|
'bar' => 'Bar', |
236
|
|
|
], |
237
|
|
|
], |
238
|
|
|
'fancy' => [ |
239
|
|
|
'provider' => 'remote', |
240
|
|
|
], |
241
|
|
|
], |
242
|
|
|
]); |
243
|
|
|
|
244
|
|
|
$this->assertEquals([ |
245
|
|
|
'default' => [ |
246
|
|
|
'provider' => 'generic', |
247
|
|
|
'options' => [ |
248
|
|
|
'foo' => 'Foo', |
249
|
|
|
'bar' => 'Bar', |
250
|
|
|
], |
251
|
|
|
], |
252
|
|
|
'fancy' => [ |
253
|
|
|
'provider' => 'remote', |
254
|
|
|
'options' => [], |
255
|
|
|
], |
256
|
|
|
], $this->container->getParameter('image_alias.placeholder_providers')); |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public function testEzPageConfiguration() |
260
|
|
|
{ |
261
|
|
|
$customLayouts = [ |
262
|
|
|
'FoobarLayout' => ['name' => 'Foo layout', 'template' => 'foolayout.html.twig'], |
263
|
|
|
]; |
264
|
|
|
$enabledLayouts = ['FoobarLayout', 'GlobalZoneLayout']; |
265
|
|
|
$customBlocks = [ |
266
|
|
|
'FoobarBlock' => ['name' => 'Foo block'], |
267
|
|
|
]; |
268
|
|
|
$enabledBlocks = ['FoobarBlock', 'DemoBlock']; |
269
|
|
|
$this->load( |
270
|
|
|
[ |
271
|
|
|
'ezpage' => [ |
272
|
|
|
'layouts' => $customLayouts, |
273
|
|
|
'blocks' => $customBlocks, |
274
|
|
|
'enabledLayouts' => $enabledLayouts, |
275
|
|
|
'enabledBlocks' => $enabledBlocks, |
276
|
|
|
], |
277
|
|
|
] |
278
|
|
|
); |
279
|
|
|
|
280
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.ezpage.layouts')); |
281
|
|
|
$layouts = $this->container->getParameter('ezpublish.ezpage.layouts'); |
282
|
|
|
$this->assertArrayHasKey('FoobarLayout', $layouts); |
283
|
|
|
$this->assertSame($customLayouts['FoobarLayout'], $layouts['FoobarLayout']); |
284
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledLayouts', $enabledLayouts); |
285
|
|
|
|
286
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.ezpage.blocks')); |
287
|
|
|
$blocks = $this->container->getParameter('ezpublish.ezpage.blocks'); |
288
|
|
|
$this->assertArrayHasKey('FoobarBlock', $blocks); |
289
|
|
|
$this->assertSame($customBlocks['FoobarBlock'], $blocks['FoobarBlock']); |
290
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledBlocks', $enabledBlocks); |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
public function testRoutingConfiguration() |
294
|
|
|
{ |
295
|
|
|
$this->load(); |
296
|
|
|
$this->assertContainerBuilderHasAlias('router', 'ezpublish.chain_router'); |
297
|
|
|
|
298
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.default_router.non_siteaccess_aware_routes')); |
299
|
|
|
$nonSiteaccessAwareRoutes = $this->container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes'); |
300
|
|
|
// See ezpublish_minimal_no_siteaccess.yml fixture |
301
|
|
|
$this->assertContains('foo_route', $nonSiteaccessAwareRoutes); |
302
|
|
|
$this->assertContains('my_prefix_', $nonSiteaccessAwareRoutes); |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
/** |
306
|
|
|
* @dataProvider cacheConfigurationProvider |
307
|
|
|
* |
308
|
|
|
* @param array $customCacheConfig |
309
|
|
|
* @param string $expectedPurgeType |
310
|
|
|
*/ |
311
|
|
|
public function testCacheConfiguration(array $customCacheConfig, $expectedPurgeType) |
312
|
|
|
{ |
313
|
|
|
$this->load($customCacheConfig); |
314
|
|
|
|
315
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', $expectedPurgeType); |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
public function cacheConfigurationProvider() |
319
|
|
|
{ |
320
|
|
|
return [ |
321
|
|
|
[[], 'local'], |
322
|
|
|
[ |
323
|
|
|
[ |
324
|
|
|
'http_cache' => ['purge_type' => 'local'], |
325
|
|
|
], |
326
|
|
|
'local', |
327
|
|
|
], |
328
|
|
|
[ |
329
|
|
|
[ |
330
|
|
|
'http_cache' => ['purge_type' => 'multiple_http'], |
331
|
|
|
], |
332
|
|
|
'http', |
333
|
|
|
], |
334
|
|
|
[ |
335
|
|
|
[ |
336
|
|
|
'http_cache' => ['purge_type' => 'single_http'], |
337
|
|
|
], |
338
|
|
|
'http', |
339
|
|
|
], |
340
|
|
|
[ |
341
|
|
|
[ |
342
|
|
|
'http_cache' => ['purge_type' => 'http'], |
343
|
|
|
], |
344
|
|
|
'http', |
345
|
|
|
], |
346
|
|
|
]; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
public function testCacheConfigurationCustomPurgeService() |
350
|
|
|
{ |
351
|
|
|
$serviceId = 'foobar'; |
352
|
|
|
$this->setDefinition($serviceId, new Definition()); |
353
|
|
|
$this->load( |
354
|
|
|
[ |
355
|
|
|
'http_cache' => ['purge_type' => 'foobar', 'timeout' => 12], |
356
|
|
|
] |
357
|
|
|
); |
358
|
|
|
|
359
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', 'foobar'); |
360
|
|
|
} |
361
|
|
|
|
362
|
|
|
public function testLocaleConfiguration() |
363
|
|
|
{ |
364
|
|
|
$this->load(['locale_conversion' => ['foo' => 'bar']]); |
365
|
|
|
$conversionMap = $this->container->getParameter('ezpublish.locale.conversion_map'); |
366
|
|
|
$this->assertArrayHasKey('foo', $conversionMap); |
367
|
|
|
$this->assertSame('bar', $conversionMap['foo']); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
public function testRepositoriesConfiguration() |
371
|
|
|
{ |
372
|
|
|
$repositories = [ |
373
|
|
|
'main' => [ |
374
|
|
|
'storage' => [ |
375
|
|
|
'engine' => 'legacy', |
376
|
|
|
'connection' => 'default', |
377
|
|
|
], |
378
|
|
|
'search' => [ |
379
|
|
|
'engine' => 'elasticsearch', |
380
|
|
|
'connection' => 'blabla', |
381
|
|
|
], |
382
|
|
|
'fields_groups' => [ |
383
|
|
|
'list' => ['content', 'metadata'], |
384
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
385
|
|
|
], |
386
|
|
|
'options' => [ |
387
|
|
|
'default_version_archive_limit' => 5, |
388
|
|
|
], |
389
|
|
|
], |
390
|
|
|
'foo' => [ |
391
|
|
|
'storage' => [ |
392
|
|
|
'engine' => 'sqlng', |
393
|
|
|
'connection' => 'default', |
394
|
|
|
], |
395
|
|
|
'search' => [ |
396
|
|
|
'engine' => 'solr', |
397
|
|
|
'connection' => 'lalala', |
398
|
|
|
], |
399
|
|
|
'fields_groups' => [ |
400
|
|
|
'list' => ['content', 'metadata'], |
401
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
402
|
|
|
], |
403
|
|
|
'options' => [ |
404
|
|
|
'default_version_archive_limit' => 5, |
405
|
|
|
], |
406
|
|
|
], |
407
|
|
|
]; |
408
|
|
|
$this->load(['repositories' => $repositories]); |
409
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
410
|
|
|
|
411
|
|
|
foreach ($repositories as &$repositoryConfig) { |
412
|
|
|
$repositoryConfig['storage']['config'] = []; |
413
|
|
|
$repositoryConfig['search']['config'] = []; |
414
|
|
|
} |
415
|
|
|
$this->assertSame($repositories, $this->container->getParameter('ezpublish.repositories')); |
416
|
|
|
} |
417
|
|
|
|
418
|
|
|
/** |
419
|
|
|
* @dataProvider repositoriesConfigurationFieldGroupsProvider |
420
|
|
|
*/ |
421
|
|
|
public function testRepositoriesConfigurationFieldGroups($repositories, $expectedRepositories) |
422
|
|
|
{ |
423
|
|
|
$this->load(['repositories' => $repositories]); |
424
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
425
|
|
|
|
426
|
|
|
$repositoriesPar = $this->container->getParameter('ezpublish.repositories'); |
427
|
|
|
$this->assertEquals(count($repositories), count($repositoriesPar)); |
428
|
|
|
|
429
|
|
|
foreach ($repositoriesPar as $key => $repo) { |
430
|
|
|
$this->assertArrayHasKey($key, $expectedRepositories); |
431
|
|
|
$this->assertArrayHasKey('fields_groups', $repo); |
432
|
|
|
$this->assertEquals($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element', 0.0, 10, true); |
433
|
|
|
} |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
public function repositoriesConfigurationFieldGroupsProvider() |
437
|
|
|
{ |
438
|
|
|
return [ |
439
|
|
|
//empty config |
440
|
|
|
[ |
441
|
|
|
['main' => null], |
442
|
|
|
['main' => [ |
443
|
|
|
'fields_groups' => [ |
444
|
|
|
'list' => ['content', 'metadata'], |
445
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
446
|
|
|
], |
447
|
|
|
], |
448
|
|
|
], |
449
|
|
|
], |
450
|
|
|
//single item with custom fields |
451
|
|
|
[ |
452
|
|
|
['foo' => [ |
453
|
|
|
'fields_groups' => [ |
454
|
|
|
'list' => ['bar', 'baz', 'john'], |
455
|
|
|
'default' => 'bar', |
456
|
|
|
], |
457
|
|
|
], |
458
|
|
|
], |
459
|
|
|
['foo' => [ |
460
|
|
|
'fields_groups' => [ |
461
|
|
|
'list' => ['bar', 'baz', 'john'], |
462
|
|
|
'default' => 'bar', |
463
|
|
|
], |
464
|
|
|
], |
465
|
|
|
], |
466
|
|
|
], |
467
|
|
|
//mixed item with custom config and empty item |
468
|
|
|
[ |
469
|
|
|
[ |
470
|
|
|
'foo' => [ |
471
|
|
|
'fields_groups' => [ |
472
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
473
|
|
|
'default' => 'bar', |
474
|
|
|
], |
475
|
|
|
], |
476
|
|
|
'anotherone' => null, |
477
|
|
|
], |
478
|
|
|
[ |
479
|
|
|
'foo' => [ |
480
|
|
|
'fields_groups' => [ |
481
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
482
|
|
|
'default' => 'bar', |
483
|
|
|
], |
484
|
|
|
], |
485
|
|
|
'anotherone' => [ |
486
|
|
|
'fields_groups' => [ |
487
|
|
|
'list' => ['content', 'metadata'], |
488
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
489
|
|
|
], |
490
|
|
|
], |
491
|
|
|
], |
492
|
|
|
], |
493
|
|
|
//items with only one field configured |
494
|
|
|
[ |
495
|
|
|
[ |
496
|
|
|
'foo' => [ |
497
|
|
|
'fields_groups' => [ |
498
|
|
|
'list' => ['bar', 'baz', 'john'], |
499
|
|
|
], |
500
|
|
|
], |
501
|
|
|
'bar' => [ |
502
|
|
|
'fields_groups' => [ |
503
|
|
|
'default' => 'metadata', |
504
|
|
|
], |
505
|
|
|
], |
506
|
|
|
], |
507
|
|
|
[ |
508
|
|
|
'foo' => [ |
509
|
|
|
'fields_groups' => [ |
510
|
|
|
'list' => ['bar', 'baz', 'john'], |
511
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
512
|
|
|
], |
513
|
|
|
], |
514
|
|
|
'bar' => [ |
515
|
|
|
'fields_groups' => [ |
516
|
|
|
'list' => ['content', 'metadata'], |
517
|
|
|
'default' => 'metadata', |
518
|
|
|
], |
519
|
|
|
], |
520
|
|
|
], |
521
|
|
|
], |
522
|
|
|
//two different repositories |
523
|
|
|
[ |
524
|
|
|
[ |
525
|
|
|
'foo' => [ |
526
|
|
|
'fields_groups' => [ |
527
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
528
|
|
|
'default' => 'bar', |
529
|
|
|
], |
530
|
|
|
], |
531
|
|
|
'bar' => [ |
532
|
|
|
'fields_groups' => [ |
533
|
|
|
'list' => ['lorem', 'ipsum'], |
534
|
|
|
'default' => 'lorem', |
535
|
|
|
], |
536
|
|
|
], |
537
|
|
|
], |
538
|
|
|
[ |
539
|
|
|
'foo' => [ |
540
|
|
|
'fields_groups' => [ |
541
|
|
|
'list' => ['bar', 'baz', 'john', 'doe'], |
542
|
|
|
'default' => 'bar', |
543
|
|
|
], |
544
|
|
|
], |
545
|
|
|
'bar' => [ |
546
|
|
|
'fields_groups' => [ |
547
|
|
|
'list' => ['lorem', 'ipsum'], |
548
|
|
|
'default' => 'lorem', |
549
|
|
|
], |
550
|
|
|
], |
551
|
|
|
], |
552
|
|
|
], |
553
|
|
|
]; |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
public function testRepositoriesConfigurationEmpty() |
557
|
|
|
{ |
558
|
|
|
$repositories = [ |
559
|
|
|
'main' => null, |
560
|
|
|
]; |
561
|
|
|
$expectedRepositories = [ |
562
|
|
|
'main' => [ |
563
|
|
|
'storage' => [ |
564
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
565
|
|
|
'connection' => null, |
566
|
|
|
'config' => [], |
567
|
|
|
], |
568
|
|
|
'search' => [ |
569
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
570
|
|
|
'connection' => null, |
571
|
|
|
'config' => [], |
572
|
|
|
], |
573
|
|
|
'fields_groups' => [ |
574
|
|
|
'list' => ['content', 'metadata'], |
575
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
576
|
|
|
], |
577
|
|
|
'options' => [ |
578
|
|
|
'default_version_archive_limit' => 5, |
579
|
|
|
], |
580
|
|
|
], |
581
|
|
|
]; |
582
|
|
|
$this->load(['repositories' => $repositories]); |
583
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
584
|
|
|
|
585
|
|
|
$this->assertSame( |
586
|
|
|
$expectedRepositories, |
587
|
|
|
$this->container->getParameter('ezpublish.repositories') |
588
|
|
|
); |
589
|
|
|
} |
590
|
|
|
|
591
|
|
View Code Duplication |
public function testRepositoriesConfigurationStorageEmpty() |
592
|
|
|
{ |
593
|
|
|
$repositories = [ |
594
|
|
|
'main' => [ |
595
|
|
|
'search' => [ |
596
|
|
|
'engine' => 'fantasticfind', |
597
|
|
|
'connection' => 'french', |
598
|
|
|
], |
599
|
|
|
], |
600
|
|
|
]; |
601
|
|
|
$expectedRepositories = [ |
602
|
|
|
'main' => [ |
603
|
|
|
'search' => [ |
604
|
|
|
'engine' => 'fantasticfind', |
605
|
|
|
'connection' => 'french', |
606
|
|
|
'config' => [], |
607
|
|
|
], |
608
|
|
|
'storage' => [ |
609
|
|
|
'engine' => '%ezpublish.api.storage_engine.default%', |
610
|
|
|
'connection' => null, |
611
|
|
|
'config' => [], |
612
|
|
|
], |
613
|
|
|
'fields_groups' => [ |
614
|
|
|
'list' => ['content', 'metadata'], |
615
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
616
|
|
|
], |
617
|
|
|
'options' => [ |
618
|
|
|
'default_version_archive_limit' => 5, |
619
|
|
|
], |
620
|
|
|
], |
621
|
|
|
]; |
622
|
|
|
$this->load(['repositories' => $repositories]); |
623
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
624
|
|
|
|
625
|
|
|
$this->assertSame( |
626
|
|
|
$expectedRepositories, |
627
|
|
|
$this->container->getParameter('ezpublish.repositories') |
628
|
|
|
); |
629
|
|
|
} |
630
|
|
|
|
631
|
|
View Code Duplication |
public function testRepositoriesConfigurationSearchEmpty() |
632
|
|
|
{ |
633
|
|
|
$repositories = [ |
634
|
|
|
'main' => [ |
635
|
|
|
'storage' => [ |
636
|
|
|
'engine' => 'persistentprudence', |
637
|
|
|
'connection' => 'yes', |
638
|
|
|
], |
639
|
|
|
], |
640
|
|
|
]; |
641
|
|
|
$expectedRepositories = [ |
642
|
|
|
'main' => [ |
643
|
|
|
'storage' => [ |
644
|
|
|
'engine' => 'persistentprudence', |
645
|
|
|
'connection' => 'yes', |
646
|
|
|
'config' => [], |
647
|
|
|
], |
648
|
|
|
'search' => [ |
649
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
650
|
|
|
'connection' => null, |
651
|
|
|
'config' => [], |
652
|
|
|
], |
653
|
|
|
'fields_groups' => [ |
654
|
|
|
'list' => ['content', 'metadata'], |
655
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
656
|
|
|
], |
657
|
|
|
'options' => [ |
658
|
|
|
'default_version_archive_limit' => 5, |
659
|
|
|
], |
660
|
|
|
], |
661
|
|
|
]; |
662
|
|
|
$this->load(['repositories' => $repositories]); |
663
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
664
|
|
|
|
665
|
|
|
$this->assertSame( |
666
|
|
|
$expectedRepositories, |
667
|
|
|
$this->container->getParameter('ezpublish.repositories') |
668
|
|
|
); |
669
|
|
|
} |
670
|
|
|
|
671
|
|
|
public function testRepositoriesConfigurationCompatibility() |
672
|
|
|
{ |
673
|
|
|
$repositories = [ |
674
|
|
|
'main' => [ |
675
|
|
|
'engine' => 'legacy', |
676
|
|
|
'connection' => 'default', |
677
|
|
|
'search' => [ |
678
|
|
|
'engine' => 'elasticsearch', |
679
|
|
|
'connection' => 'blabla', |
680
|
|
|
], |
681
|
|
|
], |
682
|
|
|
'foo' => [ |
683
|
|
|
'engine' => 'sqlng', |
684
|
|
|
'connection' => 'default', |
685
|
|
|
'search' => [ |
686
|
|
|
'engine' => 'solr', |
687
|
|
|
'connection' => 'lalala', |
688
|
|
|
], |
689
|
|
|
], |
690
|
|
|
]; |
691
|
|
|
$expectedRepositories = [ |
692
|
|
|
'main' => [ |
693
|
|
|
'search' => [ |
694
|
|
|
'engine' => 'elasticsearch', |
695
|
|
|
'connection' => 'blabla', |
696
|
|
|
'config' => [], |
697
|
|
|
], |
698
|
|
|
'storage' => [ |
699
|
|
|
'engine' => 'legacy', |
700
|
|
|
'connection' => 'default', |
701
|
|
|
'config' => [], |
702
|
|
|
], |
703
|
|
|
'fields_groups' => [ |
704
|
|
|
'list' => ['content', 'metadata'], |
705
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
706
|
|
|
], |
707
|
|
|
'options' => [ |
708
|
|
|
'default_version_archive_limit' => 5, |
709
|
|
|
], |
710
|
|
|
], |
711
|
|
|
'foo' => [ |
712
|
|
|
'search' => [ |
713
|
|
|
'engine' => 'solr', |
714
|
|
|
'connection' => 'lalala', |
715
|
|
|
'config' => [], |
716
|
|
|
], |
717
|
|
|
'storage' => [ |
718
|
|
|
'engine' => 'sqlng', |
719
|
|
|
'connection' => 'default', |
720
|
|
|
'config' => [], |
721
|
|
|
], |
722
|
|
|
'fields_groups' => [ |
723
|
|
|
'list' => ['content', 'metadata'], |
724
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
725
|
|
|
], |
726
|
|
|
'options' => [ |
727
|
|
|
'default_version_archive_limit' => 5, |
728
|
|
|
], |
729
|
|
|
], |
730
|
|
|
]; |
731
|
|
|
$this->load(['repositories' => $repositories]); |
732
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
733
|
|
|
|
734
|
|
|
$this->assertSame( |
735
|
|
|
$expectedRepositories, |
736
|
|
|
$this->container->getParameter('ezpublish.repositories') |
737
|
|
|
); |
738
|
|
|
} |
739
|
|
|
|
740
|
|
View Code Duplication |
public function testRepositoriesConfigurationCompatibility2() |
741
|
|
|
{ |
742
|
|
|
$repositories = [ |
743
|
|
|
'main' => [ |
744
|
|
|
'engine' => 'legacy', |
745
|
|
|
'connection' => 'default', |
746
|
|
|
], |
747
|
|
|
]; |
748
|
|
|
$expectedRepositories = [ |
749
|
|
|
'main' => [ |
750
|
|
|
'storage' => [ |
751
|
|
|
'engine' => 'legacy', |
752
|
|
|
'connection' => 'default', |
753
|
|
|
'config' => [], |
754
|
|
|
], |
755
|
|
|
'search' => [ |
756
|
|
|
'engine' => '%ezpublish.api.search_engine.default%', |
757
|
|
|
'connection' => null, |
758
|
|
|
'config' => [], |
759
|
|
|
], |
760
|
|
|
'fields_groups' => [ |
761
|
|
|
'list' => ['content', 'metadata'], |
762
|
|
|
'default' => '%ezsettings.default.content.field_groups.default%', |
763
|
|
|
], |
764
|
|
|
'options' => [ |
765
|
|
|
'default_version_archive_limit' => 5, |
766
|
|
|
], |
767
|
|
|
], |
768
|
|
|
]; |
769
|
|
|
$this->load(['repositories' => $repositories]); |
770
|
|
|
$this->assertTrue($this->container->hasParameter('ezpublish.repositories')); |
771
|
|
|
|
772
|
|
|
$this->assertSame( |
773
|
|
|
$expectedRepositories, |
774
|
|
|
$this->container->getParameter('ezpublish.repositories') |
775
|
|
|
); |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
public function testRelatedSiteAccesses() |
779
|
|
|
{ |
780
|
|
|
$mainRepo = 'main'; |
781
|
|
|
$fooRepo = 'foo'; |
782
|
|
|
$rootLocationId1 = 123; |
783
|
|
|
$rootLocationId2 = 456; |
784
|
|
|
$rootLocationId3 = 2; |
785
|
|
|
$config = [ |
786
|
|
|
'siteaccess' => [ |
787
|
|
|
'default_siteaccess' => 'ezdemo_site', |
788
|
|
|
'list' => ['ezdemo_site', 'eng', 'fre', 'ezdemo_site2', 'eng2', 'ezdemo_site3', 'fre3'], |
789
|
|
|
'groups' => [ |
790
|
|
|
'ezdemo_group' => ['ezdemo_site', 'eng', 'fre'], |
791
|
|
|
'ezdemo_group2' => ['ezdemo_site2', 'eng2'], |
792
|
|
|
'ezdemo_group3' => ['ezdemo_site3', 'fre3'], |
793
|
|
|
], |
794
|
|
|
'match' => [], |
795
|
|
|
], |
796
|
|
|
'repositories' => [ |
797
|
|
|
$mainRepo => ['engine' => 'legacy', 'connection' => 'default'], |
798
|
|
|
$fooRepo => ['engine' => 'bar', 'connection' => 'blabla'], |
799
|
|
|
], |
800
|
|
|
'system' => [ |
801
|
|
|
'ezdemo_group' => [ |
802
|
|
|
'repository' => $mainRepo, |
803
|
|
|
'content' => [ |
804
|
|
|
'tree_root' => ['location_id' => $rootLocationId1], |
805
|
|
|
], |
806
|
|
|
], |
807
|
|
|
'ezdemo_group2' => [ |
808
|
|
|
'repository' => $mainRepo, |
809
|
|
|
'content' => [ |
810
|
|
|
'tree_root' => ['location_id' => $rootLocationId2], |
811
|
|
|
], |
812
|
|
|
], |
813
|
|
|
'ezdemo_group3' => [ |
814
|
|
|
'repository' => $fooRepo, |
815
|
|
|
], |
816
|
|
|
], |
817
|
|
|
] + $this->siteaccessConfig; |
818
|
|
|
|
819
|
|
|
// Injecting needed config parsers. |
820
|
|
|
$refExtension = new ReflectionObject($this->extension); |
821
|
|
|
$refMethod = $refExtension->getMethod('getMainConfigParser'); |
822
|
|
|
$refMethod->setAccessible(true); |
823
|
|
|
$refMethod->invoke($this->extension); |
824
|
|
|
$refParser = $refExtension->getProperty('mainConfigParser'); |
825
|
|
|
$refParser->setAccessible(true); |
826
|
|
|
/** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */ |
827
|
|
|
$parser = $refParser->getValue($this->extension); |
828
|
|
|
$parser->setConfigParsers([new Common(), new Content()]); |
829
|
|
|
|
830
|
|
|
$this->load($config); |
831
|
|
|
|
832
|
|
|
$relatedSiteAccesses1 = ['ezdemo_site', 'eng', 'fre']; |
833
|
|
|
$relatedSiteAccesses2 = ['ezdemo_site2', 'eng2']; |
834
|
|
|
$relatedSiteAccesses3 = ['ezdemo_site3', 'fre3']; |
835
|
|
|
$expectedRelationMap = [ |
836
|
|
|
$mainRepo => [ |
837
|
|
|
$rootLocationId1 => $relatedSiteAccesses1, |
838
|
|
|
$rootLocationId2 => $relatedSiteAccesses2, |
839
|
|
|
], |
840
|
|
|
$fooRepo => [ |
841
|
|
|
$rootLocationId3 => $relatedSiteAccesses3, |
842
|
|
|
], |
843
|
|
|
]; |
844
|
|
|
$this->assertContainerBuilderHasParameter('ezpublish.siteaccess.relation_map', $expectedRelationMap); |
845
|
|
|
|
846
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses1); |
847
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses1); |
848
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses1); |
849
|
|
|
|
850
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site2.related_siteaccesses', $relatedSiteAccesses2); |
851
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.eng2.related_siteaccesses', $relatedSiteAccesses2); |
852
|
|
|
|
853
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site3.related_siteaccesses', $relatedSiteAccesses3); |
854
|
|
|
$this->assertContainerBuilderHasParameter('ezsettings.fre3.related_siteaccesses', $relatedSiteAccesses3); |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
public function testRegisteredPolicies() |
858
|
|
|
{ |
859
|
|
|
$this->load(); |
860
|
|
|
self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map'); |
861
|
|
|
$previousPolicyMap = $this->container->getParameter('ezpublish.api.role.policy_map'); |
862
|
|
|
|
863
|
|
|
$policies1 = [ |
864
|
|
|
'custom_module' => [ |
865
|
|
|
'custom_function_1' => null, |
866
|
|
|
'custom_function_2' => ['CustomLimitation'], |
867
|
|
|
], |
868
|
|
|
'helloworld' => [ |
869
|
|
|
'foo' => ['bar'], |
870
|
|
|
'baz' => null, |
871
|
|
|
], |
872
|
|
|
]; |
873
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies1)); |
874
|
|
|
|
875
|
|
|
$policies2 = [ |
876
|
|
|
'custom_module2' => [ |
877
|
|
|
'custom_function_3' => null, |
878
|
|
|
'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'], |
879
|
|
|
], |
880
|
|
|
'helloworld' => [ |
881
|
|
|
'foo' => ['additional_limitation'], |
882
|
|
|
'some' => ['thingy', 'thing', 'but', 'wait'], |
883
|
|
|
], |
884
|
|
|
]; |
885
|
|
|
$this->extension->addPolicyProvider(new StubPolicyProvider($policies2)); |
886
|
|
|
|
887
|
|
|
$expectedPolicies = [ |
888
|
|
|
'custom_module' => [ |
889
|
|
|
'custom_function_1' => [], |
890
|
|
|
'custom_function_2' => ['CustomLimitation' => true], |
891
|
|
|
], |
892
|
|
|
'helloworld' => [ |
893
|
|
|
'foo' => ['bar' => true, 'additional_limitation' => true], |
894
|
|
|
'baz' => [], |
895
|
|
|
'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true], |
896
|
|
|
], |
897
|
|
|
'custom_module2' => [ |
898
|
|
|
'custom_function_3' => [], |
899
|
|
|
'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true], |
900
|
|
|
], |
901
|
|
|
]; |
902
|
|
|
|
903
|
|
|
$this->load(); |
904
|
|
|
self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map'); |
905
|
|
|
$expectedPolicies = array_merge_recursive($expectedPolicies, $previousPolicyMap); |
906
|
|
|
self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map')); |
907
|
|
|
} |
908
|
|
|
|
909
|
|
|
/** |
910
|
|
|
* Test RichText Semantic Configuration. |
911
|
|
|
*/ |
912
|
|
|
public function testRichTextConfiguration() |
913
|
|
|
{ |
914
|
|
|
$config = Yaml::parseFile(__DIR__ . '/Fixtures/FieldType/RichText/ezrichtext.yml'); |
915
|
|
|
$this->load($config); |
916
|
|
|
|
917
|
|
|
// Validate Custom Tags |
918
|
|
|
$this->assertTrue( |
919
|
|
|
$this->container->hasParameter($this->extension::RICHTEXT_CUSTOM_TAGS_PARAMETER) |
920
|
|
|
); |
921
|
|
|
$expectedCustomTagsConfig = [ |
922
|
|
|
'video' => [ |
923
|
|
|
'template' => 'MyBundle:FieldType/RichText/tag:video.html.twig', |
924
|
|
|
'icon' => '/bundles/mybundle/fieldtype/richtext/video.svg#video', |
925
|
|
|
'attributes' => [ |
926
|
|
|
'title' => [ |
927
|
|
|
'type' => 'string', |
928
|
|
|
'required' => true, |
929
|
|
|
'default_value' => 'abc', |
930
|
|
|
], |
931
|
|
|
'width' => [ |
932
|
|
|
'type' => 'number', |
933
|
|
|
'required' => true, |
934
|
|
|
'default_value' => 360, |
935
|
|
|
], |
936
|
|
|
'autoplay' => [ |
937
|
|
|
'type' => 'boolean', |
938
|
|
|
'required' => false, |
939
|
|
|
'default_value' => null, |
940
|
|
|
], |
941
|
|
|
], |
942
|
|
|
], |
943
|
|
|
'equation' => [ |
944
|
|
|
'template' => 'MyBundle:FieldType/RichText/tag:equation.html.twig', |
945
|
|
|
'icon' => '/bundles/mybundle/fieldtype/richtext/equation.svg#equation', |
946
|
|
|
'attributes' => [ |
947
|
|
|
'name' => [ |
948
|
|
|
'type' => 'string', |
949
|
|
|
'required' => true, |
950
|
|
|
'default_value' => 'Equation', |
951
|
|
|
], |
952
|
|
|
'processor' => [ |
953
|
|
|
'type' => 'choice', |
954
|
|
|
'required' => true, |
955
|
|
|
'default_value' => 'latex', |
956
|
|
|
'choices' => ['latex', 'tex'], |
957
|
|
|
], |
958
|
|
|
], |
959
|
|
|
], |
960
|
|
|
]; |
961
|
|
|
|
962
|
|
|
$this->assertSame( |
963
|
|
|
$expectedCustomTagsConfig, |
964
|
|
|
$this->container->getParameter($this->extension::RICHTEXT_CUSTOM_TAGS_PARAMETER) |
965
|
|
|
); |
966
|
|
|
} |
967
|
|
|
|
968
|
|
|
public function testUrlAliasConfiguration() |
969
|
|
|
{ |
970
|
|
|
$configuration = [ |
971
|
|
|
'transformation' => 'urlalias_lowercase', |
972
|
|
|
'separator' => 'dash', |
973
|
|
|
'transformation_groups' => [ |
974
|
|
|
'urlalias' => [ |
975
|
|
|
'commands' => [ |
976
|
|
|
'ascii_lowercase', |
977
|
|
|
'cyrillic_lowercase', |
978
|
|
|
], |
979
|
|
|
'cleanup_method' => 'url_cleanup', |
980
|
|
|
], |
981
|
|
|
'urlalias_compact' => [ |
982
|
|
|
'commands' => [ |
983
|
|
|
'greek_normalize', |
984
|
|
|
'exta_lowercase', |
985
|
|
|
], |
986
|
|
|
'cleanup_method' => 'compact_cleanup', |
987
|
|
|
], |
988
|
|
|
], |
989
|
|
|
]; |
990
|
|
|
$this->load([ |
991
|
|
|
'url_alias' => [ |
992
|
|
|
'slug_converter' => $configuration, |
993
|
|
|
], |
994
|
|
|
]); |
995
|
|
|
$parsedConfig = $this->container->getParameter('ezpublish.url_alias.slug_converter'); |
996
|
|
|
$this->assertSame( |
997
|
|
|
$configuration, |
998
|
|
|
$parsedConfig |
999
|
|
|
); |
1000
|
|
|
} |
1001
|
|
|
|
1002
|
|
|
/** |
1003
|
|
|
* Load & cache RichText default settings. |
1004
|
|
|
* |
1005
|
|
|
* @return array |
1006
|
|
|
*/ |
1007
|
|
|
private function loadRichTextDefaultSettings(): array |
1008
|
|
|
{ |
1009
|
|
|
if (null === static::$richTextDefaultSettings) { |
|
|
|
|
1010
|
|
|
static::$richTextDefaultSettings = Yaml::parseFile( |
|
|
|
|
1011
|
|
|
__DIR__ . '/../../Resources/config/ezrichtext_default_settings.yml' |
1012
|
|
|
); |
1013
|
|
|
} |
1014
|
|
|
|
1015
|
|
|
return static::$richTextDefaultSettings; |
|
|
|
|
1016
|
|
|
} |
1017
|
|
|
} |
1018
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.