|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* File contains: eZ\Publish\Core\Repository\Tests\Service\Mock\NameSchemaTest 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\Repository\Tests\Service\Mock; |
|
10
|
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Repository\Tests\Service\Mock\Base as BaseServiceMockTest; |
|
12
|
|
|
use eZ\Publish\Core\Repository\Values\Content\Content; |
|
13
|
|
|
use eZ\Publish\Core\Repository\Values\Content\VersionInfo; |
|
14
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\ContentType; |
|
15
|
|
|
use eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition; |
|
16
|
|
|
use eZ\Publish\API\Repository\Values\Content\Field; |
|
17
|
|
|
use eZ\Publish\Core\FieldType\TextLine\Value as TextLineValue; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Mock Test case for NameSchema service. |
|
21
|
|
|
*/ |
|
22
|
|
|
class NameSchemaTest extends BaseServiceMockTest |
|
23
|
|
|
{ |
|
24
|
|
|
/** |
|
25
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
26
|
|
|
* |
|
27
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveUrlAliasSchema |
|
28
|
|
|
*/ |
|
29
|
|
View Code Duplication |
public function testResolveUrlAliasSchema() |
|
30
|
|
|
{ |
|
31
|
|
|
$serviceMock = $this->getPartlyMockedNameSchemaService(array('resolve')); |
|
32
|
|
|
|
|
33
|
|
|
list($content, $contentType) = $this->buildTestObjects(); |
|
34
|
|
|
|
|
35
|
|
|
$serviceMock->expects( |
|
36
|
|
|
$this->once() |
|
37
|
|
|
)->method( |
|
38
|
|
|
'resolve' |
|
39
|
|
|
)->with( |
|
40
|
|
|
'<urlalias_schema>', |
|
41
|
|
|
$this->equalTo($contentType), |
|
42
|
|
|
$this->equalTo($content->fields), |
|
43
|
|
|
$this->equalTo($content->versionInfo->languageCodes) |
|
44
|
|
|
)->will( |
|
45
|
|
|
$this->returnValue(42) |
|
46
|
|
|
); |
|
47
|
|
|
|
|
48
|
|
|
$result = $serviceMock->resolveUrlAliasSchema($content, $contentType); |
|
49
|
|
|
|
|
50
|
|
|
self::assertEquals(42, $result); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
55
|
|
|
* |
|
56
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveUrlAliasSchema |
|
57
|
|
|
*/ |
|
58
|
|
View Code Duplication |
public function testResolveUrlAliasSchemaFallbackToNameSchema() |
|
59
|
|
|
{ |
|
60
|
|
|
$serviceMock = $this->getPartlyMockedNameSchemaService(array('resolve')); |
|
61
|
|
|
|
|
62
|
|
|
list($content, $contentType) = $this->buildTestObjects('<name_schema>', ''); |
|
63
|
|
|
|
|
64
|
|
|
$serviceMock->expects( |
|
65
|
|
|
$this->once() |
|
66
|
|
|
)->method( |
|
67
|
|
|
'resolve' |
|
68
|
|
|
)->with( |
|
69
|
|
|
'<name_schema>', |
|
70
|
|
|
$this->equalTo($contentType), |
|
71
|
|
|
$this->equalTo($content->fields), |
|
72
|
|
|
$this->equalTo($content->versionInfo->languageCodes) |
|
73
|
|
|
)->will( |
|
74
|
|
|
$this->returnValue(42) |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
$result = $serviceMock->resolveUrlAliasSchema($content, $contentType); |
|
78
|
|
|
|
|
79
|
|
|
self::assertEquals(42, $result); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
84
|
|
|
* |
|
85
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveNameSchema |
|
86
|
|
|
*/ |
|
87
|
|
View Code Duplication |
public function testResolveNameSchema() |
|
88
|
|
|
{ |
|
89
|
|
|
$serviceMock = $this->getPartlyMockedNameSchemaService(array('resolve')); |
|
90
|
|
|
|
|
91
|
|
|
list($content, $contentType) = $this->buildTestObjects(); |
|
92
|
|
|
|
|
93
|
|
|
$serviceMock->expects( |
|
94
|
|
|
$this->once() |
|
95
|
|
|
)->method( |
|
96
|
|
|
'resolve' |
|
97
|
|
|
)->with( |
|
98
|
|
|
'<name_schema>', |
|
99
|
|
|
$this->equalTo($contentType), |
|
100
|
|
|
$this->equalTo($content->fields), |
|
101
|
|
|
$this->equalTo($content->versionInfo->languageCodes) |
|
102
|
|
|
)->will( |
|
103
|
|
|
$this->returnValue(42) |
|
104
|
|
|
); |
|
105
|
|
|
|
|
106
|
|
|
$result = $serviceMock->resolveNameSchema($content, array(), array(), $contentType); |
|
107
|
|
|
|
|
108
|
|
|
self::assertEquals(42, $result); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Test eZ\Publish\Core\Repository\Helper\NameSchemaService method. |
|
113
|
|
|
* |
|
114
|
|
|
* @covers \eZ\Publish\Core\Repository\Helper\NameSchemaService::resolveNameSchema |
|
115
|
|
|
*/ |
|
116
|
|
|
public function testResolveNameSchemaWithFields() |
|
117
|
|
|
{ |
|
118
|
|
|
$serviceMock = $this->getPartlyMockedNameSchemaService(array('resolve')); |
|
119
|
|
|
|
|
120
|
|
|
list($content, $contentType) = $this->buildTestObjects(); |
|
121
|
|
|
|
|
122
|
|
|
$fields = array(); |
|
123
|
|
|
$fields['text3']['cro-HR'] = new TextLineValue('tri'); |
|
124
|
|
|
$fields['text1']['ger-DE'] = new TextLineValue('ein'); |
|
125
|
|
|
$fields['text2']['ger-DE'] = new TextLineValue('zwei'); |
|
126
|
|
|
$fields['text3']['ger-DE'] = new TextLineValue('drei'); |
|
127
|
|
|
$mergedFields = $fields; |
|
128
|
|
|
$mergedFields['text1']['cro-HR'] = new TextLineValue('jedan'); |
|
129
|
|
|
$mergedFields['text2']['cro-HR'] = new TextLineValue('dva'); |
|
130
|
|
|
$mergedFields['text1']['eng-GB'] = new TextLineValue('one'); |
|
131
|
|
|
$mergedFields['text2']['eng-GB'] = new TextLineValue('two'); |
|
132
|
|
|
$mergedFields['text3']['eng-GB'] = new TextLineValue(''); |
|
133
|
|
|
$languages = array('eng-GB', 'cro-HR', 'ger-DE'); |
|
134
|
|
|
|
|
135
|
|
|
$serviceMock->expects( |
|
136
|
|
|
$this->once() |
|
137
|
|
|
)->method( |
|
138
|
|
|
'resolve' |
|
139
|
|
|
)->with( |
|
140
|
|
|
'<name_schema>', |
|
141
|
|
|
$this->equalTo($contentType), |
|
142
|
|
|
$this->equalTo($mergedFields), |
|
143
|
|
|
$this->equalTo($languages) |
|
144
|
|
|
)->will( |
|
145
|
|
|
$this->returnValue(42) |
|
146
|
|
|
); |
|
147
|
|
|
|
|
148
|
|
|
$result = $serviceMock->resolveNameSchema($content, $fields, $languages, $contentType); |
|
149
|
|
|
|
|
150
|
|
|
self::assertEquals(42, $result); |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
/** |
|
154
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Field[] |
|
155
|
|
|
*/ |
|
156
|
|
View Code Duplication |
protected function getFields() |
|
157
|
|
|
{ |
|
158
|
|
|
return array( |
|
159
|
|
|
new Field( |
|
160
|
|
|
array( |
|
161
|
|
|
'languageCode' => 'eng-GB', |
|
162
|
|
|
'fieldDefIdentifier' => 'text1', |
|
163
|
|
|
'value' => new TextLineValue('one'), |
|
164
|
|
|
) |
|
165
|
|
|
), |
|
166
|
|
|
new Field( |
|
167
|
|
|
array( |
|
168
|
|
|
'languageCode' => 'eng-GB', |
|
169
|
|
|
'fieldDefIdentifier' => 'text2', |
|
170
|
|
|
'value' => new TextLineValue('two'), |
|
171
|
|
|
) |
|
172
|
|
|
), |
|
173
|
|
|
new Field( |
|
174
|
|
|
array( |
|
175
|
|
|
'languageCode' => 'eng-GB', |
|
176
|
|
|
'fieldDefIdentifier' => 'text3', |
|
177
|
|
|
'value' => new TextLineValue(''), |
|
178
|
|
|
) |
|
179
|
|
|
), |
|
180
|
|
|
new Field( |
|
181
|
|
|
array( |
|
182
|
|
|
'languageCode' => 'cro-HR', |
|
183
|
|
|
'fieldDefIdentifier' => 'text1', |
|
184
|
|
|
'value' => new TextLineValue('jedan'), |
|
185
|
|
|
) |
|
186
|
|
|
), |
|
187
|
|
|
new Field( |
|
188
|
|
|
array( |
|
189
|
|
|
'languageCode' => 'cro-HR', |
|
190
|
|
|
'fieldDefIdentifier' => 'text2', |
|
191
|
|
|
'value' => new TextLineValue('dva'), |
|
192
|
|
|
) |
|
193
|
|
|
), |
|
194
|
|
|
new Field( |
|
195
|
|
|
array( |
|
196
|
|
|
'languageCode' => 'cro-HR', |
|
197
|
|
|
'fieldDefIdentifier' => 'text3', |
|
198
|
|
|
'value' => new TextLineValue(''), |
|
199
|
|
|
) |
|
200
|
|
|
), |
|
201
|
|
|
); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* @return \eZ\Publish\Core\Repository\Values\ContentType\FieldDefinition[] |
|
206
|
|
|
*/ |
|
207
|
|
View Code Duplication |
protected function getFieldDefinitions() |
|
208
|
|
|
{ |
|
209
|
|
|
return array( |
|
210
|
|
|
new FieldDefinition( |
|
211
|
|
|
array( |
|
212
|
|
|
'id' => '1', |
|
213
|
|
|
'identifier' => 'text1', |
|
214
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
215
|
|
|
) |
|
216
|
|
|
), |
|
217
|
|
|
new FieldDefinition( |
|
218
|
|
|
array( |
|
219
|
|
|
'id' => '2', |
|
220
|
|
|
'identifier' => 'text2', |
|
221
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
222
|
|
|
) |
|
223
|
|
|
), |
|
224
|
|
|
new FieldDefinition( |
|
225
|
|
|
array( |
|
226
|
|
|
'id' => '3', |
|
227
|
|
|
'identifier' => 'text3', |
|
228
|
|
|
'fieldTypeIdentifier' => 'ezstring', |
|
229
|
|
|
) |
|
230
|
|
|
), |
|
231
|
|
|
); |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Builds stubbed content for testing purpose. |
|
236
|
|
|
* |
|
237
|
|
|
* @return \eZ\Publish\API\Repository\Values\Content\Content |
|
238
|
|
|
*/ |
|
239
|
|
View Code Duplication |
protected function buildTestObjects($nameSchema = '<name_schema>', $urlAliasSchema = '<urlalias_schema>') |
|
240
|
|
|
{ |
|
241
|
|
|
$content = new Content( |
|
242
|
|
|
array( |
|
243
|
|
|
'internalFields' => $this->getFields(), |
|
244
|
|
|
'versionInfo' => new VersionInfo( |
|
245
|
|
|
array( |
|
246
|
|
|
'languageCodes' => array('eng-GB', 'cro-HR'), |
|
247
|
|
|
) |
|
248
|
|
|
), |
|
249
|
|
|
) |
|
250
|
|
|
); |
|
251
|
|
|
$contentType = new ContentType( |
|
252
|
|
|
array( |
|
253
|
|
|
'nameSchema' => $nameSchema, |
|
254
|
|
|
'urlAliasSchema' => $urlAliasSchema, |
|
255
|
|
|
'fieldDefinitions' => $this->getFieldDefinitions(), |
|
256
|
|
|
) |
|
257
|
|
|
); |
|
258
|
|
|
|
|
259
|
|
|
return array($content, $contentType); |
|
260
|
|
|
} |
|
261
|
|
|
|
|
262
|
|
|
/** |
|
263
|
|
|
* Returns the content service to test with $methods mocked. |
|
264
|
|
|
* |
|
265
|
|
|
* Injected Repository comes from {@see getRepositoryMock()} |
|
266
|
|
|
* |
|
267
|
|
|
* @param string[] $methods |
|
268
|
|
|
* |
|
269
|
|
|
* @return \eZ\Publish\Core\Repository\Helper\NameSchemaService|\PHPUnit_Framework_MockObject_MockObject |
|
270
|
|
|
*/ |
|
271
|
|
|
protected function getPartlyMockedNameSchemaService(array $methods = null) |
|
272
|
|
|
{ |
|
273
|
|
|
return $this->getMock( |
|
274
|
|
|
'eZ\\Publish\\Core\\Repository\\Helper\\NameSchemaService', |
|
275
|
|
|
$methods, |
|
276
|
|
|
array( |
|
277
|
|
|
$this->getPersistenceMock()->contentTypeHandler(), |
|
278
|
|
|
$this->getContentTypeDomainMapperMock(), |
|
279
|
|
|
$this->getNameableFieldTypeRegistryMock(), |
|
280
|
|
|
) |
|
281
|
|
|
); |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
protected $contentTypeDomainMapperMock; |
|
285
|
|
|
|
|
286
|
|
|
/** |
|
287
|
|
|
* @return \PHPUnit_Framework_MockObject_MockObject|\eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
|
288
|
|
|
*/ |
|
289
|
|
|
protected function getContentTypeDomainMapperMock() |
|
290
|
|
|
{ |
|
291
|
|
|
if (!isset($this->contentTypeDomainMapperMock)) { |
|
292
|
|
|
$this->contentTypeDomainMapperMock = $this |
|
293
|
|
|
->getMockBuilder('eZ\\Publish\\Core\\Repository\\Helper\\ContentTypeDomainMapper') |
|
294
|
|
|
->disableOriginalConstructor() |
|
295
|
|
|
->getMock(); |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
return $this->contentTypeDomainMapperMock; |
|
299
|
|
|
} |
|
300
|
|
|
} |
|
301
|
|
|
|