Completed
Push — master ( 3b7ffc...93bca7 )
by Łukasz
15:02
created

testRelatedSiteAccesses()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 78
rs 8.48
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A EzPublishCoreExtensionTest::testUrlAliasConfiguration() 0 33 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Compiler\QueryTypePass;
12
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Common;
13
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Content;
14
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
15
use eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Stub\QueryTypeBundle\QueryType\TestQueryType;
16
use eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Stub\StubPolicyProvider;
17
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
18
use Symfony\Component\DependencyInjection\Compiler\CheckExceptionOnInvalidReferenceBehaviorPass;
19
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
20
use Symfony\Component\DependencyInjection\Definition;
21
use Symfony\Component\Yaml\Yaml;
22
use ReflectionObject;
23
24
class EzPublishCoreExtensionTest extends AbstractExtensionTestCase
25
{
26
    private $minimalConfig = [];
27
28
    private $siteaccessConfig = [];
29
30
    /** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension */
31
    private $extension;
32
33
    protected function setUp(): void
34
    {
35
        $this->extension = new EzPublishCoreExtension();
36
        $this->siteaccessConfig = [
37
            'siteaccess' => [
38
                'default_siteaccess' => 'ezdemo_site',
39
                'list' => ['ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'],
40
                'groups' => [
41
                    'ezdemo_group' => ['ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'],
42
                    'ezdemo_frontend_group' => ['ezdemo_site', 'eng', 'fre'],
43
                ],
44
                'match' => [
45
                    'URILElement' => 1,
46
                    'Map\URI' => ['the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin'],
47
                ],
48
            ],
49
            'system' => [
50
                'ezdemo_site' => [],
51
                'eng' => [],
52
                'fre' => [],
53
                'ezdemo_site_admin' => [],
54
            ],
55
        ];
56
57
        parent::setUp();
58
    }
59
60
    protected function getContainerExtensions(): array
61
    {
62
        return [$this->extension];
63
    }
64
65
    protected function getMinimalConfiguration(): array
66
    {
67
        return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml'));
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Yaml\...al_no_siteaccess.yml')) of type * is incompatible with the declared type array of property $minimalConfig.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
68
    }
69
70
    public function testSiteAccessConfiguration()
71
    {
72
        // Injecting needed config parsers.
73
        $refExtension = new ReflectionObject($this->extension);
74
        $refMethod = $refExtension->getMethod('getMainConfigParser');
75
        $refMethod->setAccessible(true);
76
        $refMethod->invoke($this->extension);
77
        $refParser = $refExtension->getProperty('mainConfigParser');
78
        $refParser->setAccessible(true);
79
        /** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */
80
        $parser = $refParser->getValue($this->extension);
81
        $parser->setConfigParsers([new Common(), new Content()]);
82
83
        $this->load($this->siteaccessConfig);
84
        $this->assertContainerBuilderHasParameter(
85
            'ezpublish.siteaccess.list',
86
            $this->siteaccessConfig['siteaccess']['list']
87
        );
88
        $this->assertContainerBuilderHasParameter(
89
            'ezpublish.siteaccess.default',
90
            $this->siteaccessConfig['siteaccess']['default_siteaccess']
91
        );
92
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', $this->siteaccessConfig['siteaccess']['groups']);
93
94
        $expectedMatchingConfig = [];
95
        foreach ($this->siteaccessConfig['siteaccess']['match'] as $key => $val) {
96
            // Value is expected to always be an array (transformed by semantic configuration parser).
97
            $expectedMatchingConfig[$key] = is_array($val) ? $val : ['value' => $val];
98
        }
99
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', $expectedMatchingConfig);
100
101
        $groupsBySiteaccess = [];
102 View Code Duplication
        foreach ($this->siteaccessConfig['siteaccess']['groups'] as $groupName => $groupMembers) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
            foreach ($groupMembers as $member) {
104
                if (!isset($groupsBySiteaccess[$member])) {
105
                    $groupsBySiteaccess[$member] = [];
106
                }
107
108
                $groupsBySiteaccess[$member][] = $groupName;
109
            }
110
        }
111
    }
112
113
    public function testSiteAccessNoConfiguration()
114
    {
115
        $this->load();
116
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.list', ['setup']);
117
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.default', 'setup');
118
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', []);
119
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', []);
120
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', null);
121
    }
