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