1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the ConfigParserTest 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\Configuration; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ConfigParser; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\ParserInterface; |
13
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface; |
14
|
|
|
use PHPUnit\Framework\TestCase; |
15
|
|
|
use stdClass; |
16
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
17
|
|
|
|
18
|
|
|
class ConfigParserTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\InvalidArgumentType |
22
|
|
|
*/ |
23
|
|
|
public function testConstructWrongInnerParser() |
24
|
|
|
{ |
25
|
|
|
new ConfigParser( |
26
|
|
|
array( |
27
|
|
|
$this->getConfigurationParserMock(), |
28
|
|
|
new stdClass(), |
29
|
|
|
) |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function testConstruct() |
34
|
|
|
{ |
35
|
|
|
$innerParsers = array( |
36
|
|
|
$this->getConfigurationParserMock(), |
37
|
|
|
$this->getConfigurationParserMock(), |
38
|
|
|
$this->getConfigurationParserMock(), |
39
|
|
|
); |
40
|
|
|
$configParser = new ConfigParser($innerParsers); |
41
|
|
|
$this->assertSame($innerParsers, $configParser->getConfigParsers()); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testGetSetInnerParsers() |
45
|
|
|
{ |
46
|
|
|
$configParser = new ConfigParser(); |
47
|
|
|
$this->assertSame(array(), $configParser->getConfigParsers()); |
48
|
|
|
|
49
|
|
|
$innerParsers = array( |
50
|
|
|
$this->getConfigurationParserMock(), |
51
|
|
|
$this->getConfigurationParserMock(), |
52
|
|
|
$this->getConfigurationParserMock(), |
53
|
|
|
); |
54
|
|
|
$configParser->setConfigParsers($innerParsers); |
55
|
|
|
$this->assertSame($innerParsers, $configParser->getConfigParsers()); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function testMapConfig() |
59
|
|
|
{ |
60
|
|
|
$parsers = array( |
61
|
|
|
$this->getConfigurationParserMock(), |
62
|
|
|
$this->getConfigurationParserMock(), |
63
|
|
|
); |
64
|
|
|
$configParser = new ConfigParser($parsers); |
65
|
|
|
|
66
|
|
|
$scopeSettings = array( |
67
|
|
|
'foo' => 'bar', |
68
|
|
|
'some' => 'thing', |
69
|
|
|
); |
70
|
|
|
$currentScope = 'the_current_scope'; |
71
|
|
|
$contextualizer = $this->createMock(ContextualizerInterface::class); |
72
|
|
|
|
73
|
|
|
foreach ($parsers as $parser) { |
74
|
|
|
/* @var \PHPUnit_Framework_MockObject_MockObject $parser */ |
75
|
|
|
$parser |
76
|
|
|
->expects($this->once()) |
77
|
|
|
->method('mapConfig') |
78
|
|
|
->with($scopeSettings, $currentScope, $contextualizer); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$configParser->mapConfig($scopeSettings, $currentScope, $contextualizer); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testPrePostMap() |
85
|
|
|
{ |
86
|
|
|
$parsers = array( |
87
|
|
|
$this->getConfigurationParserMock(), |
88
|
|
|
$this->getConfigurationParserMock(), |
89
|
|
|
); |
90
|
|
|
$configParser = new ConfigParser($parsers); |
91
|
|
|
|
92
|
|
|
$config = array( |
93
|
|
|
'foo' => 'bar', |
94
|
|
|
'some' => 'thing', |
95
|
|
|
); |
96
|
|
|
$contextualizer = $this->createMock(ContextualizerInterface::class); |
97
|
|
|
|
98
|
|
|
foreach ($parsers as $parser) { |
99
|
|
|
/* @var \PHPUnit_Framework_MockObject_MockObject $parser */ |
100
|
|
|
$parser |
101
|
|
|
->expects($this->once()) |
102
|
|
|
->method('preMap') |
103
|
|
|
->with($config, $contextualizer); |
104
|
|
|
$parser |
105
|
|
|
->expects($this->once()) |
106
|
|
|
->method('postMap') |
107
|
|
|
->with($config, $contextualizer); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
$configParser->preMap($config, $contextualizer); |
111
|
|
|
$configParser->postMap($config, $contextualizer); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testAddSemanticConfig() |
115
|
|
|
{ |
116
|
|
|
$parsers = array( |
117
|
|
|
$this->getConfigurationParserMock(), |
118
|
|
|
$this->getConfigurationParserMock(), |
119
|
|
|
); |
120
|
|
|
$configParser = new ConfigParser($parsers); |
121
|
|
|
|
122
|
|
|
$nodeBuilder = new NodeBuilder(); |
123
|
|
|
|
124
|
|
|
foreach ($parsers as $parser) { |
125
|
|
|
/* @var \PHPUnit_Framework_MockObject_MockObject $parser */ |
126
|
|
|
$parser |
127
|
|
|
->expects($this->once()) |
128
|
|
|
->method('addSemanticConfig') |
129
|
|
|
->with($nodeBuilder); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$configParser->addSemanticConfig($nodeBuilder); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
protected function getConfigurationParserMock() |
136
|
|
|
{ |
137
|
|
|
return $this->createMock(ParserInterface::class); |
138
|
|
|
} |
139
|
|
|
} |
140
|
|
|
|