Completed
Push — master ( cf5cfd...77d9d3 )
by Łukasz
20:22
created

testRepositoriesConfigurationStorageEmpty()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 39
Code Lines 26

Duplication

Lines 39
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 26
nc 1
nop 0
dl 39
loc 39
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 testEzPageConfiguration()
185
    {
186
        $customLayouts = array(
187
            'FoobarLayout' => array('name' => 'Foo layout', 'template' => 'foolayout.html.twig'),
188
        );
189
        $enabledLayouts = array('FoobarLayout', 'GlobalZoneLayout');
190
        $customBlocks = array(
191
            'FoobarBlock' => array('name' => 'Foo block'),
192
        );
193
        $enabledBlocks = array('FoobarBlock', 'DemoBlock');
194
        $this->load(
195
            array(
196
                'ezpage' => array(
197
                    'layouts' => $customLayouts,
198
                    'blocks' => $customBlocks,
199
                    'enabledLayouts' => $enabledLayouts,
200
                    'enabledBlocks' => $enabledBlocks,
201
                ),
202
            )
203
        );
204
205
        $this->assertTrue($this->container->hasParameter('ezpublish.ezpage.layouts'));
206
        $layouts = $this->container->getParameter('ezpublish.ezpage.layouts');
207
        $this->assertArrayHasKey('FoobarLayout', $layouts);
208
        $this->assertSame($customLayouts['FoobarLayout'], $layouts['FoobarLayout']);
209
        $this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledLayouts', $enabledLayouts);
210
211
        $this->assertTrue($this->container->hasParameter('ezpublish.ezpage.blocks'));
212
        $blocks = $this->container->getParameter('ezpublish.ezpage.blocks');
213
        $this->assertArrayHasKey('FoobarBlock', $blocks);
214
        $this->assertSame($customBlocks['FoobarBlock'], $blocks['FoobarBlock']);
215
        $this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledBlocks', $enabledBlocks);
216
    }
217
218
    public function testRoutingConfiguration()
219
    {
220
        $this->load();
221
        $this->assertContainerBuilderHasAlias('router', 'ezpublish.chain_router');
222
223
        $this->assertTrue($this->container->hasParameter('ezpublish.default_router.non_siteaccess_aware_routes'));
224
        $nonSiteaccessAwareRoutes = $this->container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes');
225
        // See ezpublish_minimal_no_siteaccess.yml fixture
226
        $this->assertContains('foo_route', $nonSiteaccessAwareRoutes);
227
        $this->assertContains('my_prefix_', $nonSiteaccessAwareRoutes);
228
    }
229
230
    /**
231
     * @dataProvider cacheConfigurationProvider
232
     *
233
     * @param array $customCacheConfig
234
     * @param string $expectedPurgeType
235
     */
236
    public function testCacheConfiguration(array $customCacheConfig, $expectedPurgeType)
237
    {
238
        $this->load($customCacheConfig);
239
240
        $this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', $expectedPurgeType);
241
    }
242
243
    public function cacheConfigurationProvider()
244
    {
245
        return array(
246
            array(array(), 'local'),
247
            array(
248
                array(
249
                    'http_cache' => array('purge_type' => 'local'),
250
                ),
251
                'local',
252
            ),
253
            array(
254
                array(
255
                    'http_cache' => array('purge_type' => 'multiple_http'),
256
                ),
257
                'http',
258
            ),
259
            array(
260
                array(
261
                    'http_cache' => array('purge_type' => 'single_http'),
262
                ),
263
                'http',
264
            ),
265
            array(
266
                array(
267
                    'http_cache' => array('purge_type' => 'http'),
268
                ),
269
                'http',
270
            ),
271
        );
272
    }
273
274
    public function testCacheConfigurationCustomPurgeService()