122
123
    public function testImageMagickConfigurationBasic()
124
    {
125 View Code Duplication
        if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
126
            $this->markTestSkipped('Missing or mis-configured Imagemagick convert path.');
127
        }
128
129
        $this->load(
130
            [
131
                'imagemagick' => [
132
                    'enabled' => true,
133
                    'path' => $_ENV['imagemagickConvertPath'],
134
                ],
135
            ]
136
        );
137
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.enabled', true);
138
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable_path', dirname($_ENV['imagemagickConvertPath']));
139
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable', basename($_ENV['imagemagickConvertPath']));
140
    }
141
142
    public function testImageMagickConfigurationFilters()
143
    {
144 View Code Duplication
        if (!isset($_ENV['imagemagickConvertPath']) || !is_executable($_ENV['imagemagickConvertPath'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
145
            $this->markTestSkipped('Missing or mis-configured Imagemagick convert path.');
146
        }
147
148
        $customFilters = [
149
            'foobar' => '-foobar',
150
            'wow' => '-amazing',
151
        ];
152
        $this->load(
153
            [
154
                'imagemagick' => [
155
                    'enabled' => true,
156
                    'path' => $_ENV['imagemagickConvertPath'],
157
                    'filters' => $customFilters,
158
                ],
159
            ]
160
        );
161
        $this->assertTrue($this->container->hasParameter('ezpublish.image.imagemagick.filters'));
162
        $filters = $this->container->getParameter('ezpublish.image.imagemagick.filters');
163
        $this->assertArrayHasKey('foobar', $filters);
164
        $this->assertSame($customFilters['foobar'], $filters['foobar']);
165
        $this->assertArrayHasKey('wow', $filters);
166
        $this->assertSame($customFilters['wow'], $filters['wow']);
167
    }
168
169
    public function testImagePlaceholderConfiguration()
170
    {
171
        $this->load([
172
            'image_placeholder' => [
173
                'default' => [
174
                    'provider' => 'generic',
175
                    'options' => [
176
                        'foo' => 'Foo',
177
                        'bar' => 'Bar',
178
                    ],
179
                ],
180
                'fancy' => [
181
                    'provider' => 'remote',
182
                ],
183
            ],
184
        ]);
185
186
        $this->assertEquals([
187
            'default' => [
188
                'provider' => 'generic',
189
                'options' => [
190
                    'foo' => 'Foo',
191
                    'bar' => 'Bar',
192
                ],
193
            ],
194
            'fancy' => [
195
                'provider' => 'remote',
196
                'options' => [],
197
            ],
198
        ], $this->container->getParameter('image_alias.placeholder_providers'));
199
    }
200
201
    public function testRoutingConfiguration()
202
    {
203
        $this->load();
204
        $this->assertContainerBuilderHasAlias('router', 'ezpublish.chain_router');
205
206
        $this->assertTrue($this->container->hasParameter('ezpublish.default_router.non_siteaccess_aware_routes'));
207
        $nonSiteaccessAwareRoutes = $this->container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes');
208
        // See ezpublish_minimal_no_siteaccess.yml fixture
209
        $this->assertContains('foo_route', $nonSiteaccessAwareRoutes);
210
        $this->assertContains('my_prefix_', $nonSiteaccessAwareRoutes);
211
    }
212
213
    /**
214
     * @dataProvider cacheConfigurationProvider
215
     *
216
     * @param array $customCacheConfig
217
     * @param string $expectedPurgeType
218
     */
219
    public function testCacheConfiguration(array $customCacheConfig, $expectedPurgeType)
220
    {
221
        $this->load($customCacheConfig);
222
223
        $this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', $expectedPurgeType);
224
    }
225
226
    public function cacheConfigurationProvider()
227
    {
228
        return [
229
            [[], 'local'],
230
            [
231
                [
232
                    'http_cache' => ['purge_type' => 'local'],
233
                ],
234
                'local',
235
            ],
236
            [
237
                [
238
                    'http_cache' => ['purge_type' => 'multiple_http'],
239
                ],
240
                'http',
241
            ],
242
            [
243
                [
244
                    'http_cache' => ['purge_type' => 'single_http'],
245
                ],
246
                'http',
247
            ],
248
            [
249
                [
250
                    'http_cache' => ['purge_type' => 'http'],
251
                ],
252
                'http',
253
            ],
254
        ];
255
    }
256
257
    public function testCacheConfigurationCustomPurgeService()
258
    {
259
        $serviceId = 'foobar';
260
        $this->setDefinition($serviceId, new Definition());
261
        $this->load(
262
            [
263
                'http_cache' => ['purge_type' => 'foobar', 'timeout' => 12],
264
            ]
265
        );
266
267
        $this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', 'foobar');
268
    }
269
270
    public function testLocaleConfiguration()
271
    {
272
        $this->load(['locale_conversion' => ['foo' => 'bar']]);
273
        $conversionMap = $this->container->getParameter('ezpublish.locale.conversion_map');
274
        $this->assertArrayHasKey('foo', $conversionMap);
275
        $this->assertSame('bar', $conversionMap['foo']);
276
    }
277
278
    public function testRepositoriesConfiguration()
279
    {
280
        $repositories = [
281
            'main' => [
282
                'storage' => [
283
                    'engine' => 'legacy',
284
                    'connection' => 'default',
285
                ],
286
                'search' => [
287
                    'engine' => 'legacy',
288
                    'connection' => 'blabla',
289
                ],
290
                'fields_groups' => [
291
                    'list' => ['content', 'metadata'],
292
                    'default' => '%ezsettings.default.content.field_groups.default%',
293
                ],
294
                'options' => [
295
                    'default_version_archive_limit' => 5,
296
                ],
297
            ],
298
            'foo' => [
299
                'storage' => [
300
                    'engine' => 'sqlng',
301
                    'connection' => 'default',
302
                ],
303
                'search' => [
304
                    'engine' => 'solr',
305
                    'connection' => 'lalala',
306
                ],
307
                'fields_groups' => [
308
                    'list' => ['content', 'metadata'],
309
                    'default' => '%ezsettings.default.content.field_groups.default%',
310
                ],
311
                'options' => [
312
                    'default_version_archive_limit' => 5,
313
                ],
314
            ],
315
        ];
316
        $this->load(['repositories' => $repositories]);
317
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
318
319
        foreach ($repositories as &$repositoryConfig) {
320
            $repositoryConfig['storage']['config'] = [];
321
            $repositoryConfig['search']['config'] = [];
322
        }
323
        $this->assertSame($repositories, $this->container->getParameter('ezpublish.repositories'));
324
    }
325
326
    /**
327
     * @dataProvider repositoriesConfigurationFieldGroupsProvider
328
     */
329
    public function testRepositoriesConfigurationFieldGroups($repositories, $expectedRepositories)
330
    {
331
        $this->load(['repositories' => $repositories]);
332
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
333
334
        $repositoriesPar = $this->container->getParameter('ezpublish.repositories');
335
        $this->assertEquals(count($repositories), count($repositoriesPar));
336
337
        foreach ($repositoriesPar as $key => $repo) {
338
            $this->assertArrayHasKey($key, $expectedRepositories);
339
            $this->assertArrayHasKey('fields_groups', $repo);
340
            $this->assertEqualsCanonicalizing($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element');
341
        }
342
    }
343
344
    public function repositoriesConfigurationFieldGroupsProvider()
345
    {
346
        return [
347
            //empty config
348
            [
349
                ['main' => null],
350
                ['main' => [
351
                        'fields_groups' => [
352
                            'list' => ['content', 'metadata'],
353
                            'default' => '%ezsettings.default.content.field_groups.default%',
354
                        ],
355
                    ],
356
                ],
357
            ],
358
            //single item with custom fields
359
            [
360
                ['foo' => [
361
                        'fields_groups' => [
362
                            'list' => ['bar', 'baz', 'john'],
363
                            'default' => 'bar',
364
                        ],
365
                    ],
366
                ],
367
                ['foo' => [
368
                        'fields_groups' => [
369
                            'list' => ['bar', 'baz', 'john'],
370
                            'default' => 'bar',
371
                        ],
372
                    ],
373
                ],
374
            ],
375
            //mixed item with custom config and empty item
376
            [
377
                [
378
                    'foo' => [
379
                        'fields_groups' => [
380
                            'list' => ['bar', 'baz', 'john', 'doe'],
381
                            'default' => 'bar',
382
                        ],
383
                    ],
384
                    'anotherone' => null,
385
                ],
386
                [
387
                    'foo' => [
388
                        'fields_groups' => [
389
                            'list' => ['bar', 'baz', 'john', 'doe'],
390
                            'default' => 'bar',
391
                        ],
392
                    ],
393
                    'anotherone' => [
394
                        'fields_groups' => [
395
                            'list' => ['content', 'metadata'],
396
                            'default' => '%ezsettings.default.content.field_groups.default%',
397
                        ],
398
                    ],
399
                ],
400
            ],
401
            //items with only one field configured
402
            [
403
                [
404
                    'foo' => [
405
                        'fields_groups' => [
406
                            'list' => ['bar', 'baz', 'john'],
407
                        ],
408
                    ],
409
                    'bar' => [
410
                        'fields_groups' => [
411
                            'default' => 'metadata',
412
                        ],
413
                    ],
414
                ],
415
                [
416
                    'foo' => [
417
                        'fields_groups' => [
418
                            'list' => ['bar', 'baz', 'john'],
419
                            'default' => '%ezsettings.default.content.field_groups.default%',
420
                        ],
421
                    ],
422
                    'bar' => [
423
                        'fields_groups' => [
424
                            'list' => ['content', 'metadata'],
425
                            'default' => 'metadata',
426
                        ],
427
                    ],
428
                ],
429
            ],
430
            //two different repositories
431
            [
432
                [
433
                    'foo' => [
434
                        'fields_groups' => [
435
                            'list' => ['bar', 'baz', 'john', 'doe'],
436
                            'default' => 'bar',
437
                        ],
438
                    ],
439
                    'bar' => [
440
                        'fields_groups' => [
441
                            'list' => ['lorem', 'ipsum'],
442
                            'default' => 'lorem',
443
                        ],
444
                    ],
445
                ],
446
                [
447
                    'foo' => [
448
                        'fields_groups' => [
449
                            'list' => ['bar', 'baz', 'john', 'doe'],
450
                            'default' => 'bar',
451
                        ],
452
                    ],
453
                    'bar' => [
454
                        'fields_groups' => [
455
                            'list' => ['lorem', 'ipsum'],
456
                            'default' => 'lorem',
457
                        ],
458
                    ],
459
                ],
460
            ],
461
        ];
462
    }
463
464
    public function testRepositoriesConfigurationEmpty()
465
    {
466
        $repositories = [
467
            'main' => null,
468
        ];
469
        $expectedRepositories = [
470
            'main' => [
471
                'storage' => [
472
                    'engine' => '%ezpublish.api.storage_engine.default%',
473
                    'connection' => null,
474
                    'config' => [],
475
                ],
476
                'search' => [
477
                    'engine' => '%ezpublish.api.search_engine.default%',
478
                    'connection' => null,
479
                    'config' => [],
480
                ],
481
                'fields_groups' => [
482
                    'list' => ['content', 'metadata'],
483
                    'default' => '%ezsettings.default.content.field_groups.default%',
484
                ],
485
                'options' => [
486
                    'default_version_archive_limit' => 5,
487
                ],
488
            ],
489
        ];
490
        $this->load(['repositories' => $repositories]);
491
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
492
493
        $this->assertSame(
494
            $expectedRepositories,
495
            $this->container->getParameter('ezpublish.repositories')
496
        );
497
    }
498
499 View Code Duplication
    public function testRepositoriesConfigurationStorageEmpty()
500
    {
501
        $repositories = [
502
            'main' => [
503
                'search' => [
504
                    'engine' => 'fantasticfind',
505
                    'connection' => 'french',
506
                ],
507
            ],
508
        ];
509
        $expectedRepositories = [
510
            'main' => [
511
                'search' => [
512
                    'engine' => 'fantasticfind',
513
                    'connection' => 'french',
514
                    'config' => [],
515
                ],
516
                'storage' => [
517
                    'engine' => '%ezpublish.api.storage_engine.default%',
518
                    'connection' => null,
519
                    'config' => [],
520
                ],
521
                'fields_groups' => [
522
                    'list' => ['content', 'metadata'],
523
                    'default' => '%ezsettings.default.content.field_groups.default%',
524
                ],
525
                'options' => [
526
                    'default_version_archive_limit' => 5,
527
                ],
528
            ],
529
        ];
530
        $this->load(['repositories' => $repositories]);
531
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
532
533
        $this->assertSame(
534
            $expectedRepositories,
535
            $this->container->getParameter('ezpublish.repositories')
536
        );
537
    }
538
539 View Code Duplication
    public function testRepositoriesConfigurationSearchEmpty()
540
    {
541
        $repositories = [
542
            'main' => [
543
                'storage' => [
544
                    'engine' => 'persistentprudence',
545
                    'connection' => 'yes',
546
                ],
547
            ],
548
        ];
549
        $expectedRepositories = [
550
            'main' => [
551
                'storage' => [
552
                    'engine' => 'persistentprudence',
553
                    'connection' => 'yes',
554
                    'config' => [],
555
                ],
556
                'search' => [
557
                    'engine' => '%ezpublish.api.search_engine.default%',
558
                    'connection' => null,
559
                    'config' => [],
560
                ],
561
                'fields_groups' => [
562
                    'list' => ['content', 'metadata'],
563
                    'default' => '%ezsettings.default.content.field_groups.default%',
564
                ],
565
                'options' => [
566
                    'default_version_archive_limit' => 5,
567
                ],
568
            ],
569
        ];
570
        $this->load(['repositories' => $repositories]);
571
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
572
573
        $this->assertSame(
574
            $expectedRepositories,
575
            $this->container->getParameter('ezpublish.repositories')
576
        );
577
    }
578
579
    public function testRepositoriesConfigurationCompatibility()
580
    {
581
        $repositories = [
582
            'main' => [
583
                'engine' => 'legacy',
584
                'connection' => 'default',
585
                'search' => [
586
                    'engine' => 'legacy',
587
                    'connection' => 'blabla',
588
                ],
589
            ],
590
            'foo' => [
591
                'engine' => 'sqlng',
592
                'connection' => 'default',
593
                'search' => [
594
                    'engine' => 'solr',
595
                    'connection' => 'lalala',
596
                ],
597
            ],
598
        ];
599
        $expectedRepositories = [
600
            'main' => [
601
                'search' => [
602
                    'engine' => 'legacy',
603
                    'connection' => 'blabla',
604
                    'config' => [],
605
                ],
606
                'storage' => [
607
                    'engine' => 'legacy',
608
                    'connection' => 'default',
609
                    'config' => [],
610
                ],
611
                'fields_groups' => [
612
                    'list' => ['content', 'metadata'],
613
                    'default' => '%ezsettings.default.content.field_groups.default%',
614
                ],
615
                'options' => [
616
                    'default_version_archive_limit' => 5,
617
                ],
618
            ],
619
            'foo' => [
620
                'search' => [
621
                    'engine' => 'solr',
622
                    'connection' => 'lalala',
623
                    'config' => [],
624
                ],
625
                'storage' => [
626
                    'engine' => 'sqlng',
627
                    'connection' => 'default',
628
                    'config' => [],
629
                ],
630
                'fields_groups' => [
631
                    'list' => ['content', 'metadata'],
632
                    'default' => '%ezsettings.default.content.field_groups.default%',
633
                ],
634
                'options' => [
635
                    'default_version_archive_limit' => 5,
636
                ],
637
            ],
638
        ];
639
        $this->load(['repositories' => $repositories]);
640
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
641
642
        $this->assertSame(
643
            $expectedRepositories,
644
            $this->container->getParameter('ezpublish.repositories')
645
        );
646
    }
647
648 View Code Duplication
    public function testRepositoriesConfigurationCompatibility2()
649
    {
650
        $repositories = [
651
            'main' => [
652
                'engine' => 'legacy',
653
                'connection' => 'default',
654
            ],
655
        ];
656
        $expectedRepositories = [
657
            'main' => [
658
                'storage' => [
659
                    'engine' => 'legacy',
660
                    'connection' => 'default',
661
                    'config' => [],
662
                ],
663
                'search' => [
664
                    'engine' => '%ezpublish.api.search_engine.default%',
665
                    'connection' => null,
666
                    'config' => [],
667
                ],
668
                'fields_groups' => [
669
                    'list' => ['content', 'metadata'],
670
                    'default' => '%ezsettings.default.content.field_groups.default%',
671
                ],
672
                'options' => [
673
                    'default_version_archive_limit' => 5,
674
                ],
675
            ],
676
        ];
677
        $this->load(['repositories' => $repositories]);
678
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
679
680
        $this->assertSame(
681
            $expectedRepositories,
682
            $this->container->getParameter('ezpublish.repositories')
683
        );
684
    }
685
686
    public function testRegisteredPolicies()
687
    {
688
        $this->load();
689
        self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map');
690
        $previousPolicyMap = $this->container->getParameter('ezpublish.api.role.policy_map');
691
692
        $policies1 = [
693
            'custom_module' => [
694
                'custom_function_1' => null,
695
                'custom_function_2' => ['CustomLimitation'],
696
            ],
697
            'helloworld' => [
698
                'foo' => ['bar'],
699
                'baz' => null,
700
            ],
701
        ];
702
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies1));
703
704
        $policies2 = [
705
            'custom_module2' => [
706
                'custom_function_3' => null,
707
                'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'],
708
            ],
709
            'helloworld' => [
710
                'foo' => ['additional_limitation'],
711
                'some' => ['thingy', 'thing', 'but', 'wait'],
712
            ],
713
        ];
714
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies2));
715
716
        $expectedPolicies = [
717
            'custom_module' => [
718
                'custom_function_1' => [],
719
                'custom_function_2' => ['CustomLimitation' => true],
720
            ],
721
            'helloworld' => [
722
                'foo' => ['bar' => true, 'additional_limitation' => true],
723
                'baz' => [],
724
                'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true],
725
            ],
726
            'custom_module2' => [
727
                'custom_function_3' => [],
728
                'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true],
729
            ],
730
        ];
