Completed
Push — test-fieldrelation-location-se... ( 448993...a417bd )
by
unknown
13:37
created

testLocaleConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 9.4285
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
 * @version //autogentag//
10
 */
11
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection;
12
13
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Common;
14
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Content;
15
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension;
16
use eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Stub\StubPolicyProvider;
17
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;
18
use Symfony\Component\DependencyInjection\Definition;
19
use Symfony\Component\Yaml\Yaml;
20
use ReflectionObject;
21
22
class EzPublishCoreExtensionTest extends AbstractExtensionTestCase
23
{
24
    private $minimalConfig = array();
25
26
    private $siteaccessConfig = array();
27
28
    /**
29
     * @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension
30
     */
31
    private $extension;
32
33
    protected function setUp()
34
    {
35
        $this->extension = new EzPublishCoreExtension();
36
        $this->siteaccessConfig = array(
37
            'siteaccess' => array(
38
                'default_siteaccess' => 'ezdemo_site',
39
                'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'),
40
                'groups' => array(
41
                    'ezdemo_group' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin'),
42
                    'ezdemo_frontend_group' => array('ezdemo_site', 'eng', 'fre'),
43
                ),
44
                'match' => array(
45
                    'URILElement' => 1,
46
                    'Map\URI' => array('the_front' => 'ezdemo_site', 'the_back' => 'ezdemo_site_admin'),
47
                ),
48
            ),
49
            'system' => array(
50
                'ezdemo_site' => array(),
51
                'eng' => array(),
52
                'fre' => array(),
53
                'ezdemo_site_admin' => array(),
54
            ),
55
        );
56
57
        parent::setUp();
58
    }
59
60
    protected function getContainerExtensions()
61
    {
62
        return array($this->extension);
63
    }
64
65
    protected function getMinimalConfiguration()
66
    {
67
        return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/Fixtures/ezpublish_minimal_no_siteaccess.yml'));
0 ignored issues
show
Documentation Bug introduced by
It seems like \Symfony\Component\Yaml\...al_no_siteaccess.yml')) can also be of type string or object<stdClass>. However, the property $minimalConfig is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

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

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

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

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

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

Loading history...
103
            foreach ($groupMembers as $member) {
104
                if (!isset($groupsBySiteaccess[$member])) {
105
                    $groupsBySiteaccess[$member] = array();
106
                }
107
108
                $groupsBySiteaccess[$member][] = $groupName;
109
            }
110
        }
111
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', $groupsBySiteaccess);
112
113
        $relatedSiteAccesses = array('ezdemo_site', 'eng', 'fre', 'ezdemo_site_admin');
114
        $this->assertContainerBuilderHasParameter(
115
            'ezpublish.siteaccess.relation_map',
116
            array(
117
                // Empty string is the default repository name
118
                '' => array(
119
                    // 2 is the default rootLocationId
120
                    2 => $relatedSiteAccesses,
121
                ),
122
            )
123
        );
124
125
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses);
126
        $this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses);
127
        $this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses);
128
    }
129
130
    public function testSiteAccessNoConfiguration()
131
    {
132
        $this->load();
133
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.list', array('setup'));
134
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.default', 'setup');
135
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups', array());
136
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.groups_by_siteaccess', array());
137
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.match_config', null);
138
    }
139
140
    public function testImageMagickConfigurationBasic()
141
    {
142 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...
143
            $this->markTestSkipped('Missing or mis-configured Imagemagick convert path.');
144
        }
145
146
        $this->load(
147
            array(
148
                'imagemagick' => array(
149
                    'enabled' => true,
150
                    'path' => $_ENV['imagemagickConvertPath'],
151
                ),
152
            )
153
        );
154
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.enabled', true);
155
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable_path', dirname($_ENV['imagemagickConvertPath']));
156
        $this->assertContainerBuilderHasParameter('ezpublish.image.imagemagick.executable', basename($_ENV['imagemagickConvertPath']));
157
    }
158
159
    public function testImageMagickConfigurationFilters()
160
    {
161 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...
162
            $this->markTestSkipped('Missing or mis-configured Imagemagick convert path.');
163
        }
164
165
        $customFilters = array(
166
            'foobar' => '-foobar',
167
            'wow' => '-amazing',
168
        );
169
        $this->load(
170
            array(
171
                'imagemagick' => array(
172
                    'enabled' => true,
173
                    'path' => $_ENV['imagemagickConvertPath'],
174
                    'filters' => $customFilters,
175
                ),
176
            )
177
        );
178
        $this->assertTrue($this->container->hasParameter('ezpublish.image.imagemagick.filters'));