275
    {
276
        $serviceId = 'foobar';
277
        $this->setDefinition($serviceId, new Definition());
278
        $this->load(
279
            array(
280
                'http_cache' => array('purge_type' => 'foobar', 'timeout' => 12),
281
            )
282
        );
283
284
        $this->assertContainerBuilderHasParameter('ezpublish.http_cache.purge_type', 'foobar');
285
    }
286
287
    public function testLocaleConfiguration()
288
    {
289
        $this->load(array('locale_conversion' => array('foo' => 'bar')));
290
        $conversionMap = $this->container->getParameter('ezpublish.locale.conversion_map');
291
        $this->assertArrayHasKey('foo', $conversionMap);
292
        $this->assertSame('bar', $conversionMap['foo']);
293
    }
294
295
    public function testRepositoriesConfiguration()
296
    {
297
        $repositories = array(
298
            'main' => array(
299
                'storage' => array(
300
                    'engine' => 'legacy',
301
                    'connection' => 'default',
302
                ),
303
                'search' => array(
304
                    'engine' => 'elasticsearch',
305
                    'connection' => 'blabla',
306
                ),
307
                'fields_groups' => array(
308
                    'list' => ['content', 'metadata'],
309
                    'default' => '%ezsettings.default.content.field_groups.default%',
310
                ),
311
                'options' => [
312
                    'default_version_archive_limit' => 5,
313
                ],
314
            ),
315
            'foo' => array(
316
                'storage' => array(
317
                    'engine' => 'sqlng',
318
                    'connection' => 'default',
319
                ),
320
                'search' => array(
321
                    'engine' => 'solr',
322
                    'connection' => 'lalala',
323
                ),
324
                'fields_groups' => array(
325
                    'list' => ['content', 'metadata'],
326
                    'default' => '%ezsettings.default.content.field_groups.default%',
327
                ),
328
                'options' => [
329
                    'default_version_archive_limit' => 5,
330
                ],
331
            ),
332
        );
333
        $this->load(array('repositories' => $repositories));
334
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
335
336
        foreach ($repositories as &$repositoryConfig) {
337
            $repositoryConfig['storage']['config'] = array();
338
            $repositoryConfig['search']['config'] = array();
339
        }
340
        $this->assertSame($repositories, $this->container->getParameter('ezpublish.repositories'));
341
    }
342
343
    /**
344
     * @dataProvider repositoriesConfigurationFieldGroupsProvider
345
     */
346
    public function testRepositoriesConfigurationFieldGroups($repositories, $expectedRepositories)
347
    {
348
        $this->load(['repositories' => $repositories]);
349
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
350
351
        $repositoriesPar = $this->container->getParameter('ezpublish.repositories');
352
        $this->assertEquals(count($repositories), count($repositoriesPar));
353
354
        foreach ($repositoriesPar as $key => $repo) {
355
            $this->assertArrayHasKey($key, $expectedRepositories);
356
            $this->assertArrayHasKey('fields_groups', $repo);
357
            $this->assertEquals($expectedRepositories[$key]['fields_groups'], $repo['fields_groups'], 'Invalid fields groups element', 0.0, 10, true);
358
        }
359
    }
360
361
    public function repositoriesConfigurationFieldGroupsProvider()
