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