179
        $filters = $this->container->getParameter('ezpublish.image.imagemagick.filters');
180
        $this->assertArrayHasKey('foobar', $filters);
181
        $this->assertSame($customFilters['foobar'], $filters['foobar']);
182
        $this->assertArrayHasKey('wow', $filters);
183
        $this->assertSame($customFilters['wow'], $filters['wow']);
184
    }
185
186
    public function testEzPageConfiguration()
187
    {
188
        $customLayouts = array(
189
            'FoobarLayout' => array('name' => 'Foo layout', 'template' => 'foolayout.html.twig'),
190
        );
191
        $enabledLayouts = array('FoobarLayout', 'GlobalZoneLayout');
192
        $customBlocks = array(
193
            'FoobarBlock' => array('name' => 'Foo block'),
194
        );
195
        $enabledBlocks = array('FoobarBlock', 'DemoBlock');
196
        $this->load(
197
            array(
198
                'ezpage' => array(
199
                    'layouts' => $customLayouts,
200
                    'blocks' => $customBlocks,
201
                    'enabledLayouts' => $enabledLayouts,
202
                    'enabledBlocks' => $enabledBlocks,
203
                ),
204
            )
205
        );
206
207
        $this->assertTrue($this->container->hasParameter('ezpublish.ezpage.layouts'));
208
        $layouts = $this->container->getParameter('ezpublish.ezpage.layouts');
209
        $this->assertArrayHasKey('FoobarLayout', $layouts);
210
        $this->assertSame($customLayouts['FoobarLayout'], $layouts['FoobarLayout']);
211
        $this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledLayouts', $enabledLayouts);
212
213
        $this->assertTrue($this->container->hasParameter('ezpublish.ezpage.blocks'));
214
        $blocks = $this->container->getParameter('ezpublish.ezpage.blocks');
215
        $this->assertArrayHasKey('FoobarBlock', $blocks);
216
        $this->assertSame($customBlocks['FoobarBlock'], $blocks['FoobarBlock']);
217
        $this->assertContainerBuilderHasParameter('ezpublish.ezpage.enabledBlocks', $enabledBlocks);
218
    }
219
220
    public function testRoutingConfiguration()
221
    {
222
        $this->load();
223
        $this->assertContainerBuilderHasAlias('router', 'ezpublish.chain_router');
224
225
        $this->assertTrue($this->container->hasParameter('ezpublish.default_router.non_siteaccess_aware_routes'));
226
        $nonSiteaccessAwareRoutes = $this->container->getParameter('ezpublish.default_router.non_siteaccess_aware_routes');
227
        // See ezpublish_minimal_no_siteaccess.yml fixture
228
        $this->assertContains('foo_route', $nonSiteaccessAwareRoutes);
229
        $this->assertContains('my_prefix_', $nonSiteaccessAwareRoutes);
230
    }
231
232
    /**
233
     * @dataProvider cacheConfigurationProvider
234
     *
235
     * @param array $customCacheConfig
236
     * @param string $expectedPurgeService
237
     * @param int $expectedTimeout
0 ignored issues
show
Bug introduced by
There is no parameter named $expectedTimeout. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
238
     */
239
    public function testCacheConfiguration(array $customCacheConfig, $expectedPurgeService)
240
    {
241
        $this->load($customCacheConfig);
242
243
        $this->assertContainerBuilderHasAlias('ezpublish.http_cache.purge_client', $expectedPurgeService);
244
    }
245
246
    public function cacheConfigurationProvider()
247
    {
248
        return array(
249
            array(array(), 'ezpublish.http_cache.purge_client.local', 1),
250
            array(
251
                array(
252
                    'http_cache' => array('purge_type' => 'local'),
253
                ),
254
                'ezpublish.http_cache.purge_client.local',
255
            ),
256
            array(
257
                array(
258
                    'http_cache' => array('purge_type' => 'multiple_http'),
259
                ),
260
                'ezpublish.http_cache.purge_client.fos',
261
            ),
262
            array(
263
                array(
264
                    'http_cache' => array('purge_type' => 'single_http'),
265
                ),
266
                'ezpublish.http_cache.purge_client.fos',
267
            ),
268
            array(
269
                array(
270
                    'http_cache' => array('purge_type' => 'http'),
271
                ),
272
                'ezpublish.http_cache.purge_client.fos',
273
            ),
274
        );
275
    }
276
277
    /**
278
     * @expectedException \InvalidArgumentException
279
     */
280
    public function testCacheConfigurationWrongPurgeType()