362
    {
363
        return [
364
            //empty config
365
            [
366
                ['main' => null],
367
                ['main' => [
368
                        'fields_groups' => [
369
                            'list' => ['content', 'metadata'],
370
                            'default' => '%ezsettings.default.content.field_groups.default%',
371
                        ],
372
                    ],
373
                ],
374
            ],
375
            //single item with custom fields
376
            [
377
                ['foo' => [
378
                        'fields_groups' => [
379
                            'list' => ['bar', 'baz', 'john'],
380
                            'default' => 'bar',
381
                        ],
382
                    ],
383
                ],
384
                ['foo' => [
385
                        'fields_groups' => [
386
                            'list' => ['bar', 'baz', 'john'],
387
                            'default' => 'bar',
388
                        ],
389
                    ],
390
                ],
391
            ],
392
            //mixed item with custom config and empty item
393
            [
394
                [
395
                    'foo' => [
396
                        'fields_groups' => [
397
                            'list' => ['bar', 'baz', 'john', 'doe'],
398
                            'default' => 'bar',
399
                        ],
400
                    ],
401
                    'anotherone' => null,
402
                ],
403
                [
404
                    'foo' => [
405
                        'fields_groups' => [
406
                            'list' => ['bar', 'baz', 'john', 'doe'],
407
                            'default' => 'bar',
408
                        ],
409
                    ],
410
                    'anotherone' => [
411
                        'fields_groups' => [
412
                            'list' => ['content', 'metadata'],
413
                            'default' => '%ezsettings.default.content.field_groups.default%',
414
                        ],
415
                    ],
416
                ],
417
            ],
418
            //items with only one field configured
419
            [
420
                [
421
                    'foo' => [
422
                        'fields_groups' => [
423
                            'list' => ['bar', 'baz', 'john'],
424
                        ],
425
                    ],
426
                    'bar' => [
427
                        'fields_groups' => [
428
                            'default' => 'metadata',
429
                        ],
430
                    ],
431
                ],
432
                [
433
                    'foo' => [
434
                        'fields_groups' => [
435
                            'list' => ['bar', 'baz', 'john'],
436
                            'default' => '%ezsettings.default.content.field_groups.default%',
437
                        ],
438
                    ],
439
                    'bar' => [
440
                        'fields_groups' => [
441
                            'list' => ['content', 'metadata'],
442
                            'default' => 'metadata',
443
                        ],
444
                    ],
445
                ],
446
            ],
447
            //two different repositories
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
                    'foo' => [
465
                        'fields_groups' => [
466
                            'list' => ['bar', 'baz', 'john', 'doe'],
467
                            'default' => 'bar',
468
                        ],
469
                    ],
470
                    'bar' => [
471
                        'fields_groups' => [
472
                            'list' => ['lorem', 'ipsum'],
473
                            'default' => 'lorem',
474
                        ],
475
                    ],
476
                ],
477
            ],
478
        ];
479
    }
480
481
    public function testRepositoriesConfigurationEmpty()
482
    {
483
        $repositories = array(
484
            'main' => null,
485
        );
486
        $expectedRepositories = array(
487
            'main' => array(
488
                'storage' => array(
489
                    'engine' => '%ezpublish.api.storage_engine.default%',
490
                    'connection' => null,
491
                    'config' => array(),
492
                ),
493
                'search' => array(
494
                    'engine' => '%ezpublish.api.search_engine.default%',
495
                    'connection' => null,
496
                    'config' => array(),
497
                ),
498
                'fields_groups' => array(
499
                    'list' => ['content', 'metadata'],
500
                    'default' => '%ezsettings.default.content.field_groups.default%',
501
                ),
502
                'options' => [
503
                    'default_version_archive_limit' => 5,
504
                ],
505
            ),
506
        );
507
        $this->load(array('repositories' => $repositories));
508
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
509
510
        $this->assertSame(
511
            $expectedRepositories,
512
            $this->container->getParameter('ezpublish.repositories')
513
        );
514
    }
515
516 View Code Duplication
    public function testRepositoriesConfigurationStorageEmpty()
517
    {
518
        $repositories = array(
519
            'main' => array(
520
                'search' => array(
521
                    'engine' => 'fantasticfind',
522
                    'connection' => 'french',
523
                ),
524
            ),
525
        );
526
        $expectedRepositories = array(
527
            'main' => array(
528
                'search' => array(
529
                    'engine' => 'fantasticfind',
530
                    'connection' => 'french',
531
                    'config' => array(),
532
                ),
533
                'storage' => array(
534
                    'engine' => '%ezpublish.api.storage_engine.default%',
535
                    'connection' => null,
536
                    'config' => array(),
537
                ),
538
                'fields_groups' => array(
539
                    'list' => ['content', 'metadata'],
540
                    'default' => '%ezsettings.default.content.field_groups.default%',
541
                ),
542
                'options' => [
543
                    'default_version_archive_limit' => 5,
544
                ],
545
            ),
546
        );
547
        $this->load(array('repositories' => $repositories));
548
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
549
550
        $this->assertSame(
551
            $expectedRepositories,
552
            $this->container->getParameter('ezpublish.repositories')
553
        );
554
    }
