1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File containing the CommonTest 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\Parser; |
10
|
|
|
|
11
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Parser\Common; |
12
|
|
|
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\EzPublishCoreExtension; |
13
|
|
|
use Symfony\Component\Yaml\Yaml; |
14
|
|
|
|
15
|
|
|
class CommonTest extends AbstractParserTestCase |
16
|
|
|
{ |
17
|
|
|
private $minimalConfig; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject |
21
|
|
|
*/ |
22
|
|
|
private $suggestionCollector; |
23
|
|
|
|
24
|
|
|
protected function getContainerExtensions() |
25
|
|
|
{ |
26
|
|
|
$this->suggestionCollector = $this->getMock('eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\Suggestion\ConfigSuggestion\SuggestionCollectorInterface'); |
27
|
|
|
|
28
|
|
|
return array(new EzPublishCoreExtension(array(new Common()))); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
protected function getMinimalConfiguration() |
32
|
|
|
{ |
33
|
|
|
return $this->minimalConfig = Yaml::parse(file_get_contents(__DIR__ . '/../../Fixtures/ezpublish_minimal.yml')); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function testIndexPage() |
37
|
|
|
{ |
38
|
|
|
$indexPage1 = '/Getting-Started'; |
39
|
|
|
$indexPage2 = '/Contact-Us'; |
40
|
|
|
$config = array( |
41
|
|
|
'system' => array( |
42
|
|
|
'ezdemo_site' => array('index_page' => $indexPage1), |
43
|
|
|
'ezdemo_site_admin' => array('index_page' => $indexPage2), |
44
|
|
|
), |
45
|
|
|
); |
46
|
|
|
$this->load($config); |
47
|
|
|
|
48
|
|
|
$this->assertConfigResolverParameterValue('index_page', $indexPage1, 'ezdemo_site'); |
49
|
|
|
$this->assertConfigResolverParameterValue('index_page', $indexPage2, 'ezdemo_site_admin'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
View Code Duplication |
public function testDefaultPage() |
53
|
|
|
{ |
54
|
|
|
$defaultPage1 = '/Getting-Started'; |
55
|
|
|
$defaultPage2 = '/Foo/bar'; |
56
|
|
|
$config = array( |
57
|
|
|
'system' => array( |
58
|
|
|
'ezdemo_site' => array('default_page' => $defaultPage1), |
59
|
|
|
'ezdemo_site_admin' => array('default_page' => $defaultPage2), |
60
|
|
|
), |
61
|
|
|
); |
62
|
|
|
$this->load($config); |
63
|
|
|
|
64
|
|
|
$this->assertConfigResolverParameterValue('default_page', $defaultPage1, 'ezdemo_site'); |
65
|
|
|
$this->assertConfigResolverParameterValue('default_page', $defaultPage2, 'ezdemo_site_admin'); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @expectedException \InvalidArgumentException |
70
|
|
|
*/ |
71
|
|
View Code Duplication |
public function testDatabaseSingleSiteaccess() |
72
|
|
|
{ |
73
|
|
|
$this->load( |
74
|
|
|
array( |
75
|
|
|
'system' => array( |
76
|
|
|
'ezdemo_site' => array( |
77
|
|
|
'database' => array( |
78
|
|
|
'type' => 'sqlite', |
79
|
|
|
'server' => 'localhost', |
80
|
|
|
'user' => 'root', |
81
|
|
|
'password' => 'root', |
82
|
|
|
'database_name' => 'ezdemo', |
83
|
|
|
), |
84
|
|
|
), |
85
|
|
|
), |
86
|
|
|
) |
87
|
|
|
); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @expectedException \InvalidArgumentException |
92
|
|
|
*/ |
93
|
|
View Code Duplication |
public function testDatabaseSiteaccessGroup() |
94
|
|
|
{ |
95
|
|
|
$this->load( |
96
|
|
|
array( |
97
|
|
|
'system' => array( |
98
|
|
|
'ezdemo_group' => array( |
99
|
|
|
'database' => array( |
100
|
|
|
'type' => 'sqlite', |
101
|
|
|
'server' => 'localhost', |
102
|
|
|
'user' => 'root', |
103
|
|
|
'password' => 'root', |
104
|
|
|
'database_name' => 'ezdemo', |
105
|
|
|
), |
106
|
|
|
), |
107
|
|
|
), |
108
|
|
|
) |
109
|
|
|
); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* Test defaults. |
114
|
|
|
*/ |
115
|
|
|
public function testNonExistentSettings() |
116
|
|
|
{ |
117
|
|
|
$this->load(); |
118
|
|
|
$this->assertConfigResolverParameterValue('url_alias_router', true, 'ezdemo_site'); |
119
|
|
|
$this->assertConfigResolverParameterValue('cache_pool_name', 'default', 'ezdemo_site'); |
120
|
|
|
$this->assertConfigResolverParameterValue('var_dir', 'var', 'ezdemo_site'); |
121
|
|
|
$this->assertConfigResolverParameterValue('storage_dir', 'storage', 'ezdemo_site'); |
122
|
|
|
$this->assertConfigResolverParameterValue('binary_dir', 'original', 'ezdemo_site'); |
123
|
|
|
$this->assertConfigResolverParameterValue('session_name', '%ezpublish.session_name.default%', 'ezdemo_site'); |
124
|
|
|
$this->assertConfigResolverParameterValue('http_cache.purge_servers', array(), 'ezdemo_site'); |
125
|
|
|
$this->assertConfigResolverParameterValue('anonymous_user_id', 10, 'ezdemo_site'); |
126
|
|
|
$this->assertConfigResolverParameterValue('index_page', null, 'ezdemo_site'); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function testMiscSettings() |
130
|
|
|
{ |
131
|
|
|
$cachePoolName = 'cache_foo'; |
132
|
|
|
$varDir = 'var/foo/bar'; |
133
|
|
|
$storageDir = 'alternative_storage_folder'; |
134
|
|
|
$binaryDir = 'alternative_binary_folder'; |
135
|
|
|
$sessionName = 'alternative_session_name'; |
136
|
|
|
$indexPage = '/alternative_index_page'; |
137
|
|
|
$cachePurgeServers = array( |
138
|
|
|
'http://purge.server1/', |
139
|
|
|
'http://purge.server2:1234/foo', |
140
|
|
|
'https://purge.server3/bar', |
141
|
|
|
); |
142
|
|
|
$anonymousUserId = 10; |
143
|
|
|
$this->load( |
144
|
|
|
array( |
145
|
|
|
'system' => array( |
146
|
|
|
'ezdemo_site' => array( |
147
|
|
|
'cache_pool_name' => $cachePoolName, |
148
|
|
|
'var_dir' => $varDir, |
149
|
|
|
'storage_dir' => $storageDir, |
150
|
|
|
'binary_dir' => $binaryDir, |
151
|
|
|
'session_name' => $sessionName, |
152
|
|
|
'index_page' => $indexPage, |
153
|
|
|
'http_cache' => array( |
154
|
|
|
'purge_servers' => $cachePurgeServers, |
155
|
|
|
), |
156
|
|
|
'anonymous_user_id' => $anonymousUserId, |
157
|
|
|
), |
158
|
|
|
), |
159
|
|
|
) |
160
|
|
|
); |
161
|
|
|
|
162
|
|
|
$this->assertConfigResolverParameterValue('cache_pool_name', $cachePoolName, 'ezdemo_site'); |
163
|
|
|
$this->assertConfigResolverParameterValue('var_dir', $varDir, 'ezdemo_site'); |
164
|
|
|
$this->assertConfigResolverParameterValue('storage_dir', $storageDir, 'ezdemo_site'); |
165
|
|
|
$this->assertConfigResolverParameterValue('binary_dir', $binaryDir, 'ezdemo_site'); |
166
|
|
|
$this->assertConfigResolverParameterValue('session_name', $sessionName, 'ezdemo_site'); |
167
|
|
|
$this->assertConfigResolverParameterValue('index_page', $indexPage, 'ezdemo_site'); |
168
|
|
|
$this->assertConfigResolverParameterValue('http_cache.purge_servers', $cachePurgeServers, 'ezdemo_site'); |
169
|
|
|
$this->assertConfigResolverParameterValue('anonymous_user_id', $anonymousUserId, 'ezdemo_site'); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
public function testApiKeysSettings() |
173
|
|
|
{ |
174
|
|
|
$key = 'my_key'; |
175
|
|
|
$this->load( |
176
|
|
|
array( |
177
|
|
|
'system' => array( |
178
|
|
|
'ezdemo_group' => array( |
179
|
|
|
'api_keys' => array( |
180
|
|
|
'google_maps' => $key, |
181
|
|
|
), |
182
|
|
|
), |
183
|
|
|
), |
184
|
|
|
) |
185
|
|
|
); |
186
|
|
|
|
187
|
|
|
$this->assertConfigResolverParameterValue('api_keys', ['google_maps' => $key], 'ezdemo_site'); |
188
|
|
|
$this->assertConfigResolverParameterValue('api_keys.google_maps', $key, 'ezdemo_site'); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
View Code Duplication |
public function testUserSettings() |
192
|
|
|
{ |
193
|
|
|
$layout = 'somelayout.html.twig'; |
194
|
|
|
$loginTemplate = 'login_template.html.twig'; |
195
|
|
|
$this->load( |
196
|
|
|
array( |
197
|
|
|
'system' => array( |
198
|
|
|
'ezdemo_site' => array( |
199
|
|
|
'user' => array( |
200
|
|
|
'layout' => $layout, |
201
|
|
|
'login_template' => $loginTemplate, |
202
|
|
|
), |
203
|
|
|
), |
204
|
|
|
), |
205
|
|
|
) |
206
|
|
|
); |
207
|
|
|
|
208
|
|
|
$this->assertConfigResolverParameterValue('security.base_layout', $layout, 'ezdemo_site'); |
209
|
|
|
$this->assertConfigResolverParameterValue('security.login_template', $loginTemplate, 'ezdemo_site'); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
public function testNoUserSettings() |
213
|
|
|
{ |
214
|
|
|
$this->load(); |
215
|
|
|
$this->assertConfigResolverParameterValue( |
216
|
|
|
'security.base_layout', |
217
|
|
|
'%ezsettings.default.pagelayout%', |
218
|
|
|
'ezdemo_site' |
219
|
|
|
); |
220
|
|
|
$this->assertConfigResolverParameterValue( |
221
|
|
|
'security.login_template', |
222
|
|
|
'EzPublishCoreBundle:Security:login.html.twig', |
223
|
|
|
'ezdemo_site' |
224
|
|
|
); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* @dataProvider sessionSettingsProvider |
229
|
|
|
*/ |
230
|
|
|
public function testSessionSettings(array $inputParams, array $expected) |
231
|
|
|
{ |
232
|
|
|
$this->load( |
233
|
|
|
array( |
234
|
|
|
'system' => array( |
235
|
|
|
'ezdemo_site' => $inputParams, |
236
|
|
|
), |
237
|
|
|
) |
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
$this->assertConfigResolverParameterValue('session', $expected['session'], 'ezdemo_site'); |
241
|
|
|
$this->assertConfigResolverParameterValue('session_name', $expected['session_name'], 'ezdemo_site'); |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
public function sessionSettingsProvider() |
245
|
|
|
{ |
246
|
|
|
return array( |
247
|
|
|
array( |
248
|
|
|
array( |
249
|
|
|
'session' => array( |
250
|
|
|
'name' => 'foo', |
251
|
|
|
'cookie_path' => '/foo', |
252
|
|
|
'cookie_domain' => 'foo.com', |
253
|
|
|
'cookie_lifetime' => 86400, |
254
|
|
|
'cookie_secure' => false, |
255
|
|
|
'cookie_httponly' => true, |
256
|
|
|
), |
257
|
|
|
), |
258
|
|
|
array( |
259
|
|
|
'session' => array( |
260
|
|
|
'name' => 'foo', |
261
|
|
|
'cookie_path' => '/foo', |
262
|
|
|
'cookie_domain' => 'foo.com', |
263
|
|
|
'cookie_lifetime' => 86400, |
264
|
|
|
'cookie_secure' => false, |
265
|
|
|
'cookie_httponly' => true, |
266
|
|
|
), |
267
|
|
|
'session_name' => 'foo', |
268
|
|
|
), |
269
|
|
|
), |
270
|
|
|
array( |
271
|
|
|
array( |
272
|
|
|
'session' => array( |
273
|
|
|
'name' => 'foo', |
274
|
|
|
'cookie_path' => '/foo', |
275
|
|
|
'cookie_domain' => 'foo.com', |
276
|
|
|
'cookie_lifetime' => 86400, |
277
|
|
|
'cookie_secure' => false, |
278
|
|
|
'cookie_httponly' => true, |
279
|
|
|
), |
280
|
|
|
'session_name' => 'bar', |
281
|
|
|
), |
282
|
|
|
array( |
283
|
|
|
'session' => array( |
284
|
|
|
'name' => 'bar', |
285
|
|
|
'cookie_path' => '/foo', |
286
|
|
|
'cookie_domain' => 'foo.com', |
287
|
|
|
'cookie_lifetime' => 86400, |
288
|
|
|
'cookie_secure' => false, |
289
|
|
|
'cookie_httponly' => true, |
290
|
|
|
), |
291
|
|
|
'session_name' => 'bar', |
292
|
|
|
), |
293
|
|
|
), |
294
|
|
|
array( |
295
|
|
|
array( |
296
|
|
|
'session_name' => 'some_other_session_name', |
297
|
|
|
), |
298
|
|
|
array( |
299
|
|
|
'session' => array( |
300
|
|
|
'name' => 'some_other_session_name', |
301
|
|
|
), |
302
|
|
|
'session_name' => 'some_other_session_name', |
303
|
|
|
), |
304
|
|
|
), |
305
|
|
|
); |
306
|
|
|
} |
307
|
|
|
} |
308
|
|
|
|
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:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.