731
732
        $this->load();
733
        self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map');
734
        $expectedPolicies = array_merge_recursive($expectedPolicies, $previousPolicyMap);
735
        self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map'));
736
    }
737
738
    public function testUrlAliasConfiguration()
739
    {
740
        $configuration = [
741
            'transformation' => 'urlalias_lowercase',
742
            'separator' => 'dash',
743
            'transformation_groups' => [
744
                'urlalias' => [
745
                    'commands' => [
746
                        'ascii_lowercase',
747
                        'cyrillic_lowercase',
748
                    ],
749
                    'cleanup_method' => 'url_cleanup',
750
                ],
751
                'urlalias_compact' => [
752
                    'commands' => [
753
                        'greek_normalize',
754
                        'exta_lowercase',
755
                    ],
756
                    'cleanup_method' => 'compact_cleanup',
757
                ],
758
            ],
759
        ];
760
        $this->load([
761
            'url_alias' => [
762
                'slug_converter' => $configuration,
763
            ],
764
        ]);
765
        $parsedConfig = $this->container->getParameter('ezpublish.url_alias.slug_converter');
766
        $this->assertSame(
767
            $configuration,
768
            $parsedConfig
769
        );
770
    }
771
772
    /**
773
     * Test automatic configuration of services implementing QueryType interface.
774
     *
775
     * @see \eZ\Publish\Core\QueryType\QueryType
776
     */
