|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
5
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace eZ\Bundle\EzPublishCoreBundle\Tests\DependencyInjection\Compiler; |
|
8
|
|
|
|
|
9
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Compiler\SlugConverterConfigurationPass; |
|
10
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter; |
|
11
|
|
|
use eZ\Publish\Core\Persistence\TransformationProcessor; |
|
12
|
|
|
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractCompilerPassTestCase; |
|
13
|
|
|
use ReflectionClass; |
|
14
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\Definition; |
|
16
|
|
|
|
|
17
|
|
|
class SlugConverterConfigurationPassTest extends AbstractCompilerPassTestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function registerCompilerPass(ContainerBuilder $container) |
|
23
|
|
|
{ |
|
24
|
|
|
$container->addCompilerPass(new SlugConverterConfigurationPass()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @dataProvider configurationProvider |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $commandsToAdd |
|
31
|
|
|
* @param array $existingOldParameters |
|
32
|
|
|
* @param array $expectedCommands |
|
33
|
|
|
* |
|
34
|
|
|
* @throws \ReflectionException |
|
35
|
|
|
*/ |
|
36
|
|
|
public function testMergeConfigurations( |
|
37
|
|
|
array $commandsToAdd, |
|
38
|
|
|
array $existingOldParameters, |
|
39
|
|
|
array $expectedCommands |
|
40
|
|
|
) { |
|
41
|
|
|
$definition = new Definition(SlugConverter::class); |
|
42
|
|
|
$definition->setArgument(0, $this->createMock(TransformationProcessor::class)); |
|
43
|
|
|
$definition->setArgument(1, $existingOldParameters); |
|
44
|
|
|
|
|
45
|
|
|
$this->setDefinition('ezpublish.persistence.slug_converter', $definition); |
|
46
|
|
|
|
|
47
|
|
|
$this->setParameter('ezpublish.url_alias.slug_converter', [ |
|
48
|
|
|
'transformation' => 'urlalias', |
|
49
|
|
|
'separator' => 'underscore', |
|
50
|
|
|
'transformation_groups' => [ |
|
51
|
|
|
'urlalias' => [ |
|
52
|
|
|
'commands' => $commandsToAdd, |
|
53
|
|
|
'cleanup_method' => 'url_cleanup', |
|
54
|
|
|
], |
|
55
|
|
|
], |
|
56
|
|
|
]); |
|
57
|
|
|
$this->compile(); |
|
58
|
|
|
|
|
59
|
|
|
/** @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter $slugConverter */ |
|
60
|
|
|
$slugConverterRef = new ReflectionClass(SlugConverter::class); |
|
61
|
|
|
$configurationPropertyRef = $slugConverterRef->getProperty('configuration'); |
|
62
|
|
|
$configurationPropertyRef->setAccessible(true); |
|
63
|
|
|
$configuration = $configurationPropertyRef->getValue($this->container->get('ezpublish.persistence.slug_converter')); |
|
64
|
|
|
|
|
65
|
|
|
$this->assertEquals('urlalias', $configuration['transformation']); |
|
66
|
|
|
$this->assertEquals('underscore', $configuration['wordSeparatorName']); |
|
67
|
|
|
$this->assertEquals($expectedCommands, $configuration['transformationGroups']['urlalias']['commands']); |
|
68
|
|
|
$this->assertEquals('url_cleanup', $configuration['transformationGroups']['urlalias']['cleanupMethod']); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function configurationProvider() |
|
72
|
|
|
{ |
|
73
|
|
|
$injectedBySemanticCommands = [ |
|
74
|
|
|
'new_command_to_add', |
|
75
|
|
|
'second_new_command_to_add', |
|
76
|
|
|
]; |
|
77
|
|
|
|
|
78
|
|
|
$injectedByParameterCommands = [ |
|
79
|
|
|
'injected_command', |
|
80
|
|
|
]; |
|
81
|
|
|
|
|
82
|
|
|
return [ |
|
83
|
|
|
[ |
|
84
|
|
|
$injectedBySemanticCommands, |
|
85
|
|
|
[], |
|
86
|
|
|
array_merge( |
|
87
|
|
|
SlugConverter::DEFAULT_CONFIGURATION['transformationGroups']['urlalias']['commands'], |
|
88
|
|
|
$injectedBySemanticCommands |
|
89
|
|
|
), |
|
90
|
|
|
], |
|
91
|
|
|
[ |
|
92
|
|
|
$injectedBySemanticCommands, |
|
93
|
|
|
[ |
|
94
|
|
|
'transformation' => 'urlalias_lowercase', |
|
95
|
|
|
'transformationGroups' => [ |
|
96
|
|
|
'urlalias' => [ |
|
97
|
|
|
'commands' => $injectedByParameterCommands, |
|
98
|
|
|
'cleanupMethod' => 'url_cleanup', |
|
99
|
|
|
], |
|
100
|
|
|
], |
|
101
|
|
|
'wordSeparatorName' => 'dash', |
|
102
|
|
|
], |
|
103
|
|
|
array_merge( |
|
104
|
|
|
['injected_command'], |
|
105
|
|
|
$injectedBySemanticCommands |
|
106
|
|
|
), |
|
107
|
|
|
], |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|