|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File contains: eZ\Publish\Core\Repository\Tests\Service\Integration\NameSchemaBase 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\Publish\Core\Repository\Tests\Service\Integration; |
|
12
|
|
|
|
|
13
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
|
14
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
|
15
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\ContentType; |
|
16
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; |
|
17
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
18
|
|
|
use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue; |
|
19
|
|
|
use PHPUnit_Framework_TestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Test case for NameSchema service. |
|
23
|
|
|
*/ |
|
24
|
|
|
class NameSchemaTest extends PHPUnit_Framework_TestCase |
|
25
|
|
|
{ |
|
26
|
|
|
/** |
|
27
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
28
|
|
|
* |
|
29
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolve |
|
30
|
|
|
* @dataProvider providerForTestResolve |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testResolve($nameSchema, $expectedName) |
|
33
|
|
|
{ |
|
34
|
|
|
$service = $this->getNameSchemaServiceMock(); |
|
35
|
|
|
|
|
36
|
|
|
list($content, $contentType) = $this->buildTestObjects(); |
|
37
|
|
|
|
|
38
|
|
|
$name = $service->resolve( |
|
39
|
|
|
$nameSchema, |
|
40
|
|
|
$contentType, |
|
41
|
|
|
$content->fields, |
|
42
|
|
|
$content->versionInfo->languageCodes |
|
43
|
|
|
); |
|
44
|
|
|
|
|
45
|
|
|
self::assertEquals($expectedName, $name); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
50
|
|
|
* |
|
51
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolve |
|
52
|
|
|
*/ |
|
53
|
|
|
public function testResolveWithSettings() |
|
54
|
|
|
{ |
|
55
|
|
|
$service = $this->getNameSchemaServiceMock(); |
|
56
|
|
|
|
|
57
|
|
|
list($content, $contentType) = $this->buildTestObjects(); |
|
58
|
|
|
|
|
59
|
|
|
$name = $service->resolve( |
|
60
|
|
|
'Hello, <text1> and <text2> and then goodbye and hello again', |
|
61
|
|
|
$contentType, |
|
62
|
|
|
$content->fields, |
|
63
|
|
|
$content->versionInfo->languageCodes |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
self::assertEquals( |
|
67
|
|
|
array( |
|
68
|
|
|
'eng-GB' => 'Hello, one and two and then goodbye...', |
|
69
|
|
|
'cro-HR' => 'Hello, jedan and dva and then goodb...', |
|
70
|
|
|
), |
|
71
|
|
|
$name |
|
72
|
|
|
); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
*/ |
|
77
|
|
|
public function providerForTestResolve() |
|
78
|
|
|
{ |
|
79
|
|
|
return array( |
|
80
|
|
|
array( |
|
81
|
|
|
'<text1>', |
|
82
|
|
|
array( |
|
83
|
|
|
'eng-GB' => 'one', |
|
84
|
|
|
'cro-HR' => 'jedan', |
|
85
|
|
|
), |
|
86
|
|
|
), |
|
87
|
|
|
array( |
|
88
|
|
|
'<text1> <text2>', |
|
89
|
|
|
array( |
|
90
|
|
|
'eng-GB' => 'one two', |
|
91
|
|
|
'cro-HR' => 'jedan dva', |
|
92
|
|
|
), |
|
93
|
|
|
), |
|
94
|
|
|
array( |
|
95
|
|
|
'Hello <text1>', |
|
96
|
|
|
array( |
|
97
|
|
|
'eng-GB' => 'Hello one', |
|
98
|
|
|
'cro-HR' => 'Hello jedan', |
|
99
|
|
|
), |
|
100
|
|
|
), |
|
101
|
|
|
array( |
|
102
|
|
|
'Hello, <text1> and <text2> and then goodbye', |
|
103
|
|
|
array( |
|
104
|
|
|
'eng-GB' => 'Hello, one and two and then goodbye', |
|
105
|
|
|
'cro-HR' => 'Hello, jedan and dva and then goodbye', |
|
106
|
|
|
), |
|
107
|
|
|
), |
|
108
|
|
|
array( |
|
109
|
|
|
'<text1|text2>', |
|
110
|
|
|
array( |
|
111
|
|
|
'eng-GB' => 'one', |
|
112
|
|
|
'cro-HR' => 'jedan', |
|
113
|
|
|
), |
|
114
|
|
|
), |
|
115
|
|
|
array( |
|
116
|
|
|
'<text2|text1>', |
|
117
|
|
|
array( |
|
118
|
|
|
'eng-GB' => 'two', |
|
119
|
|
|
'cro-HR' => 'dva', |
|
120
|
|
|
), |
|
121
|
|
|
), |
|
122
|
|
|
array( |
|
123
|
|
|
'<text3|text1>', |
|
124
|
|
|
array( |
|
125
|
|
|
'eng-GB' => 'one', |
|
126
|
|
|
'cro-HR' => 'jedan', |
|
127
|
|
|
), |
|
128
|
|
|
), |
|
129
|
|
|
array( |
|
130
|
|
|
'<(<text1> <text2>)>', |
|
131
|
|
|
array( |
|
132
|
|
|
'eng-GB' => 'one two', |
|
133
|
|
|
'cro-HR' => 'jedan dva', |
|
134
|
|
|
), |
|
135
|
|
|
), |
|
136
|
|
|
array( |
|
137
|
|
|
'<(<text3|text2>)>', |
|
138
|
|
|
array( |
|
139
|
|
|
'eng-GB' => 'two', |
|
140
|
|
|
'cro-HR' => 'dva', |
|
141
|
|
|
), |
|
142
|
|
|
), |
|
143
|
|
|
array( |
|
144
|
|
|
'<text3|(<text3|text2>)>', |
|
145
|
|
|
array( |
|
146
|
|
|
'eng-GB' => 'two', |
|
147
|
|
|
'cro-HR' => 'dva', |
|
148
|
|
|
), |
|
149
|
|
|
), |
|
150
|
|
|
array( |
|
151
|
|
|
'<text3|(Hello <text2> and <text1>!)>', |
|
152
|
|
|
array( |
|
153
|
|
|
'eng-GB' => 'Hello two and one!', |
|
154
|
|
|
'cro-HR' => 'Hello dva and jedan!', |
|
155
|
|
|
), |
|
156
|
|
|
), |
|
157
|
|
|
array( |
|
158
|
|
|
'<text3|(Hello <text3> and <text1>)|text2>!', |
|
159
|
|
|
array( |
|
160
|
|
|
'eng-GB' => 'Hello and one!', |
|
161
|
|
|
'cro-HR' => 'Hello and jedan!', |
|
162
|
|
|
), |
|
163
|
|
|
), |
|
164
|
|
|
array( |
|
165
|
|
|
'<text3|(Hello <text3|text2> and <text1>)|text2>!', |
|
166
|
|
|
array( |
|
167
|
|
|
'eng-GB' => 'Hello two and one!', |
|
168
|
|
|
'cro-HR' => 'Hello dva and jedan!', |
|
169
|
|
|
), |
|
170
|
|
|
), |
|
171
|
|
|
); |
|
172
|
|
|
} |
|
173
|
|
|
|
|
174
|
|
|
/** |
|
175
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] |
|
176
|
|
|
*/ |
|
177
|
|
View Code Duplication |
protected function getFields() |
|
178
|
|
|
{ |
|
179
|
|
|
return array( |
|
180
|
|
|
new Field( |
|
181
|
|
|
array( |
|
182
|
|
|
'languageCode' => 'eng-GB', |
|
183
|
|
|
'fieldDefIdentifier' => 'text1', |
|
184
|
|
|
'value' => new TextLineValue('one'), |
|
185
|
|
|
) |
|
186
|
|
|
), |
|
187
|
|
|
new Field( |
|
188
|
|
|
array( |
|
189
|
|
|
'languageCode' => 'eng-GB', |
|
190
|
|
|
'fieldDefIdentifier' => 'text2', |
|
191
|
|
|
'value' => new TextLineValue('two'), |
|
192
|
|
|
) |
|
193
|
|
|
), |
|
194
|
|
|
new Field( |
|
195
|
|
|
array( |
|
196
|
|
|
'languageCode' => 'eng-GB', |
|
197
|
|
|
'fieldDefIdentifier' => 'text3', |
|
198
|
|
|
'value' => new TextLineValue(''), |
|
199
|
|
|
) |
|
200
|
|
|
), |
|
201
|
|
|
new Field( |
|
202
|
|
|
array( |
|
203
|
|
|
'languageCode' => 'cro-HR', |
|
204
|
|
|
'fieldDefIdentifier' => 'text1', |
|
205
|
|
|
'value' => new TextLineValue('jedan'), |
|
206
|
|
|
) |
|
207
|
|
|
), |
|
208
|
|
|
new Field( |
|
209
|
|
|
array( |
|
210
|
|
|
'languageCode' => 'cro-HR', |
|
211
|
|
|
'fieldDefIdentifier' => 'text2', |
|
212
|
|
|
'value' => new TextLineValue('dva'), |
|
213
|
|
|
) |
|
214
|
|
|
), |
|
215
|
|
|
new Field( |
|
216
|
|
|
array( |
|
217
|
|
|
'languageCode' => 'cro-HR', |
|
218
|
|
|
'fieldDefIdentifier' => 'text3', |
|
219
|
|
|
'value' => new TextLineValue(''), |
|
220
|
|
|
) |
|
221
|
|
|
), |
|
222
|
|
|
); |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
/** |
|
226
|
|
|
* @return \eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition[] |
|
227
|
|
|
*/ |
|
228
|
|
View Code Duplication |
protected function getFieldDefinitions() |
|
229
|
|
|
{ |
|
230
|
|
|
return array( |
|
231
|
|
|
new FieldDefinition( |
|
232
|
|
|
array( |
|
233
|
|
|
'id' => '1', |
|
234
|
|
|
'identifier' => 'text1', |
|
235
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
236
|
|
|
) |
|
237
|
|
|
), |
|
238
|
|
|
new FieldDefinition( |
|
239
|
|
|
array( |
|
240
|
|
|
'id' => '2', |
|
241
|
|
|
'identifier' => 'text2', |
|
242
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
243
|
|
|
) |
|
244
|
|
|
), |
|
245
|
|
|
new FieldDefinition( |
|
246
|
|
|
array( |
|
247
|
|
|
'id' => '3', |
|
248
|
|
|
'identifier' => 'text3', |
|
249
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
250
|
|
|
) |
|
251
|
|
|
), |
|
252
|
|
|
); |
|
253
|
|
|
} |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* Builds stubbed content for testing purpose. |
|
257
|
|
|
* |
|
258
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
|
259
|
|
|
*/ |
|
260
|
|
View Code Duplication |
protected function buildTestObjects($nameSchema = '<name_schema>', $urlAliasSchema = '<urlalias_schema>') |
|
261
|
|
|
{ |
|
262
|
|
|
$contentType = new ContentType( |
|
263
|
|
|
array( |
|
264
|
|
|
'nameSchema' => $nameSchema, |
|
265
|
|
|
'urlAliasSchema' => $urlAliasSchema, |
|
266
|
|
|
'fieldDefinitions' => $this->getFieldDefinitions(), |
|
267
|
|
|
) |
|
268
|
|
|
); |
|
269
|
|
|
$content = new Content( |
|
270
|
|
|
array( |
|
271
|
|
|
'internalFields' => $this->getFields(), |
|
272
|
|
|
'versionInfo' => new VersionInfo( |
|
273
|
|
|
array( |
|
274
|
|
|
'languageCodes' => array('eng-GB', 'cro-HR'), |
|
275
|
|
|
) |
|
276
|
|
|
), |
|
277
|
|
|
) |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
return array($content, $contentType); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Repository\Helper\NameSchemaService |
|
285
|
|
|
*/ |
|
286
|
|
|
protected function getNameSchemaServiceMock() |
|
287
|
|
|
{ |
|
288
|
|
|
$contentTypeHandlerMock = $this |
|
289
|
|
|
->getMockBuilder('eZ\Publish\SPI\Persistence\Content\Type\Handler') |
|
290
|
|
|
->disableOriginalConstructor() |
|
291
|
|
|
->getMock(); |
|
292
|
|
|
|
|
293
|
|
|
$contentTypeDomainMapper = $this |
|
294
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper') |
|
295
|
|
|
->disableOriginalConstructor() |
|
296
|
|
|
->getMock(); |
|
297
|
|
|
|
|
298
|
|
|
$fieldTypeMock = $this |
|
299
|
|
|
->getMockBuilder('eZ\Publish\SPI\FieldType\Nameable') |
|
300
|
|
|
->setMethods(['getFieldName']) |
|
301
|
|
|
->getMockForAbstractClass(); |
|
302
|
|
|
$fieldTypeMock |
|
303
|
|
|
->expects($this->any()) |
|
304
|
|
|
->method('getFieldName') |
|
305
|
|
|
->with($this->isInstanceOf('eZ\Publish\SPI\FieldType\Value')) |
|
306
|
|
|
->will( |
|
307
|
|
|
$this->returnCallback( |
|
308
|
|
|
function ($value) { |
|
309
|
|
|
return (string)$value; |
|
310
|
|
|
} |
|
311
|
|
|
) |
|
312
|
|
|
); |
|
313
|
|
|
|
|
314
|
|
|
$nameableFieldTypeRegistry = $this |
|
315
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry') |
|
316
|
|
|
->setMethods(['getFieldType']) |
|
317
|
|
|
->disableOriginalConstructor() |
|
318
|
|
|
->getMock(); |
|
319
|
|
|
$nameableFieldTypeRegistry |
|
320
|
|
|
->expects($this->any()) |
|
321
|
|
|
->method('getFieldType') |
|
322
|
|
|
->will($this->returnValue($fieldTypeMock)); |
|
323
|
|
|
|
|
324
|
|
|
$settings = [ |
|
325
|
|
|
'limit' => 38, |
|
326
|
|
|
'sequence' => '...', |
|
327
|
|
|
]; |
|
328
|
|
|
|
|
329
|
|
|
return $this |
|
330
|
|
|
->getMockBuilder('eZ\Publish\Core\Repository\Helper\NameSchemaService') |
|
331
|
|
|
->setMethods(['resolveUrlAliasSchema', 'resolveNameSchema']) |
|
332
|
|
|
->setConstructorArgs( |
|
333
|
|
|
[ |
|
334
|
|
|
$contentTypeHandlerMock, |
|
335
|
|
|
$contentTypeDomainMapper, |
|
336
|
|
|
$nameableFieldTypeRegistry, |
|
337
|
|
|
$settings |
|
338
|
|
|
] |
|
339
|
|
|
) |
|
340
|
|
|
->getMock(); |
|
341
|
|
|
} |
|
342
|
|
|
} |
|
343
|
|
|
|