777
    public function testQueryTypeAutomaticConfiguration(): void
778
    {
779
        $definition = new Definition(TestQueryType::class);
780
        $definition->setAutoconfigured(true);
781
        $this->setDefinition(TestQueryType::class, $definition);
782
783
        $this->load();
784
785
        $this->compileCoreContainer();
786
787
        $this->assertContainerBuilderHasServiceDefinitionWithTag(
788
            TestQueryType::class,
789
            QueryTypePass::QUERY_TYPE_SERVICE_TAG
790
        );
791
    }
792
793
    /**
794
     * Prepare Core Container for compilation by mocking required parameters and compile it.
795
     */
796
    private function compileCoreContainer(): void
797
    {
798
        $this->disableCheckExceptionOnInvalidReferenceBehaviorPass();
799
        $this->container->setParameter('webroot_dir', __DIR__);
800
        $this->container->setParameter('kernel.root_dir', __DIR__);
801
        $this->container->setParameter('kernel.debug', false);
802
        $this->compile();
803
    }
804
805
    final public function disableCheckExceptionOnInvalidReferenceBehaviorPass(): void
806
    {
807
        $compilerPassConfig = $this->container->getCompilerPassConfig();
808
        $compilerPassConfig->setAfterRemovingPasses(
809
            array_filter(
810
                $compilerPassConfig->getAfterRemovingPasses(),
811
                static function (CompilerPassInterface $pass) {
812
                    return !($pass instanceof CheckExceptionOnInvalidReferenceBehaviorPass);
813
                }
814
            )
815
        );
816
    }
817
}
818