281
    {
282
        $this->load(
283
            array(
284
                'http_cache' => array('purge_type' => 'foobar', 'timeout' => 12),
285
            )
286
        );
287
    }
288
289
    public function testCacheConfigurationCustomPurgeService()
290
    {
291
        $serviceId = 'foobar';
292
        $this->setDefinition($serviceId, new Definition());
293
        $this->load(
294
            array(
295
                'http_cache' => array('purge_type' => 'foobar', 'timeout' => 12),
296
            )
297
        );
298
    }
299
300
    public function testLocaleConfiguration()
301
    {
302
        $this->load(array('locale_conversion' => array('foo' => 'bar')));
303
        $conversionMap = $this->container->getParameter('ezpublish.locale.conversion_map');
304
        $this->assertArrayHasKey('foo', $conversionMap);
305
        $this->assertSame('bar', $conversionMap['foo']);
306
    }
307
308
    public function testRepositoriesConfiguration()
309
    {
310
        $repositories = array(
311
            'main' => array(
312
                'storage' => array(
313
                    'engine' => 'legacy',
314
                    'connection' => 'default',
315
                ),
316
                'search' => array(
317
                    'engine' => 'elasticsearch',
318
                    'connection' => 'blabla',
319
                ),
320
                'fields_groups' => array(
321
                    'list' => ['content'],
322
                    'default' => 'content',
323
                ),
324
            ),
325
            'foo' => array(
326
                'storage' => array(
327
                    'engine' => 'sqlng',
328
                    'connection' => 'default',
329
                ),
330
                'search' => array(
331
                    'engine' => 'solr',
332
                    'connection' => 'lalala',
333
                ),
334
                'fields_groups' => array(
335
                    'list' => ['content'],
336
                    'default' => 'content',
337
                ),
338
            ),
339
        );
340
        $this->load(array('repositories' => $repositories));
341
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
342
343
        foreach ($repositories as &$repositoryConfig) {
344
            $repositoryConfig['storage']['config'] = array();
345
            $repositoryConfig['search']['config'] = array();
346
        }
347
        $this->assertSame($repositories, $this->container->getParameter('ezpublish.repositories'));
348
    }
349
350
    public function testRepositoriesConfigurationEmpty()
351
    {
352
        $repositories = array(
353
            'main' => null,
354
        );
355
        $expectedRepositories = array(
356
            'main' => array(
357
                'storage' => array(
358
                    'engine' => '%ezpublish.api.storage_engine.default%',
359
                    'connection' => null,
360
                    'config' => array(),
361
                ),
362
                'search' => array(
363
                    'engine' => '%ezpublish.api.search_engine.default%',
364
                    'connection' => null,
365
                    'config' => array(),
366
                ),
367
                'fields_groups' => array(
368
                    'list' => ['content'],
369
                    'default' => 'content',
370
                ),
371
            ),
372
        );
373
        $this->load(array('repositories' => $repositories));
374
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
375
376
        $this->assertSame(
377
            $expectedRepositories,
378
            $this->container->getParameter('ezpublish.repositories')
379
        );
380
    }
381
382 View Code Duplication
    public function testRepositoriesConfigurationStorageEmpty()
383
    {
384
        $repositories = array(
385
            'main' => array(
386
                'search' => array(
387
                    'engine' => 'fantasticfind',
388
                    'connection' => 'french',
389
                ),
390
            ),
391
        );
392
        $expectedRepositories = array(
393
            'main' => array(
394
                'search' => array(
395
                    'engine' => 'fantasticfind',
396
                    'connection' => 'french',
397
                    'config' => array(),
398
                ),
399
                'storage' => array(
400
                    'engine' => '%ezpublish.api.storage_engine.default%',
401
                    'connection' => null,
402
                    'config' => array(),
403
                ),
404
                'fields_groups' => array(
405
                    'list' => ['content'],
406
                    'default' => 'content',
407
                ),
408
            ),
409
        );
410
        $this->load(array('repositories' => $repositories));
411
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
412
413
        $this->assertSame(
414
            $expectedRepositories,
415
            $this->container->getParameter('ezpublish.repositories')
416
        );
417
    }
418
419 View Code Duplication
    public function testRepositoriesConfigurationSearchEmpty()
