|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\UrlAliasMapperTest 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\Publish\Core\Persistence\Legacy\Tests\Content\UrlAlias; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase; |
|
12
|
|
|
use eZ\Publish\SPI\Persistence\Content\UrlAlias; |
|
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper; |
|
14
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator as LanguageMaskGenerator; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Test case for UrlAliasMapper. |
|
18
|
|
|
*/ |
|
19
|
|
|
class UrlAliasMapperTest extends LanguageAwareTestCase |
|
20
|
|
|
{ |
|
21
|
|
|
protected $fixture = array( |
|
22
|
|
|
0 => array( |
|
23
|
|
|
'action' => 'eznode:314', |
|
24
|
|
|
'parent' => '1', |
|
25
|
|
|
'text_md5' => 'f97c5d29941bfb1b2fdab0874906ab82', |
|
26
|
|
|
'raw_path_data' => array( |
|
27
|
|
|
0 => array( |
|
28
|
|
|
array( |
|
29
|
|
|
'lang_mask' => 2, |
|
30
|
|
|
'text' => 'root_us', |
|
31
|
|
|
), |
|
32
|
|
|
array( |
|
33
|
|
|
'lang_mask' => 4, |
|
34
|
|
|
'text' => 'root_gb', |
|
35
|
|
|
), |
|
36
|
|
|
), |
|
37
|
|
|
1 => array( |
|
38
|
|
|
array( |
|
39
|
|
|
'lang_mask' => 4, |
|
40
|
|
|
'text' => 'one', |
|
41
|
|
|
), |
|
42
|
|
|
), |
|
43
|
|
|
), |
|
44
|
|
|
'lang_mask' => 5, |
|
45
|
|
|
'is_original' => '1', |
|
46
|
|
|
'is_alias' => '1', |
|
47
|
|
|
'alias_redirects' => '0', |
|
48
|
|
|
), |
|
49
|
|
|
1 => array( |
|
50
|
|
|
'action' => 'eznode:314', |
|
51
|
|
|
'parent' => '2', |
|
52
|
|
|
'text_md5' => 'b8a9f715dbb64fd5c56e7783c6820a61', |
|
53
|
|
|
'raw_path_data' => array( |
|
54
|
|
|
0 => array( |
|
55
|
|
|
array( |
|
56
|
|
|
'lang_mask' => 3, |
|
57
|
|
|
'text' => 'two', |
|
58
|
|
|
), |
|
59
|
|
|
), |
|
60
|
|
|
), |
|
61
|
|
|
'lang_mask' => 3, |
|
62
|
|
|
'is_original' => '0', |
|
63
|
|
|
'is_alias' => '0', |
|
64
|
|
|
'alias_redirects' => '1', |
|
65
|
|
|
), |
|
66
|
|
|
2 => array( |
|
67
|
|
|
'action' => 'module:content/search', |
|
68
|
|
|
'parent' => '0', |
|
69
|
|
|
'text_md5' => '35d6d33467aae9a2e3dccb4b6b027878', |
|
70
|
|
|
'raw_path_data' => array( |
|
71
|
|
|
0 => array( |
|
72
|
|
|
array( |
|
73
|
|
|
'lang_mask' => 6, |
|
74
|
|
|
'text' => 'three', |
|
75
|
|
|
), |
|
76
|
|
|
), |
|
77
|
|
|
), |
|
78
|
|
|
'lang_mask' => 6, |
|
79
|
|
|
'is_original' => '1', |
|
80
|
|
|
'is_alias' => '1', |
|
81
|
|
|
'alias_redirects' => '1', |
|
82
|
|
|
), |
|
83
|
|
|
3 => array( |
|
84
|
|
|
'action' => 'nop:', |
|
85
|
|
|
'parent' => '3', |
|
86
|
|
|
'text_md5' => '8cbad96aced40b3838dd9f07f6ef5772', |
|
87
|
|
|
'raw_path_data' => array( |
|
88
|
|
|
0 => array( |
|
89
|
|
|
array( |
|
90
|
|
|
'lang_mask' => 1, |
|
91
|
|
|
'text' => 'four', |
|
92
|
|
|
), |
|
93
|
|
|
), |
|
94
|
|
|
), |
|
95
|
|
|
'lang_mask' => 1, |
|
96
|
|
|
'is_original' => '0', |
|
97
|
|
|
'is_alias' => '0', |
|
98
|
|
|
'alias_redirects' => '1', |
|
99
|
|
|
), |
|
100
|
|
|
4 => array( |
|
101
|
|
|
'action' => 'nop:', |
|
102
|
|
|
'parent' => '3', |
|
103
|
|
|
'text_md5' => '1d8d2fd0a99802b89eb356a86e029d25', |
|
104
|
|
|
'raw_path_data' => array( |
|
105
|
|
|
0 => array( |
|
106
|
|
|
array( |
|
107
|
|
|
'lang_mask' => 8, |
|
108
|
|
|
'text' => 'drei', |
|
109
|
|
|
), |
|
110
|
|
|
), |
|
111
|
|
|
), |
|
112
|
|
|
'lang_mask' => 8, |
|
113
|
|
|
'is_original' => '0', |
|
114
|
|
|
'is_alias' => '0', |
|
115
|
|
|
'alias_redirects' => '1', |
|
116
|
|
|
), |
|
117
|
|
|
); |
|
118
|
|
|
|
|
119
|
|
|
protected function getExpectation() |
|
120
|
|
|
{ |
|
121
|
|
|
return array( |
|
122
|
|
|
0 => new UrlAlias( |
|
123
|
|
|
array( |
|
124
|
|
|
'id' => '1-f97c5d29941bfb1b2fdab0874906ab82', |
|
125
|
|
|
'type' => UrlAlias::LOCATION, |
|
126
|
|
|
'destination' => 314, |
|
127
|
|
|
'pathData' => array( |
|
128
|
|
|
array( |
|
129
|
|
|
'always-available' => false, |
|
130
|
|
|
'translations' => array( |
|
131
|
|
|
'eng-US' => 'root_us', |
|
132
|
|
|
'eng-GB' => 'root_gb', |
|
133
|
|
|
), |
|
134
|
|
|
), |
|
135
|
|
|
array( |
|
136
|
|
|
'always-available' => false, |
|
137
|
|
|
'translations' => array( |
|
138
|
|
|
'eng-GB' => 'one', |
|
139
|
|
|
), |
|
140
|
|
|
), |
|
141
|
|
|
), |
|
142
|
|
|
'languageCodes' => array('eng-GB'), |
|
143
|
|
|
'alwaysAvailable' => true, |
|
144
|
|
|
'isHistory' => false, |
|
145
|
|
|
'isCustom' => true, |
|
146
|
|
|
'forward' => false, |
|
147
|
|
|
) |
|
148
|
|
|
), |
|
149
|
|
|
1 => new UrlAlias( |
|
150
|
|
|
array( |
|
151
|
|
|
'id' => '2-b8a9f715dbb64fd5c56e7783c6820a61', |
|
152
|
|
|
'type' => UrlAlias::LOCATION, |
|
153
|
|
|
'destination' => 314, |
|
154
|
|
|
'pathData' => array( |
|
155
|
|
|
array( |
|
156
|
|
|
'always-available' => true, |
|
157
|
|
|
'translations' => array( |
|
158
|
|
|
'eng-US' => 'two', |
|
159
|
|
|
), |
|
160
|
|
|
), |
|
161
|
|
|
), |
|
162
|
|
|
'languageCodes' => array('eng-US'), |
|
163
|
|
|
'alwaysAvailable' => true, |
|
164
|
|
|
'isHistory' => true, |
|
165
|
|
|
'isCustom' => false, |
|
166
|
|
|
'forward' => false, |
|
167
|
|
|
) |
|
168
|
|
|
), |
|
169
|
|
|
2 => new UrlAlias( |
|
170
|
|
|
array( |
|
171
|
|
|
'id' => '0-35d6d33467aae9a2e3dccb4b6b027878', |
|
172
|
|
|
'type' => UrlAlias::RESOURCE, |
|
173
|
|
|
'destination' => 'content/search', |
|
174
|
|
|
'pathData' => array( |
|
175
|
|
|
array( |
|
176
|
|
|
'always-available' => false, |
|
177
|
|
|
'translations' => array( |
|
178
|
|
|
'eng-US' => 'three', |
|
179
|
|
|
'eng-GB' => 'three', |
|
180
|
|
|
), |
|
181
|
|
|
), |
|
182
|
|
|
), |
|
183
|
|
|
'languageCodes' => array('eng-US', 'eng-GB'), |
|
184
|
|
|
'alwaysAvailable' => false, |
|
185
|
|
|
'isHistory' => false, |
|
186
|
|
|
'isCustom' => true, |
|
187
|
|
|
'forward' => true, |
|
188
|
|
|
) |
|
189
|
|
|
), |
|
190
|
|
|
3 => new UrlAlias( |
|
191
|
|
|
array( |
|
192
|
|
|
'id' => '3-8cbad96aced40b3838dd9f07f6ef5772', |
|
193
|
|
|
'type' => UrlAlias::VIRTUAL, |
|
194
|
|
|
'destination' => null, |
|
195
|
|
|
'pathData' => array( |
|
196
|
|
|
array( |
|
197
|
|
|
'always-available' => true, |
|
198
|
|
|
'translations' => array( |
|
199
|
|
|
'always-available' => 'four', |
|
200
|
|
|
), |
|
201
|
|
|
), |
|
202
|
|
|
), |
|
203
|
|
|
'languageCodes' => array(), |
|
204
|
|
|
'alwaysAvailable' => true, |
|
205
|
|
|
'isHistory' => true, |
|
206
|
|
|
'isCustom' => false, |
|
207
|
|
|
'forward' => false, |
|
208
|
|
|
) |
|
209
|
|
|
), |
|
210
|
|
|
4 => new UrlAlias( |
|
211
|
|
|
array( |
|
212
|
|
|
'id' => '3-1d8d2fd0a99802b89eb356a86e029d25', |
|
213
|
|
|
'type' => UrlAlias::VIRTUAL, |
|
214
|
|
|
'destination' => null, |
|
215
|
|
|
'pathData' => array( |
|
216
|
|
|
array( |
|
217
|
|
|
'always-available' => false, |
|
218
|
|
|
'translations' => array( |
|
219
|
|
|
'ger-DE' => 'drei', |
|
220
|
|
|
), |
|
221
|
|
|
), |
|
222
|
|
|
), |
|
223
|
|
|
'languageCodes' => array('ger-DE'), |
|
224
|
|
|
'alwaysAvailable' => false, |
|
225
|
|
|
'isHistory' => true, |
|
226
|
|
|
'isCustom' => false, |
|
227
|
|
|
'forward' => false, |
|
228
|
|
|
) |
|
229
|
|
|
), |
|
230
|
|
|
); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
public function providerForTestExtractUrlAliasFromData() |
|
234
|
|
|
{ |
|
235
|
|
|
return array(array(0), array(1), array(2), array(3)); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* Test for the extractUrlAliasFromData() method. |
|
240
|
|
|
* |
|
241
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper::extractUrlAliasFromData |
|
242
|
|
|
* @dataProvider providerForTestExtractUrlAliasFromData |
|
243
|
|
|
*/ |
|
244
|
|
|
public function testExtractUrlAliasFromData($index) |
|
245
|
|
|
{ |
|
246
|
|
|
$mapper = $this->getMapper(); |
|
247
|
|
|
|
|
248
|
|
|
$urlAlias = $mapper->extractUrlAliasFromData($this->fixture[$index]); |
|
249
|
|
|
$expectation = $this->getExpectation(); |
|
250
|
|
|
|
|
251
|
|
|
self::assertEquals( |
|
252
|
|
|
$expectation[$index], |
|
253
|
|
|
$urlAlias |
|
254
|
|
|
); |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Test for the extractUrlAliasListFromData() method. |
|
259
|
|
|
* |
|
260
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper::extractUrlAliasListFromData |
|
261
|
|
|
* @depends testExtractUrlAliasFromData |
|
262
|
|
|
*/ |
|
263
|
|
|
public function testExtractUrlAliasListFromData() |
|
264
|
|
|
{ |
|
265
|
|
|
$mapper = $this->getMapper(); |
|
266
|
|
|
|
|
267
|
|
|
self::assertEquals( |
|
268
|
|
|
$this->getExpectation(), |
|
269
|
|
|
$mapper->extractUrlAliasListFromData($this->fixture) |
|
270
|
|
|
); |
|
271
|
|
|
} |
|
272
|
|
|
|
|
273
|
|
|
/** |
|
274
|
|
|
* Test for the extractLanguageCodesFromData method. |
|
275
|
|
|
* |
|
276
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper::extractLanguageCodesFromData |
|
277
|
|
|
*/ |
|
278
|
|
|
public function testExtractLanguageCodesFromData() |
|
279
|
|
|
{ |
|
280
|
|
|
$mapper = $this->getMapper(); |
|
281
|
|
|
|
|
282
|
|
|
self::assertEquals( |
|
283
|
|
|
['eng-US', 'eng-GB', 'ger-DE'], |
|
284
|
|
|
$mapper->extractLanguageCodesFromData($this->fixture) |
|
285
|
|
|
); |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
/** |
|
289
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Mapper |
|
290
|
|
|
*/ |
|
291
|
|
|
protected function getMapper() |
|
292
|
|
|
{ |
|
293
|
|
|
$languageHandler = $this->getLanguageHandler(); |
|
294
|
|
|
$languageMaskGenerator = new LanguageMaskGenerator($languageHandler); |
|
295
|
|
|
|
|
296
|
|
|
return new Mapper($languageMaskGenerator); |
|
297
|
|
|
} |
|
298
|
|
|
} |
|
299
|
|
|
|