555
556 View Code Duplication
    public function testRepositoriesConfigurationSearchEmpty()
557
    {
558
        $repositories = array(
559
            'main' => array(
560
                'storage' => array(
561
                    'engine' => 'persistentprudence',
562
                    'connection' => 'yes',
563
                ),
564
            ),
565
        );
566
        $expectedRepositories = array(
567
            'main' => array(
568
                'storage' => array(
569
                    'engine' => 'persistentprudence',
570
                    'connection' => 'yes',
571
                    'config' => array(),
572
                ),
573
                'search' => array(
574
                    'engine' => '%ezpublish.api.search_engine.default%',
575
                    'connection' => null,
576
                    'config' => array(),
577
                ),
578
                'fields_groups' => array(
579
                    'list' => ['content', 'metadata'],
580
                    'default' => '%ezsettings.default.content.field_groups.default%',
581
                ),
582
                'options' => [
583
                    'default_version_archive_limit' => 5,
584
                ],
585
            ),
586
        );
587
        $this->load(array('repositories' => $repositories));
588
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
589
590
        $this->assertSame(
591
            $expectedRepositories,
592
            $this->container->getParameter('ezpublish.repositories')
593
        );
594
    }
595
596
    public function testRepositoriesConfigurationCompatibility()
597
    {
598
        $repositories = array(
599
            'main' => array(
600
                'engine' => 'legacy',
601
                'connection' => 'default',
602
                'search' => array(
603
                    'engine' => 'elasticsearch',
604
                    'connection' => 'blabla',
605
                ),
606
            ),
607
            'foo' => array(
608
                'engine' => 'sqlng',
609
                'connection' => 'default',
610
                'search' => array(
611
                    'engine' => 'solr',
612
                    'connection' => 'lalala',
613
                ),
614
            ),
615
        );
616
        $expectedRepositories = array(
617
            'main' => array(
618
                'search' => array(
619
                    'engine' => 'elasticsearch',
620
                    'connection' => 'blabla',
621
                    'config' => array(),
622
                ),
623
                'storage' => array(
624
                    'engine' => 'legacy',
625
                    'connection' => 'default',
626
                    'config' => array(),
627
                ),
628
                'fields_groups' => array(
629
                    'list' => ['content', 'metadata'],
630
                    'default' => '%ezsettings.default.content.field_groups.default%',
631
                ),
632
                'options' => [
633
                    'default_version_archive_limit' => 5,
634
                ],
635
            ),
636
            'foo' => array(
637
                'search' => array(
638
                    'engine' => 'solr',
639
                    'connection' => 'lalala',
640
                    'config' => array(),
641
                ),
642
                'storage' => array(
643
                    'engine' => 'sqlng',
644
                    'connection' => 'default',
645
                    'config' => array(),
646
                ),
647
                'fields_groups' => array(
648
                    'list' => ['content', 'metadata'],
649
                    'default' => '%ezsettings.default.content.field_groups.default%',
650
                ),
651
                'options' => [
652
                    'default_version_archive_limit' => 5,
653
                ],
654
            ),
655
        );
656
        $this->load(array('repositories' => $repositories));
657
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
658
659
        $this->assertSame(
660
            $expectedRepositories,
661
            $this->container->getParameter('ezpublish.repositories')
662
        );
663
    }
664
665 View Code Duplication
    public function testRepositoriesConfigurationCompatibility2()
