Completed
Push — master ( 513898...595f7b )
by Łukasz
29:17
created

testImagePlaceholderConfiguration()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 20
nc 1
nop 0
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the EzPublishCoreExtensionTest class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection;
10
11
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Common;
12
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Content;
13
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
14
use eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Stub\StubPolicyProvider;
15
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
16
use Symfony\Component\DependencyInjection\Definition;
17
use Symfony\Component\Yaml\Yaml;
18
use ReflectionObject;
19
20
class EzPublishCoreExtensionTest extends AbstractExtensionTestCase
21
{
22
    private $minimalConfig = array();
23
24
    private $siteaccessConfig = array();
25
26
    /**
27
     * @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension
28
     */
29
    private $extension;
30
31
    protected function setUp()
32
    {
33
        $this->extension = new EzPublishCoreExtension();
34
        $this->siteaccessConfig = array(
35
            'siteaccess' => array(
36
                'default_siteaccess' => 'ezdemo_site',
37
                'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'),
38
                'groups' => array(
39
                    'ezdemo_group' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'),
40
                    'ezdemo_frontend_group' => array('ezdemo_site', 'eng', 'fre'),
41
                ),
42
                'match' => array(
43
                    'URILElement' => 1,
44
                    'Map\URI' => array('the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin'),
45
                ),
46
            ),
47
            'system' => array(
48
                'ezdemo_site' => array(),
49
                'eng' => array(),
50
                'fre' => array(),
51
                'ezdemo_site_admin' => array(),
52
            ),
53
        );
54
55
        parent::setUp();
56
    }
57
58
    protected function getContainerExtensions()
59
    {
60
        return array($this->extension);
61
    }
62
63
    protected function getMinimalConfiguration()
64
    {
65
        return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml'));
0 ignored issues
show
Bug Best Practice introduced by
The return type of return $this->minimalCon...l_no_siteaccess.yml')); (null|Symfony\Component\Y...e|string|array|stdClass) is incompatible with the return type of the parent method Matthias\SymfonyDependen...getMinimalConfiguration of type array.

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:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

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