420
    {
421
        $repositories = array(
422
            'main' => array(
423
                'storage' => array(
424
                    'engine' => 'persistentprudence',
425
                    'connection' => 'yes',
426
                ),
427
            ),
428
        );
429
        $expectedRepositories = array(
430
            'main' => array(
431
                'storage' => array(
432
                    'engine' => 'persistentprudence',
433
                    'connection' => 'yes',
434
                    'config' => array(),
435
                ),
436
                'search' => array(
437
                    'engine' => '%ezpublish.api.search_engine.default%',
438
                    'connection' => null,
439
                    'config' => array(),
440
                ),
441
                'fields_groups' => array(
442
                    'list' => ['content'],
443
                    'default' => 'content',
444
                ),
445
            ),
446
        );
447
        $this->load(array('repositories' => $repositories));
448
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
449
450
        $this->assertSame(
451
            $expectedRepositories,
452
            $this->container->getParameter('ezpublish.repositories')
453
        );
454
    }
455
456
    public function testRepositoriesConfigurationCompatibility()
457
    {
458
        $repositories = array(
459
            'main' => array(
460
                'engine' => 'legacy',
461
                'connection' => 'default',
462
                'search' => array(
463
                    'engine' => 'elasticsearch',
464
                    'connection' => 'blabla',
465
                ),
466
            ),
467
            'foo' => array(
468
                'engine' => 'sqlng',
469
                'connection' => 'default',
470
                'search' => array(
471
                    'engine' => 'solr',
472
                    'connection' => 'lalala',
473
                ),
474
            ),
475
        );
476
        $expectedRepositories = array(
477
            'main' => array(
478
                'search' => array(
479
                    'engine' => 'elasticsearch',
480
                    'connection' => 'blabla',
481
                    'config' => array(),
482
                ),
483
                'storage' => array(
484
                    'engine' => 'legacy',
485
                    'connection' => 'default',
486
                    'config' => array(),
487
                ),
488
                'fields_groups' => array(
489
                    'list' => ['content'],
490
                    'default' => 'content',
491
                ),
492
            ),
493
            'foo' => array(
494
                'search' => array(
495
                    'engine' => 'solr',
496
                    'connection' => 'lalala',
497
                    'config' => array(),
498
                ),
499
                'storage' => array(
500
                    'engine' => 'sqlng',
501
                    'connection' => 'default',
502
                    'config' => array(),
503
                ),
504
                'fields_groups' => array(
505
                    'list' => ['content'],
506
                    'default' => 'content',
507
                ),
508
            ),
509
        );
510
        $this->load(array('repositories' => $repositories));
511
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
512
513
        $this->assertSame(
514
            $expectedRepositories,
515
            $this->container->getParameter('ezpublish.repositories')
516
        );
517
    }
518
519 View Code Duplication
    public function testRepositoriesConfigurationCompatibility2()
520
    {
521
        $repositories = array(
522
            'main' => array(
523
                'engine' => 'legacy',
524
                'connection' => 'default',
525
            ),
526
        );
527
        $expectedRepositories = array(
528
            'main' => array(
529
                'storage' => array(
530
                    'engine' => 'legacy',
531
                    'connection' => 'default',
532
                    'config' => array(),
533
                ),
534
                'search' => array(
535
                    'engine' => '%ezpublish.api.search_engine.default%',
536
                    'connection' => null,
537
                    'config' => array(),
538
                ),
539
                'fields_groups' => array(
540
                    'list' => ['content'],
541
                    'default' => 'content',
542
                ),
543
            ),
544
        );
545
        $this->load(array('repositories' => $repositories));
546
        $this->assertTrue($this->container->hasParameter('ezpublish.repositories'));
547
548
        $this->assertSame(
549
            $expectedRepositories,
550
            $this->container->getParameter('ezpublish.repositories')
551
        );
552
    }
553
554
    public function testRelatedSiteAccesses()