666
    {
667
        $repositories = array(
668
            'main' => array(
669
                'engine' => 'legacy',
670
                'connection' => 'default',
671
            ),
672
        );
673
        $expectedRepositories = array(
674
            'main' => array(
675
                'storage' => array(
676
                    'engine' => 'legacy',
677
                    'connection' => 'default',
678
                    'config' => array(),
679
                ),
680
                'search' => array(
681
                    'engine' => '%ezpublish.api.search_engine.default%',
682
                    'connection' => null,
683
                    'config' => array(),
684
                ),
685
                'fields_groups' => array(
686
                    'list' => ['content', 'metadata'],
687
                    'default' => '%ezsettings.default.content.field_groups.default%',
688
                ),
689
                'options' => [
690
                    'default_version_archive_limit' => 5,
691
                ],
692
            ),
693
        );
694
        $this->load(array('repositories' => $repositories));
695
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
696
697
        $this->assertSame(
698
            $expectedRepositories,
699
            $this->container->getParameter('ezpublish.repositories')
700
        );
701
    }
702
703
    public function testRelatedSiteAccesses()
704
    {
705
        $mainRepo = 'main';
706
        $fooRepo = 'foo';
707
        $rootLocationId1 = 123;
708
        $rootLocationId2 = 456;
709
        $rootLocationId3 = 2;
710
        $config = array(
711
            'siteaccess' => array(
712
                'default_siteaccess' => 'ezdemo_site',
713
                'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site2', 'eng2', 'ezdemo_site3', 'fre3'),
714
                'groups' => array(
715
                    'ezdemo_group' => array('ezdemo_site', 'eng', 'fre'),
716
                    'ezdemo_group2' => array('ezdemo_site2', 'eng2'),
717
                    'ezdemo_group3' => array('ezdemo_site3', 'fre3'),
718
                ),
719
                'match' => array(),
720
            ),
721
            'repositories' => array(
722
                $mainRepo => array('engine' => 'legacy', 'connection' => 'default'),
723
                $fooRepo => array('engine' => 'bar', 'connection' => 'blabla'),
724
            ),
725
            'system' => array(
726
                'ezdemo_group' => array(
727
                    'repository' => $mainRepo,
728
                    'content' => array(
729
                        'tree_root' => array('location_id' => $rootLocationId1),
730
                    ),
731
                ),
732
                'ezdemo_group2' => array(
733
                    'repository' => $mainRepo,
734
                    'content' => array(
735
                        'tree_root' => array('location_id' => $rootLocationId2),
736
                    ),
737
                ),
738
                'ezdemo_group3' => array(
739
                    'repository' => $fooRepo,
740
                ),
741
            ),
742
        ) + $this->siteaccessConfig;
743
744
        // Injecting needed config parsers.
745
        $refExtension = new ReflectionObject($this->extension);
746
        $refMethod = $refExtension->getMethod('getMainConfigParser');
747
        $refMethod->setAccessible(true);
748
        $refMethod->invoke($this->extension);
749
        $refParser = $refExtension->getProperty('mainConfigParser');
750
        $refParser->setAccessible(true);
751
        /** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */
752
        $parser = $refParser->getValue($this->extension);
753
        $parser->setConfigParsers(array(new Common(), new Content()));
754
755
        $this->load($config);
756
757
        $relatedSiteAccesses1 = array('ezdemo_site', 'eng', 'fre');
758
        $relatedSiteAccesses2 = array('ezdemo_site2', 'eng2');
759
        $relatedSiteAccesses3 = array('ezdemo_site3', 'fre3');
760
        $expectedRelationMap = array(
761
            $mainRepo => array(
762
                $rootLocationId1 => $relatedSiteAccesses1,
763
                $rootLocationId2 => $relatedSiteAccesses2,
764
            ),
765
            $fooRepo => array(
766
                $rootLocationId3 => $relatedSiteAccesses3,
767
            ),
768
        );
769
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.relation_map', $expectedRelationMap);
770
771
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses1);
772
        $this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses1);