555
    {
556
        $mainRepo = 'main';
557
        $fooRepo = 'foo';
558
        $rootLocationId1 = 123;
559
        $rootLocationId2 = 456;
560
        $rootLocationId3 = 2;
561
        $config = array(
562
            'siteaccess' => array(
563
                'default_siteaccess' => 'ezdemo_site',
564
                'list' => array('ezdemo_site', 'eng', 'fre', 'ezdemo_site2', 'eng2', 'ezdemo_site3', 'fre3'),
565
                'groups' => array(
566
                    'ezdemo_group' => array('ezdemo_site', 'eng', 'fre'),
567
                    'ezdemo_group2' => array('ezdemo_site2', 'eng2'),
568
                    'ezdemo_group3' => array('ezdemo_site3', 'fre3'),
569
                ),
570
                'match' => array(),
571
            ),
572
            'repositories' => array(
573
                $mainRepo => array('engine' => 'legacy', 'connection' => 'default'),
574
                $fooRepo => array('engine' => 'bar', 'connection' => 'blabla'),
575
            ),
576
            'system' => array(
577
                'ezdemo_group' => array(
578
                    'repository' => $mainRepo,
579
                    'content' => array(
580
                        'tree_root' => array('location_id' => $rootLocationId1),
581
                    ),
582
                ),
583
                'ezdemo_group2' => array(
584
                    'repository' => $mainRepo,
585
                    'content' => array(
586
                        'tree_root' => array('location_id' => $rootLocationId2),
587
                    ),
588
                ),
589
                'ezdemo_group3' => array(
590
                    'repository' => $fooRepo,
591
                ),
592
            ),
593
        ) + $this->siteaccessConfig;
594
595
        // Injecting needed config parsers.
596
        $refExtension = new ReflectionObject($this->extension);
597
        $refMethod = $refExtension->getMethod('getMainConfigParser');
598
        $refMethod->setAccessible(true);
599
        $refMethod->invoke($this->extension);
600
        $refParser = $refExtension->getProperty('mainConfigParser');
601
        $refParser->setAccessible(true);
602
        /** @var \eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser $parser */
603
        $parser = $refParser->getValue($this->extension);
604
        $parser->setConfigParsers(array(new Common(), new Content()));
605
606
        $this->load($config);
607
608
        $relatedSiteAccesses1 = array('ezdemo_site', 'eng', 'fre');
609
        $relatedSiteAccesses2 = array('ezdemo_site2', 'eng2');
610
        $relatedSiteAccesses3 = array('ezdemo_site3', 'fre3');
611
        $expectedRelationMap = array(
612
            $mainRepo => array(
613
                $rootLocationId1 => $relatedSiteAccesses1,
614
                $rootLocationId2 => $relatedSiteAccesses2,
615
            ),
616
            $fooRepo => array(
617
                $rootLocationId3 => $relatedSiteAccesses3,
618
            ),
619
        );
620
        $this->assertContainerBuilderHasParameter('ezpublish.siteaccess.relation_map', $expectedRelationMap);
621
622
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site.related_siteaccesses', $relatedSiteAccesses1);
623
        $this->assertContainerBuilderHasParameter('ezsettings.eng.related_siteaccesses', $relatedSiteAccesses1);
624
        $this->assertContainerBuilderHasParameter('ezsettings.fre.related_siteaccesses', $relatedSiteAccesses1);
625
626
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site2.related_siteaccesses', $relatedSiteAccesses2);
627
        $this->assertContainerBuilderHasParameter('ezsettings.eng2.related_siteaccesses', $relatedSiteAccesses2);
628
629
        $this->assertContainerBuilderHasParameter('ezsettings.ezdemo_site3.related_siteaccesses', $relatedSiteAccesses3);
630
        $this->assertContainerBuilderHasParameter('ezsettings.fre3.related_siteaccesses', $relatedSiteAccesses3);
631
    }
632
633
    public function testRegisteredPolicies()
634
    {
635
        $policies1 = [
636
            'custom_module' => [
637
                'custom_function_1' => null,
638
                'custom_function_2' => ['CustomLimitation'],
639
            ],
640
            'helloworld' => [
641
                'foo' => ['bar'],
642
                'baz' => null,
643
            ],
644
        ];
645
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies1));
646
647
        $policies2 = [
648
            'custom_module2' => [
649
                'custom_function_3' => null,
650
                'custom_function_4' => ['CustomLimitation2', 'CustomLimitation3'],
651
            ],
652
            'helloworld' => [
653
                'foo' => ['additional_limitation'],
654
                'some' => ['thingy', 'thing', 'but', 'wait'],
655
            ],
656
        ];
657
        $this->extension->addPolicyProvider(new StubPolicyProvider($policies2));
658
659
        $expectedPolicies = [
660
            'custom_module' => [
661
                'custom_function_1' => [],
662
                'custom_function_2' => ['CustomLimitation' => true],
663
            ],
664
            'helloworld' => [
665
                'foo' => ['bar' => true, 'additional_limitation' => true],
666
                'baz' => [],
667
                'some' => ['thingy' => true, 'thing' => true, 'but' => true, 'wait' => true],
668
            ],
669
            'custom_module2' => [
670
                'custom_function_3' => [],
671
                'custom_function_4' => ['CustomLimitation2' => true, 'CustomLimitation3' => true],
672
            ],
673
        ];
674
675
        $this->load();
676
677
        self::assertContainerBuilderHasParameter('ezpublish.api.role.policy_map');
678
        self::assertEquals($expectedPolicies, $this->container->getParameter('ezpublish.api.role.policy_map'));
679
    }
680
}
681