773
        $this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses1);
774
775
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site2.related_siteaccesses', $relatedSiteAccesses2);
776
        $this->assertContainerBuilderHasParameter('ezsettings.eng2.related_siteaccesses', $relatedSiteAccesses2);
777
778
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site3.related_siteaccesses', $relatedSiteAccesses3);
779
        $this->assertContainerBuilderHasParameter('ezsettings.fre3.related_siteaccesses', $relatedSiteAccesses3);
780
    }
781
782
    public function testRegisteredPolicies()
783
    {
784
        $policies1 = [
785
            'custom_module' => [
786
                'custom_function_1' => null,
787
                'custom_function_2' => ['CustomLimitation'],
788
            ],
789
            'helloworld' => [
790
                'foo' => ['bar'],
791
                'baz' => null,
792
            ],
793
        ];
794
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies1));
795
796
        $policies2 = [
797
            'custom_module2' => [
798
                'custom_function_3' => null,
799
                'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'],
800
            ],
801
            'helloworld' => [
802
                'foo' => ['additional_limitation'],
803
                'some' => ['thingy', 'thing', 'but', 'wait'],
804
            ],
805
        ];
806
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies2));
807
808
        $expectedPolicies = [
809
            'custom_module' => [
810
                'custom_function_1' => [],
811
                'custom_function_2' => ['CustomLimitation' => true],
812
            ],
813
            'helloworld' => [
814
                'foo' => ['bar' => true, 'additional_limitation' => true],
815
                'baz' => [],
816
                'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true],
817
            ],
818
            'custom_module2' => [
819
                'custom_function_3' => [],
820
                'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true],
821
            ],
822
        ];
823
824
        $this->load();
825
826
        self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map');
827
        self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map'));
828
    }
829
830
    /**
831
     * Test RichText Semantic Configuration.
832
     */
833
    public function testRichTextConfiguration()
834
    {
835
        $config = Yaml::parse(
836
            file_get_contents(__DIR__ . '/Fixtures/FieldType/RichText/ezrichtext.yml')
837
        );
838
        $this->load($config);
839
840
        // Validate Custom Tags
841
        $this->assertTrue(
842
            $this->container->hasParameter($this->extension::RICHTEXT_CUSTOM_TAGS_PARAMETER)
843
        );
844
        $expectedCustomTagsConfig = [
845
            'video' => [
846
                'template' => 'MyBundle:FieldType/RichText/tag:video.html.twig',
847
                'icon' => '/bundles/mybundle/fieldtype/richtext/video.svg#video',
848
                'attributes' => [
849
                    'title' => [
850
                        'type' => 'string',
851
                        'required' => true,
852
                        'default_value' => 'abc',
853
                    ],
854
                    'width' => [
855
                        'type' => 'number',
856
                        'required' => true,
857
                        'default_value' => 360,
858
                    ],
859
                    'autoplay' => [
860
                        'type' => 'boolean',
861
                        'required' => false,
862
                        'default_value' => null,
863
                    ],
864
                ],
865
            ],
866
            'equation' => [
867
                'template' => 'MyBundle:FieldType/RichText/tag:equation.html.twig',
868
                'icon' => '/bundles/mybundle/fieldtype/richtext/equation.svg#equation',
869
                'attributes' => [
870
                    'name' => [
871
                        'type' => 'string',
872
                        'required' => true,
873
                        'default_value' => 'Equation',
874
                    ],
875
                    'processor' => [
876
                        'type' => 'choice',
877
                        'required' => true,
878
                        'default_value' => 'latex',
879
                        'choices' => ['latex', 'tex'],
880
                    ],
881
                ],
882
            ],
883
        ];
884
885
        $this->assertSame(
886
            $expectedCustomTagsConfig,
887
            $this->container->getParameter($this->extension::RICHTEXT_CUSTOM_TAGS_PARAMETER)
888
        );
889
    }
890
}
891