1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\ContentHandlerTest 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; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\TestCase; |
12
|
|
|
use eZ\Publish\SPI\Persistence\Content; |
13
|
|
|
use eZ\Publish\SPI\Persistence\Content\Type; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\Field; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\FieldValue; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\CreateStruct; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content\UpdateStruct; |
20
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation; |
21
|
|
|
use eZ\Publish\SPI\Persistence\Content\MetadataUpdateStruct; |
22
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct as LocationCreateStruct; |
23
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler; |
24
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Handler; |
25
|
|
|
use eZ\Publish\API\Repository\Values\Content\Relation as RelationValue; |
26
|
|
|
use eZ\Publish\SPI\Persistence\Content\Relation\CreateStruct as RelationCreateStruct; |
27
|
|
|
use eZ\Publish\Core\Base\Exceptions\NotFoundException; |
28
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway; |
29
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter; |
30
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway; |
31
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway as ContentTypeGateway; |
32
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; |
33
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Mapper; |
34
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler; |
35
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler as ContentTypeHandler; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Test case for Content Handler. |
39
|
|
|
*/ |
40
|
|
|
class ContentHandlerTest extends TestCase |
41
|
|
|
{ |
42
|
|
|
/** |
43
|
|
|
* Content handler to test. |
44
|
|
|
* |
45
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler |
46
|
|
|
*/ |
47
|
|
|
protected $contentHandler; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Gateway mock. |
51
|
|
|
* |
52
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Gateway |
53
|
|
|
*/ |
54
|
|
|
protected $gatewayMock; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Location gateway mock. |
58
|
|
|
* |
59
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway |
60
|
|
|
*/ |
61
|
|
|
protected $locationGatewayMock; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Type gateway mock. |
65
|
|
|
* |
66
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway |
67
|
|
|
*/ |
68
|
|
|
protected $typeGatewayMock; |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Mapper mock. |
72
|
|
|
* |
73
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Mapper |
74
|
|
|
*/ |
75
|
|
|
protected $mapperMock; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Field handler mock. |
79
|
|
|
* |
80
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler |
81
|
|
|
*/ |
82
|
|
|
protected $fieldHandlerMock; |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Location handler mock. |
86
|
|
|
* |
87
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler |
88
|
|
|
*/ |
89
|
|
|
protected $treeHandlerMock; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Slug converter mock. |
93
|
|
|
* |
94
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter |
95
|
|
|
*/ |
96
|
|
|
protected $slugConverterMock; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Location handler mock. |
100
|
|
|
* |
101
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway |
102
|
|
|
*/ |
103
|
|
|
protected $urlAliasGatewayMock; |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* ContentType handler mock. |
107
|
|
|
* |
108
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler |
109
|
|
|
*/ |
110
|
|
|
protected $contentTypeHandlerMock; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::__construct |
114
|
|
|
*/ |
115
|
|
View Code Duplication |
public function testCtor() |
116
|
|
|
{ |
117
|
|
|
$handler = $this->getContentHandler(); |
118
|
|
|
|
119
|
|
|
$this->assertAttributeSame( |
|
|
|
|
120
|
|
|
$this->getGatewayMock(), |
121
|
|
|
'contentGateway', |
122
|
|
|
$handler |
123
|
|
|
); |
124
|
|
|
$this->assertAttributeSame( |
|
|
|
|
125
|
|
|
$this->getMapperMock(), |
126
|
|
|
'mapper', |
127
|
|
|
$handler |
128
|
|
|
); |
129
|
|
|
$this->assertAttributeSame( |
|
|
|
|
130
|
|
|
$this->getFieldHandlerMock(), |
131
|
|
|
'fieldHandler', |
132
|
|
|
$handler |
133
|
|
|
); |
134
|
|
|
// @todo Assert missing properties |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::create |
139
|
|
|
* |
140
|
|
|
* @todo Current method way to complex to test, refactor! |
141
|
|
|
*/ |
142
|
|
|
public function testCreate() |
143
|
|
|
{ |
144
|
|
|
$handler = $this->getContentHandler(); |
145
|
|
|
|
146
|
|
|
$mapperMock = $this->getMapperMock(); |
147
|
|
|
$gatewayMock = $this->getGatewayMock(); |
148
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
149
|
|
|
$locationMock = $this->getLocationGatewayMock(); |
150
|
|
|
$contentTypeHandlerMock = $this->getContentTypeHandlerMock(); |
151
|
|
|
$contentTypeMock = $this->createMock(Type::class); |
152
|
|
|
$createStruct = $this->getCreateStructFixture(); |
153
|
|
|
|
154
|
|
|
$contentTypeHandlerMock->expects($this->once()) |
155
|
|
|
->method('load') |
156
|
|
|
->with($createStruct->typeId) |
157
|
|
|
->will($this->returnValue($contentTypeMock)); |
158
|
|
|
|
159
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
160
|
|
|
->method('createVersionInfoFromCreateStruct') |
161
|
|
|
->with( |
162
|
|
|
$this->isInstanceOf( |
163
|
|
|
CreateStruct::class |
164
|
|
|
) |
165
|
|
|
)->will( |
166
|
|
|
$this->returnValue( |
167
|
|
|
new VersionInfo( |
168
|
|
|
array( |
169
|
|
|
'names' => array(), |
170
|
|
|
'contentInfo' => new ContentInfo(), |
171
|
|
|
) |
172
|
|
|
) |
173
|
|
|
) |
174
|
|
|
); |
175
|
|
|
|
176
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
177
|
|
|
->method('insertContentObject') |
178
|
|
|
->with( |
179
|
|
|
$this->isInstanceOf(CreateStruct::class) |
180
|
|
|
)->will($this->returnValue(23)); |
181
|
|
|
|
182
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
183
|
|
|
->method('insertVersion') |
184
|
|
|
->with( |
185
|
|
|
$this->isInstanceOf(VersionInfo::class), |
186
|
|
|
$this->isType('array') |
187
|
|
|
)->will($this->returnValue(1)); |
188
|
|
|
|
189
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
190
|
|
|
->method('createNewFields') |
191
|
|
|
->with( |
192
|
|
|
$this->isInstanceOf(Content::class), |
193
|
|
|
$this->isInstanceOf(Type::class) |
194
|
|
|
); |
195
|
|
|
|
196
|
|
|
$locationMock->expects($this->once()) |
|
|
|
|
197
|
|
|
->method('createNodeAssignment') |
198
|
|
|
->with( |
199
|
|
|
$this->isInstanceOf( |
200
|
|
|
LocationCreateStruct::class |
201
|
|
|
), |
202
|
|
|
$this->equalTo(42), |
203
|
|
|
$this->equalTo(3) // Location\Gateway::NODE_ASSIGNMENT_OP_CODE_CREATE |
204
|
|
|
); |
205
|
|
|
|
206
|
|
|
$res = $handler->create($createStruct); |
207
|
|
|
|
208
|
|
|
// @todo Make subsequent tests |
209
|
|
|
|
210
|
|
|
$this->assertInstanceOf( |
211
|
|
|
Content::class, |
212
|
|
|
$res, |
213
|
|
|
'Content not created' |
214
|
|
|
); |
215
|
|
|
$this->assertEquals( |
216
|
|
|
23, |
217
|
|
|
$res->versionInfo->contentInfo->id, |
218
|
|
|
'Content ID not set correctly' |
219
|
|
|
); |
220
|
|
|
$this->assertInstanceOf( |
221
|
|
|
VersionInfo::class, |
222
|
|
|
$res->versionInfo, |
223
|
|
|
'Version infos not created' |
224
|
|
|
); |
225
|
|
|
$this->assertEquals( |
226
|
|
|
1, |
227
|
|
|
$res->versionInfo->id, |
228
|
|
|
'Version ID not set correctly' |
229
|
|
|
); |
230
|
|
|
$this->assertEquals( |
231
|
|
|
2, |
232
|
|
|
count($res->fields), |
233
|
|
|
'Fields not set correctly in version' |
234
|
|
|
); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish |
239
|
|
|
*/ |
240
|
|
|
public function testPublishFirstVersion() |
241
|
|
|
{ |
242
|
|
|
$handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus')); |
243
|
|
|
|
244
|
|
|
$gatewayMock = $this->getGatewayMock(); |
245
|
|
|
$mapperMock = $this->getMapperMock(); |
246
|
|
|
$locationMock = $this->getLocationGatewayMock(); |
247
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
248
|
|
|
$metadataUpdateStruct = new MetadataUpdateStruct(); |
249
|
|
|
|
250
|
|
|
$handler->expects($this->at(0)) |
251
|
|
|
->method('loadVersionInfo') |
252
|
|
|
->with(23, 1) |
253
|
|
|
->will( |
254
|
|
|
$this->returnValue( |
255
|
|
|
new VersionInfo(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1)))) |
256
|
|
|
) |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
$contentRows = [['ezcontentobject_version_version' => 1]]; |
260
|
|
|
|
261
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
262
|
|
|
->method('load') |
263
|
|
|
->with( |
264
|
|
|
$this->equalTo(23), |
265
|
|
|
$this->equalTo(1), |
266
|
|
|
$this->equalTo(null) |
267
|
|
|
)->willReturn($contentRows); |
268
|
|
|
|
269
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
270
|
|
|
->method('loadVersionedNameData') |
271
|
|
|
->with( |
272
|
|
|
$this->equalTo(array(array('id' => 23, 'version' => 1))) |
273
|
|
|
)->will( |
274
|
|
|
$this->returnValue(array(22)) |
275
|
|
|
); |
276
|
|
|
|
277
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
278
|
|
|
->method('extractContentFromRows') |
279
|
|
|
->with($this->equalTo($contentRows), $this->equalTo(array(22))) |
280
|
|
|
->will($this->returnValue(array($this->getContentFixtureForDraft()))); |
281
|
|
|
|
282
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
283
|
|
|
->method('loadExternalFieldData') |
284
|
|
|
->with($this->isInstanceOf(Content::class)); |
285
|
|
|
|
286
|
|
|
$gatewayMock |
|
|
|
|
287
|
|
|
->expects($this->once()) |
288
|
|
|
->method('updateContent') |
289
|
|
|
->with(23, $metadataUpdateStruct); |
290
|
|
|
|
291
|
|
|
$locationMock |
|
|
|
|
292
|
|
|
->expects($this->once()) |
293
|
|
|
->method('createLocationsFromNodeAssignments') |
294
|
|
|
->with(23, 1); |
295
|
|
|
|
296
|
|
|
$locationMock |
|
|
|
|
297
|
|
|
->expects($this->once()) |
298
|
|
|
->method('updateLocationsContentVersionNo') |
299
|
|
|
->with(23, 1); |
300
|
|
|
|
301
|
|
|
$handler |
302
|
|
|
->expects($this->once()) |
303
|
|
|
->method('setStatus') |
304
|
|
|
->with(23, VersionInfo::STATUS_PUBLISHED, 1); |
305
|
|
|
|
306
|
|
|
$handler->publish(23, 1, $metadataUpdateStruct); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
/** |
310
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::publish |
311
|
|
|
*/ |
312
|
|
|
public function testPublish() |
313
|
|
|
{ |
314
|
|
|
$handler = $this->getPartlyMockedHandler(array('loadVersionInfo', 'setStatus')); |
315
|
|
|
|
316
|
|
|
$gatewayMock = $this->getGatewayMock(); |
317
|
|
|
$mapperMock = $this->getMapperMock(); |
318
|
|
|
$locationMock = $this->getLocationGatewayMock(); |
319
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
320
|
|
|
$metadataUpdateStruct = new MetadataUpdateStruct(); |
321
|
|
|
|
322
|
|
|
$handler->expects($this->at(0)) |
323
|
|
|
->method('loadVersionInfo') |
324
|
|
|
->with(23, 2) |
325
|
|
|
->will( |
326
|
|
|
$this->returnValue( |
327
|
|
|
new VersionInfo(array('contentInfo' => new ContentInfo(array('currentVersionNo' => 1)))) |
328
|
|
|
) |
329
|
|
|
); |
330
|
|
|
|
331
|
|
|
$handler |
332
|
|
|
->expects($this->at(1)) |
333
|
|
|
->method('setStatus') |
334
|
|
|
->with(23, VersionInfo::STATUS_ARCHIVED, 1); |
335
|
|
|
|
336
|
|
|
$contentRows = [['ezcontentobject_version_version' => 2]]; |
337
|
|
|
|
338
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
339
|
|
|
->method('load') |
340
|
|
|
->with( |
341
|
|
|
$this->equalTo(23), |
342
|
|
|
$this->equalTo(2), |
343
|
|
|
$this->equalTo(null) |
344
|
|
|
) |
345
|
|
|
->willReturn($contentRows); |
346
|
|
|
|
347
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
348
|
|
|
->method('loadVersionedNameData') |
349
|
|
|
->with( |
350
|
|
|
$this->equalTo(array(array('id' => 23, 'version' => 2))) |
351
|
|
|
)->will( |
352
|
|
|
$this->returnValue(array(22)) |
353
|
|
|
); |
354
|
|
|
|
355
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
356
|
|
|
->method('extractContentFromRows') |
357
|
|
|
->with($this->equalTo($contentRows), $this->equalTo(array(22))) |
358
|
|
|
->will($this->returnValue(array($this->getContentFixtureForDraft()))); |
359
|
|
|
|
360
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
361
|
|
|
->method('loadExternalFieldData') |
362
|
|
|
->with($this->isInstanceOf(Content::class)); |
363
|
|
|
|
364
|
|
|
$gatewayMock |
|
|
|
|
365
|
|
|
->expects($this->once()) |
366
|
|
|
->method('updateContent') |
367
|
|
|
->with(23, $metadataUpdateStruct, $this->isInstanceOf(VersionInfo::class)); |
368
|
|
|
|
369
|
|
|
$locationMock |
|
|
|
|
370
|
|
|
->expects($this->once()) |
371
|
|
|
->method('createLocationsFromNodeAssignments') |
372
|
|
|
->with(23, 2); |
373
|
|
|
|
374
|
|
|
$locationMock |
|
|
|
|
375
|
|
|
->expects($this->once()) |
376
|
|
|
->method('updateLocationsContentVersionNo') |
377
|
|
|
->with(23, 2); |
378
|
|
|
|
379
|
|
|
$handler |
380
|
|
|
->expects($this->at(2)) |
381
|
|
|
->method('setStatus') |
382
|
|
|
->with(23, VersionInfo::STATUS_PUBLISHED, 2); |
383
|
|
|
|
384
|
|
|
$handler->publish(23, 2, $metadataUpdateStruct); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::createDraftFromVersion |
389
|
|
|
*/ |
390
|
|
|
public function testCreateDraftFromVersion() |
391
|
|
|
{ |
392
|
|
|
$handler = $this->getPartlyMockedHandler(array('load')); |
393
|
|
|
|
394
|
|
|
$mapperMock = $this->getMapperMock(); |
395
|
|
|
$gatewayMock = $this->getGatewayMock(); |
396
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
397
|
|
|
|
398
|
|
|
$handler->expects($this->once()) |
399
|
|
|
->method('load') |
400
|
|
|
->with(23, 2) |
401
|
|
|
->will($this->returnValue($this->getContentFixtureForDraft())); |
402
|
|
|
|
403
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
404
|
|
|
->method('createVersionInfoForContent') |
405
|
|
|
->with( |
406
|
|
|
$this->isInstanceOf(Content::class), |
407
|
|
|
$this->equalTo(3), |
408
|
|
|
$this->equalTo(14) |
409
|
|
|
)->will( |
410
|
|
|
$this->returnValue( |
411
|
|
|
new VersionInfo( |
412
|
|
|
array( |
413
|
|
|
'names' => array(), |
414
|
|
|
'versionNo' => 3, |
415
|
|
|
) |
416
|
|
|
) |
417
|
|
|
) |
418
|
|
|
); |
419
|
|
|
|
420
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
421
|
|
|
->method('insertVersion') |
422
|
|
|
->with( |
423
|
|
|
$this->isInstanceOf(VersionInfo::class), |
424
|
|
|
$this->getContentFixtureForDraft()->fields |
425
|
|
|
)->will($this->returnValue(42)); |
426
|
|
|
|
427
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
428
|
|
|
->method('getLastVersionNumber') |
429
|
|
|
->with($this->equalTo(23)) |
430
|
|
|
->will($this->returnValue(2)); |
431
|
|
|
|
432
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
433
|
|
|
->method('createExistingFieldsInNewVersion') |
434
|
|
|
->with($this->isInstanceOf(Content::class)); |
435
|
|
|
|
436
|
|
|
$relationData = array( |
437
|
|
|
array( |
438
|
|
|
'ezcontentobject_link_contentclassattribute_id' => 0, |
439
|
|
|
'ezcontentobject_link_to_contentobject_id' => 42, |
440
|
|
|
'ezcontentobject_link_relation_type' => 1, |
441
|
|
|
), |
442
|
|
|
); |
443
|
|
|
|
444
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
445
|
|
|
->method('loadRelations') |
446
|
|
|
->with( |
447
|
|
|
$this->equalTo(23), |
448
|
|
|
$this->equalTo(2) |
449
|
|
|
) |
450
|
|
|
->will($this->returnValue($relationData)); |
451
|
|
|
|
452
|
|
|
$relationStruct = new RelationCreateStruct( |
453
|
|
|
array( |
454
|
|
|
'sourceContentId' => 23, |
455
|
|
|
'sourceContentVersionNo' => 3, |
456
|
|
|
'sourceFieldDefinitionId' => 0, |
457
|
|
|
'destinationContentId' => 42, |
458
|
|
|
'type' => 1, |
459
|
|
|
) |
460
|
|
|
); |
461
|
|
|
|
462
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
463
|
|
|
->method('insertRelation') |
464
|
|
|
->with($this->equalTo($relationStruct)); |
465
|
|
|
|
466
|
|
|
$result = $handler->createDraftFromVersion(23, 2, 14); |
467
|
|
|
|
468
|
|
|
$this->assertInstanceOf( |
469
|
|
|
Content::class, |
470
|
|
|
$result |
471
|
|
|
); |
472
|
|
|
$this->assertEquals( |
473
|
|
|
42, |
474
|
|
|
$result->versionInfo->id |
475
|
|
|
); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load |
480
|
|
|
*/ |
481
|
|
|
public function testLoad() |
482
|
|
|
{ |
483
|
|
|
$handler = $this->getContentHandler(); |
484
|
|
|
|
485
|
|
|
$gatewayMock = $this->getGatewayMock(); |
486
|
|
|
$mapperMock = $this->getMapperMock(); |
487
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
488
|
|
|
|
489
|
|
|
$contentRows = [['ezcontentobject_version_version' => 2]]; |
490
|
|
|
|
491
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
492
|
|
|
->method('load') |
493
|
|
|
->with( |
494
|
|
|
$this->equalTo(23), |
495
|
|
|
$this->equalTo(2), |
496
|
|
|
$this->equalTo(array('eng-GB')) |
497
|
|
|
)->will( |
498
|
|
|
$this->returnValue($contentRows) |
499
|
|
|
); |
500
|
|
|
|
501
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
502
|
|
|
->method('loadVersionedNameData') |
503
|
|
|
->with( |
504
|
|
|
$this->equalTo(array(array('id' => 23, 'version' => 2))) |
505
|
|
|
)->will( |
506
|
|
|
$this->returnValue(array(22)) |
507
|
|
|
); |
508
|
|
|
|
509
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
510
|
|
|
->method('extractContentFromRows') |
511
|
|
|
->with($this->equalTo($contentRows), $this->equalTo(array(22))) |
512
|
|
|
->will($this->returnValue(array($this->getContentFixtureForDraft()))); |
513
|
|
|
|
514
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
515
|
|
|
->method('loadExternalFieldData') |
516
|
|
|
->with($this->isInstanceOf(Content::class)); |
517
|
|
|
|
518
|
|
|
$result = $handler->load(23, 2, array('eng-GB')); |
519
|
|
|
|
520
|
|
|
$this->assertEquals( |
521
|
|
|
$result, |
522
|
|
|
$this->getContentFixtureForDraft() |
523
|
|
|
); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
/** |
527
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentList |
528
|
|
|
*/ |
529
|
|
|
public function testLoadContentList() |
530
|
|
|
{ |
531
|
|
|
$handler = $this->getContentHandler(); |
532
|
|
|
|
533
|
|
|
$gatewayMock = $this->getGatewayMock(); |
534
|
|
|
$mapperMock = $this->getMapperMock(); |
535
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
536
|
|
|
$contentRows = [ |
537
|
|
|
['ezcontentobject_id' => 2, 'ezcontentobject_version_version' => 2], |
538
|
|
|
['ezcontentobject_id' => 3, 'ezcontentobject_version_version' => 1], |
539
|
|
|
]; |
540
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
541
|
|
|
->method('loadContentList') |
542
|
|
|
->with([2, 3], ['eng-GB', 'eng-US']) |
543
|
|
|
->willReturn($contentRows); |
544
|
|
|
|
545
|
|
|
$nameDataRows = [ |
546
|
|
|
['ezcontentobject_name_contentobject_id' => 2, 'ezcontentobject_name_content_version' => 2], |
547
|
|
|
['ezcontentobject_name_contentobject_id' => 3, 'ezcontentobject_name_content_version' => 1], |
548
|
|
|
]; |
549
|
|
|
|
550
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
551
|
|
|
->method('loadVersionedNameData') |
552
|
|
|
->with($this->equalTo([['id' => 2, 'version' => 2], ['id' => 3, 'version' => 1]])) |
553
|
|
|
->willReturn($nameDataRows); |
554
|
|
|
|
555
|
|
|
$expected = [ |
556
|
|
|
2 => $this->getContentFixtureForDraft(2, 2), |
557
|
|
|
3 => $this->getContentFixtureForDraft(3, 1), |
558
|
|
|
]; |
559
|
|
|
$mapperMock->expects($this->at(0)) |
|
|
|
|
560
|
|
|
->method('extractContentFromRows') |
561
|
|
|
->with($this->equalTo([$contentRows[0]]), $this->equalTo([$nameDataRows[0]])) |
562
|
|
|
->willReturn([$expected[2]]); |
563
|
|
|
|
564
|
|
|
$mapperMock->expects($this->at(1)) |
|
|
|
|
565
|
|
|
->method('extractContentFromRows') |
566
|
|
|
->with($this->equalTo([$contentRows[1]]), $this->equalTo([$nameDataRows[1]])) |
567
|
|
|
->willReturn([$expected[3]]); |
568
|
|
|
|
569
|
|
|
$fieldHandlerMock->expects($this->exactly(2)) |
|
|
|
|
570
|
|
|
->method('loadExternalFieldData') |
571
|
|
|
->with($this->isInstanceOf(Content::class)); |
572
|
|
|
|
573
|
|
|
$result = $handler->loadContentList([2, 3], ['eng-GB', 'eng-US']); |
574
|
|
|
|
575
|
|
|
$this->assertEquals( |
576
|
|
|
$expected, |
577
|
|
|
$result |
578
|
|
|
); |
579
|
|
|
} |
580
|
|
|
|
581
|
|
|
/** |
582
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadContentInfoByRemoteId |
583
|
|
|
*/ |
584
|
|
View Code Duplication |
public function testLoadContentInfoByRemoteId() |
585
|
|
|
{ |
586
|
|
|
$contentInfoData = array(new ContentInfo()); |
587
|
|
|
$this->getGatewayMock()->expects($this->once()) |
|
|
|
|
588
|
|
|
->method('loadContentInfoByRemoteId') |
589
|
|
|
->with( |
590
|
|
|
$this->equalTo('15b256dbea2ae72418ff5facc999e8f9') |
591
|
|
|
)->will( |
592
|
|
|
$this->returnValue(array(42)) |
593
|
|
|
); |
594
|
|
|
|
595
|
|
|
$this->getMapperMock()->expects($this->once()) |
|
|
|
|
596
|
|
|
->method('extractContentInfoFromRow') |
597
|
|
|
->with($this->equalTo(array(42))) |
598
|
|
|
->will($this->returnValue($contentInfoData)); |
599
|
|
|
|
600
|
|
|
$this->assertSame( |
601
|
|
|
$contentInfoData, |
602
|
|
|
$this->getContentHandler()->loadContentInfoByRemoteId('15b256dbea2ae72418ff5facc999e8f9') |
603
|
|
|
); |
604
|
|
|
} |
605
|
|
|
|
606
|
|
|
/** |
607
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::load |
608
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException |
609
|
|
|
*/ |
610
|
|
View Code Duplication |
public function testLoadErrorNotFound() |
611
|
|
|
{ |
612
|
|
|
$handler = $this->getContentHandler(); |
613
|
|
|
|
614
|
|
|
$gatewayMock = $this->getGatewayMock(); |
615
|
|
|
|
616
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
617
|
|
|
->method('load') |
618
|
|
|
->will( |
619
|
|
|
$this->returnValue(array()) |
620
|
|
|
); |
621
|
|
|
|
622
|
|
|
$result = $handler->load(23, 2, array('eng-GB')); |
|
|
|
|
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Returns a Content for {@link testCreateDraftFromVersion()}. |
627
|
|
|
* |
628
|
|
|
* @param int $id Optional id |
629
|
|
|
* @param int $versionNo Optional version number |
630
|
|
|
* |
631
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content |
632
|
|
|
*/ |
633
|
|
|
protected function getContentFixtureForDraft(int $id = 23, int $versionNo = 2) |
634
|
|
|
{ |
635
|
|
|
$content = new Content(); |
636
|
|
|
$content->versionInfo = new VersionInfo(); |
637
|
|
|
$content->versionInfo->versionNo = $versionNo; |
638
|
|
|
|
639
|
|
|
$content->versionInfo->contentInfo = new ContentInfo(['id' => $id]); |
640
|
|
|
|
641
|
|
|
$field = new Field(); |
642
|
|
|
$field->versionNo = $versionNo; |
643
|
|
|
|
644
|
|
|
$content->fields = [$field]; |
645
|
|
|
|
646
|
|
|
return $content; |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
/** |
650
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateContent |
651
|
|
|
*/ |
652
|
|
|
public function testUpdateContent() |
653
|
|
|
{ |
654
|
|
|
$handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo')); |
655
|
|
|
|
656
|
|
|
$gatewayMock = $this->getGatewayMock(); |
657
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
658
|
|
|
$contentTypeHandlerMock = $this->getContentTypeHandlerMock(); |
659
|
|
|
$contentTypeMock = $this->createMock(Type::class); |
660
|
|
|
$contentStub = new Content( |
661
|
|
|
array( |
662
|
|
|
'versionInfo' => new VersionInfo( |
663
|
|
|
array( |
664
|
|
|
'contentInfo' => new ContentInfo( |
665
|
|
|
array( |
666
|
|
|
'contentTypeId' => 4242, |
667
|
|
|
) |
668
|
|
|
), |
669
|
|
|
) |
670
|
|
|
), |
671
|
|
|
) |
672
|
|
|
); |
673
|
|
|
|
674
|
|
|
$contentTypeHandlerMock->expects($this->once()) |
675
|
|
|
->method('load') |
676
|
|
|
->with($contentStub->versionInfo->contentInfo->contentTypeId) |
677
|
|
|
->will($this->returnValue($contentTypeMock)); |
678
|
|
|
|
679
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
680
|
|
|
->method('updateContent') |
681
|
|
|
->with(14, $this->isInstanceOf(MetadataUpdateStruct::class)); |
682
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
683
|
|
|
->method('updateVersion') |
684
|
|
|
->with(14, 4, $this->isInstanceOf(UpdateStruct::class)); |
685
|
|
|
|
686
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
687
|
|
|
->method('updateFields') |
688
|
|
|
->with( |
689
|
|
|
$this->isInstanceOf(Content::class), |
690
|
|
|
$this->isInstanceOf(UpdateStruct::class), |
691
|
|
|
$this->isInstanceOf(Type::class) |
692
|
|
|
); |
693
|
|
|
|
694
|
|
|
$handler->expects($this->at(0)) |
695
|
|
|
->method('load') |
696
|
|
|
->with(14, 4) |
697
|
|
|
->will($this->returnValue($contentStub)); |
698
|
|
|
|
699
|
|
|
$handler->expects($this->at(1)) |
700
|
|
|
->method('load') |
701
|
|
|
->with(14, 4); |
702
|
|
|
|
703
|
|
|
$handler->expects($this->at(2)) |
704
|
|
|
->method('loadContentInfo') |
705
|
|
|
->with(14); |
706
|
|
|
|
707
|
|
|
$resultContent = $handler->updateContent( |
|
|
|
|
708
|
|
|
14, // ContentId |
709
|
|
|
4, // VersionNo |
710
|
|
|
new UpdateStruct( |
711
|
|
|
array( |
712
|
|
|
'creatorId' => 14, |
713
|
|
|
'modificationDate' => time(), |
714
|
|
|
'initialLanguageId' => 2, |
715
|
|
|
'fields' => array( |
716
|
|
|
new Field( |
717
|
|
|
array( |
718
|
|
|
'id' => 23, |
719
|
|
|
'fieldDefinitionId' => 42, |
720
|
|
|
'type' => 'some-type', |
721
|
|
|
'value' => new FieldValue(), |
722
|
|
|
) |
723
|
|
|
), |
724
|
|
|
new Field( |
725
|
|
|
array( |
726
|
|
|
'id' => 23, |
727
|
|
|
'fieldDefinitionId' => 43, |
728
|
|
|
'type' => 'some-type', |
729
|
|
|
'value' => new FieldValue(), |
730
|
|
|
) |
731
|
|
|
), |
732
|
|
|
), |
733
|
|
|
) |
734
|
|
|
) |
735
|
|
|
); |
736
|
|
|
|
737
|
|
|
$resultContentInfo = $handler->updateMetadata( |
|
|
|
|
738
|
|
|
14, // ContentId |
739
|
|
|
new MetadataUpdateStruct( |
740
|
|
|
array( |
741
|
|
|
'ownerId' => 14, |
742
|
|
|
'name' => 'Some name', |
743
|
|
|
'modificationDate' => time(), |
744
|
|
|
'alwaysAvailable' => true, |
745
|
|
|
) |
746
|
|
|
) |
747
|
|
|
); |
748
|
|
|
} |
749
|
|
|
|
750
|
|
|
/** |
751
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata |
752
|
|
|
*/ |
753
|
|
|
public function testUpdateMetadata() |
754
|
|
|
{ |
755
|
|
|
$handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo')); |
756
|
|
|
|
757
|
|
|
$gatewayMock = $this->getGatewayMock(); |
758
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
|
|
|
|
759
|
|
|
$updateStruct = new MetadataUpdateStruct( |
760
|
|
|
array( |
761
|
|
|
'ownerId' => 14, |
762
|
|
|
'name' => 'Some name', |
763
|
|
|
'modificationDate' => time(), |
764
|
|
|
'alwaysAvailable' => true, |
765
|
|
|
) |
766
|
|
|
); |
767
|
|
|
|
768
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
769
|
|
|
->method('updateContent') |
770
|
|
|
->with(14, $updateStruct); |
771
|
|
|
|
772
|
|
|
$handler->expects($this->once()) |
773
|
|
|
->method('loadContentInfo') |
774
|
|
|
->with(14) |
775
|
|
|
->will( |
776
|
|
|
$this->returnValue( |
777
|
|
|
$this->createMock(ContentInfo::class) |
778
|
|
|
) |
779
|
|
|
); |
780
|
|
|
|
781
|
|
|
$resultContentInfo = $handler->updateMetadata( |
782
|
|
|
14, // ContentId |
783
|
|
|
$updateStruct |
784
|
|
|
); |
785
|
|
|
self::assertInstanceOf(ContentInfo::class, $resultContentInfo); |
786
|
|
|
} |
787
|
|
|
|
788
|
|
|
/** |
789
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::updateMetadata |
790
|
|
|
*/ |
791
|
|
|
public function testUpdateMetadataUpdatesPathIdentificationString() |
792
|
|
|
{ |
793
|
|
|
$handler = $this->getPartlyMockedHandler(array('load', 'loadContentInfo')); |
794
|
|
|
$locationGatewayMock = $this->getLocationGatewayMock(); |
795
|
|
|
$slugConverterMock = $this->getSlugConverterMock(); |
796
|
|
|
$urlAliasGatewayMock = $this->getUrlAliasGatewayMock(); |
797
|
|
|
$gatewayMock = $this->getGatewayMock(); |
798
|
|
|
$updateStruct = new MetadataUpdateStruct(array('mainLanguageId' => 2)); |
799
|
|
|
|
800
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
801
|
|
|
->method('updateContent') |
802
|
|
|
->with(14, $updateStruct); |
803
|
|
|
|
804
|
|
|
$locationGatewayMock->expects($this->once()) |
|
|
|
|
805
|
|
|
->method('loadLocationDataByContent') |
806
|
|
|
->with(14) |
807
|
|
|
->will( |
808
|
|
|
$this->returnValue( |
809
|
|
|
array( |
810
|
|
|
array( |
811
|
|
|
'node_id' => 100, |
812
|
|
|
'parent_node_id' => 200, |
813
|
|
|
), |
814
|
|
|
) |
815
|
|
|
) |
816
|
|
|
); |
817
|
|
|
|
818
|
|
|
$urlAliasGatewayMock->expects($this->once()) |
|
|
|
|
819
|
|
|
->method('loadLocationEntries') |
820
|
|
|
->with(100, false, 2) |
821
|
|
|
->will( |
822
|
|
|
$this->returnValue( |
823
|
|
|
array( |
824
|
|
|
array( |
825
|
|
|
'text' => 'slug', |
826
|
|
|
), |
827
|
|
|
) |
828
|
|
|
) |
829
|
|
|
); |
830
|
|
|
|
831
|
|
|
$slugConverterMock->expects($this->once()) |
|
|
|
|
832
|
|
|
->method('convert') |
833
|
|
|
->with('slug', 'node_100', 'urlalias_compat') |
834
|
|
|
->will($this->returnValue('transformed_slug')); |
835
|
|
|
|
836
|
|
|
$locationGatewayMock->expects($this->once()) |
|
|
|
|
837
|
|
|
->method('updatePathIdentificationString') |
838
|
|
|
->with(100, 200, 'transformed_slug'); |
839
|
|
|
|
840
|
|
|
$handler->expects($this->once()) |
841
|
|
|
->method('loadContentInfo') |
842
|
|
|
->with(14) |
843
|
|
|
->will( |
844
|
|
|
$this->returnValue( |
845
|
|
|
$this->createMock(ContentInfo::class) |
846
|
|
|
) |
847
|
|
|
); |
848
|
|
|
|
849
|
|
|
$handler->updateMetadata( |
850
|
|
|
14, // ContentId |
851
|
|
|
$updateStruct |
852
|
|
|
); |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
/** |
856
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadRelations |
857
|
|
|
*/ |
858
|
|
|
public function testLoadRelations() |
859
|
|
|
{ |
860
|
|
|
$handler = $this->getContentHandler(); |
861
|
|
|
|
862
|
|
|
$gatewayMock = $this->getGatewayMock(); |
863
|
|
|
$mapperMock = $this->getMapperMock(); |
864
|
|
|
|
865
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
866
|
|
|
->method('loadRelations') |
867
|
|
|
->with( |
868
|
|
|
$this->equalTo(23), |
869
|
|
|
$this->equalTo(null), |
870
|
|
|
$this->equalTo(null) |
871
|
|
|
)->will( |
872
|
|
|
$this->returnValue(array(42)) |
873
|
|
|
); |
874
|
|
|
|
875
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
876
|
|
|
->method('extractRelationsFromRows') |
877
|
|
|
->with($this->equalTo(array(42))) |
878
|
|
|
->will($this->returnValue($this->getRelationFixture())); |
879
|
|
|
|
880
|
|
|
$result = $handler->loadRelations(23); |
881
|
|
|
|
882
|
|
|
$this->assertEquals( |
883
|
|
|
$result, |
884
|
|
|
$this->getRelationFixture() |
885
|
|
|
); |
886
|
|
|
} |
887
|
|
|
|
888
|
|
|
/** |
889
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadReverseRelations |
890
|
|
|
*/ |
891
|
|
|
public function testLoadReverseRelations() |
892
|
|
|
{ |
893
|
|
|
$handler = $this->getContentHandler(); |
894
|
|
|
|
895
|
|
|
$gatewayMock = $this->getGatewayMock(); |
896
|
|
|
$mapperMock = $this->getMapperMock(); |
897
|
|
|
|
898
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
899
|
|
|
->method('loadReverseRelations') |
900
|
|
|
->with( |
901
|
|
|
$this->equalTo(23), |
902
|
|
|
$this->equalTo(null) |
903
|
|
|
)->will( |
904
|
|
|
$this->returnValue(array(42)) |
905
|
|
|
); |
906
|
|
|
|
907
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
908
|
|
|
->method('extractRelationsFromRows') |
909
|
|
|
->with($this->equalTo(array(42))) |
910
|
|
|
->will($this->returnValue($this->getRelationFixture())); |
911
|
|
|
|
912
|
|
|
$result = $handler->loadReverseRelations(23); |
913
|
|
|
|
914
|
|
|
$this->assertEquals( |
915
|
|
|
$result, |
916
|
|
|
$this->getRelationFixture() |
917
|
|
|
); |
918
|
|
|
} |
919
|
|
|
|
920
|
|
|
public function testAddRelation() |
921
|
|
|
{ |
922
|
|
|
// expected relation object after creation |
923
|
|
|
$expectedRelationObject = new Relation(); |
924
|
|
|
$expectedRelationObject->id = 42; // mocked value, not a real one |
925
|
|
|
$expectedRelationObject->sourceContentId = 23; |
926
|
|
|
$expectedRelationObject->sourceContentVersionNo = 1; |
927
|
|
|
$expectedRelationObject->destinationContentId = 66; |
928
|
|
|
$expectedRelationObject->type = RelationValue::COMMON; |
929
|
|
|
|
930
|
|
|
// relation create struct |
931
|
|
|
$relationCreateStruct = new Relation\CreateStruct(); |
932
|
|
|
$relationCreateStruct->destinationContentId = 66; |
933
|
|
|
$relationCreateStruct->sourceContentId = 23; |
934
|
|
|
$relationCreateStruct->sourceContentVersionNo = 1; |
935
|
|
|
$relationCreateStruct->type = RelationValue::COMMON; |
936
|
|
|
|
937
|
|
|
$handler = $this->getContentHandler(); |
938
|
|
|
|
939
|
|
|
$gatewayMock = $this->getGatewayMock(); |
940
|
|
|
$mapperMock = $this->getMapperMock(); |
941
|
|
|
|
942
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
943
|
|
|
->method('createRelationFromCreateStruct') |
944
|
|
|
// @todo Connected with the todo above |
945
|
|
|
->with($this->equalTo($relationCreateStruct)) |
946
|
|
|
->will($this->returnValue($expectedRelationObject)); |
947
|
|
|
|
948
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
949
|
|
|
->method('insertRelation') |
950
|
|
|
->with($this->equalTo($relationCreateStruct)) |
951
|
|
|
->will( |
952
|
|
|
// @todo Should this return a row as if it was selected from the database, the id... ? Check with other, similar create methods |
953
|
|
|
$this->returnValue(42) |
954
|
|
|
); |
955
|
|
|
|
956
|
|
|
$result = $handler->addRelation($relationCreateStruct); |
957
|
|
|
|
958
|
|
|
$this->assertEquals( |
959
|
|
|
$result, |
960
|
|
|
$expectedRelationObject |
961
|
|
|
); |
962
|
|
|
} |
963
|
|
|
|
964
|
|
|
/** |
965
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::removeRelation |
966
|
|
|
*/ |
967
|
|
|
public function testRemoveRelation() |
968
|
|
|
{ |
969
|
|
|
$gatewayMock = $this->getGatewayMock(); |
970
|
|
|
|
971
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
972
|
|
|
->method('deleteRelation') |
973
|
|
|
->with($this->equalTo(1, RelationValue::COMMON)); |
974
|
|
|
|
975
|
|
|
$this->getContentHandler()->removeRelation(1, RelationValue::COMMON); |
976
|
|
|
} |
977
|
|
|
|
978
|
|
|
protected function getRelationFixture() |
979
|
|
|
{ |
980
|
|
|
$relation = new Relation(); |
981
|
|
|
$relation->sourceContentId = 23; |
982
|
|
|
$relation->sourceContentVersionNo = 1; |
983
|
|
|
$relation->destinationContentId = 69; |
984
|
|
|
|
985
|
|
|
return $relation; |
986
|
|
|
} |
987
|
|
|
|
988
|
|
|
/** |
989
|
|
|
* Returns a CreateStruct fixture. |
990
|
|
|
* |
991
|
|
|
* @return \eZ\Publish\SPI\Persistence\Content\CreateStruct |
992
|
|
|
*/ |
993
|
|
|
public function getCreateStructFixture() |
994
|
|
|
{ |
995
|
|
|
$struct = new CreateStruct(); |
996
|
|
|
|
997
|
|
|
$struct->typeId = 4242; |
998
|
|
|
|
999
|
|
|
$firstField = new Field(); |
1000
|
|
|
$firstField->type = 'some-type'; |
1001
|
|
|
$firstField->value = new FieldValue(); |
1002
|
|
|
|
1003
|
|
|
$secondField = clone $firstField; |
1004
|
|
|
|
1005
|
|
|
$struct->fields = array( |
1006
|
|
|
$firstField, $secondField, |
1007
|
|
|
); |
1008
|
|
|
|
1009
|
|
|
$struct->locations = array( |
1010
|
|
|
new LocationCreateStruct( |
1011
|
|
|
array('parentId' => 42) |
1012
|
|
|
), |
1013
|
|
|
); |
1014
|
|
|
|
1015
|
|
|
$struct->name = array( |
|
|
|
|
1016
|
|
|
'eng-GB' => 'This is a test name', |
1017
|
|
|
); |
1018
|
|
|
|
1019
|
|
|
return $struct; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
/** |
1023
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::loadDraftsForUser |
1024
|
|
|
*/ |
1025
|
|
|
public function testLoadDraftsForUser() |
1026
|
|
|
{ |
1027
|
|
|
$handler = $this->getContentHandler(); |
1028
|
|
|
$rows = array(array('ezcontentobject_version_contentobject_id' => 42, 'ezcontentobject_version_version' => 2)); |
1029
|
|
|
|
1030
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1031
|
|
|
$mapperMock = $this->getMapperMock(); |
1032
|
|
|
|
1033
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1034
|
|
|
->method('listVersionsForUser') |
1035
|
|
|
->with($this->equalTo(23)) |
1036
|
|
|
->will($this->returnValue($rows)); |
1037
|
|
|
|
1038
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1039
|
|
|
->method('loadVersionedNameData') |
1040
|
|
|
->with($this->equalTo(array(array('id' => 42, 'version' => 2)))) |
1041
|
|
|
->will($this->returnValue(array())); |
1042
|
|
|
|
1043
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
1044
|
|
|
->method('extractVersionInfoListFromRows') |
1045
|
|
|
->with($this->equalTo($rows), $this->equalTo(array())) |
1046
|
|
|
->will($this->returnValue(array(new VersionInfo()))); |
1047
|
|
|
|
1048
|
|
|
$res = $handler->loadDraftsForUser(23); |
1049
|
|
|
|
1050
|
|
|
$this->assertEquals( |
1051
|
|
|
array(new VersionInfo()), |
1052
|
|
|
$res |
1053
|
|
|
); |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
public function testListVersions() |
1057
|
|
|
{ |
1058
|
|
|
$handler = $this->getContentHandler(); |
1059
|
|
|
|
1060
|
|
|
$treeHandlerMock = $this->getTreeHandlerMock(); |
1061
|
|
|
|
1062
|
|
|
$treeHandlerMock |
1063
|
|
|
->expects($this->once()) |
1064
|
|
|
->method('listVersions') |
1065
|
|
|
->with(23) |
1066
|
|
|
->will($this->returnValue(array(new VersionInfo()))); |
1067
|
|
|
|
1068
|
|
|
$versions = $handler->listVersions(23); |
1069
|
|
|
|
1070
|
|
|
$this->assertEquals( |
1071
|
|
|
array(new VersionInfo()), |
1072
|
|
|
$versions |
1073
|
|
|
); |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
public function testRemoveRawContent() |
1077
|
|
|
{ |
1078
|
|
|
$handler = $this->getContentHandler(); |
1079
|
|
|
$treeHandlerMock = $this->getTreeHandlerMock(); |
1080
|
|
|
|
1081
|
|
|
$treeHandlerMock |
1082
|
|
|
->expects($this->once()) |
1083
|
|
|
->method('removeRawContent') |
1084
|
|
|
->with(23); |
1085
|
|
|
|
1086
|
|
|
$handler->removeRawContent(23); |
1087
|
|
|
} |
1088
|
|
|
|
1089
|
|
|
/** |
1090
|
|
|
* Test for the deleteContent() method. |
1091
|
|
|
* |
1092
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent |
1093
|
|
|
*/ |
1094
|
|
|
public function testDeleteContentWithLocations() |
1095
|
|
|
{ |
1096
|
|
|
$handlerMock = $this->getPartlyMockedHandler(array('getAllLocationIds')); |
1097
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1098
|
|
|
$treeHandlerMock = $this->getTreeHandlerMock(); |
1099
|
|
|
|
1100
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1101
|
|
|
->method('getAllLocationIds') |
1102
|
|
|
->with($this->equalTo(23)) |
1103
|
|
|
->will($this->returnValue(array(42, 24))); |
1104
|
|
|
$treeHandlerMock->expects($this->exactly(2)) |
1105
|
|
|
->method('removeSubtree') |
1106
|
|
|
->with( |
1107
|
|
|
$this->logicalOr( |
1108
|
|
|
$this->equalTo(42), |
1109
|
|
|
$this->equalTo(24) |
1110
|
|
|
) |
1111
|
|
|
); |
1112
|
|
|
|
1113
|
|
|
$handlerMock->deleteContent(23); |
1114
|
|
|
} |
1115
|
|
|
|
1116
|
|
|
/** |
1117
|
|
|
* Test for the deleteContent() method. |
1118
|
|
|
* |
1119
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteContent |
1120
|
|
|
*/ |
1121
|
|
|
public function testDeleteContentWithoutLocations() |
1122
|
|
|
{ |
1123
|
|
|
$handlerMock = $this->getPartlyMockedHandler(array('removeRawContent')); |
1124
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1125
|
|
|
|
1126
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1127
|
|
|
->method('getAllLocationIds') |
1128
|
|
|
->with($this->equalTo(23)) |
1129
|
|
|
->will($this->returnValue(array())); |
1130
|
|
|
$handlerMock->expects($this->once()) |
1131
|
|
|
->method('removeRawContent') |
1132
|
|
|
->with($this->equalTo(23)); |
1133
|
|
|
|
1134
|
|
|
$handlerMock->deleteContent(23); |
1135
|
|
|
} |
1136
|
|
|
|
1137
|
|
|
/** |
1138
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::deleteVersion |
1139
|
|
|
*/ |
1140
|
|
|
public function testDeleteVersion() |
1141
|
|
|
{ |
1142
|
|
|
$handler = $this->getContentHandler(); |
1143
|
|
|
|
1144
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1145
|
|
|
$mapperMock = $this->getMapperMock(); |
1146
|
|
|
$locationHandlerMock = $this->getLocationGatewayMock(); |
1147
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
1148
|
|
|
|
1149
|
|
|
// Load VersionInfo to delete fields |
1150
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1151
|
|
|
->method('loadVersionInfo') |
1152
|
|
|
->with($this->equalTo(225), $this->equalTo(2)) |
1153
|
|
|
->will($this->returnValue(array(42))); |
1154
|
|
|
|
1155
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1156
|
|
|
->method('loadVersionedNameData') |
1157
|
|
|
->with($this->equalTo(array(array('id' => 225, 'version' => 2)))) |
1158
|
|
|
->will($this->returnValue(array(22))); |
1159
|
|
|
|
1160
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
1161
|
|
|
->method('extractVersionInfoListFromRows') |
1162
|
|
|
->with($this->equalTo(array(42)), $this->equalTo(array(22))) |
1163
|
|
|
->will($this->returnValue(array(new VersionInfo()))); |
1164
|
|
|
|
1165
|
|
|
$locationHandlerMock->expects($this->once()) |
|
|
|
|
1166
|
|
|
->method('deleteNodeAssignment') |
1167
|
|
|
->with( |
1168
|
|
|
$this->equalTo(225), |
1169
|
|
|
$this->equalTo(2) |
1170
|
|
|
); |
1171
|
|
|
|
1172
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
1173
|
|
|
->method('deleteFields') |
1174
|
|
|
->with( |
1175
|
|
|
$this->equalTo(225), |
1176
|
|
|
$this->isInstanceOf(VersionInfo::class) |
1177
|
|
|
); |
1178
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1179
|
|
|
->method('deleteRelations') |
1180
|
|
|
->with( |
1181
|
|
|
$this->equalTo(225), |
1182
|
|
|
$this->equalTo(2) |
1183
|
|
|
); |
1184
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1185
|
|
|
->method('deleteVersions') |
1186
|
|
|
->with( |
1187
|
|
|
$this->equalTo(225), |
1188
|
|
|
$this->equalTo(2) |
1189
|
|
|
); |
1190
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1191
|
|
|
->method('deleteNames') |
1192
|
|
|
->with( |
1193
|
|
|
$this->equalTo(225), |
1194
|
|
|
$this->equalTo(2) |
1195
|
|
|
); |
1196
|
|
|
|
1197
|
|
|
$handler->deleteVersion(225, 2); |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
|
/** |
1201
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy |
1202
|
|
|
*/ |
1203
|
|
|
public function testCopySingleVersion() |
1204
|
|
|
{ |
1205
|
|
|
$handler = $this->getPartlyMockedHandler(array('load', 'internalCreate')); |
1206
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1207
|
|
|
$mapperMock = $this->getMapperMock(); |
1208
|
|
|
|
1209
|
|
|
$handler->expects( |
1210
|
|
|
$this->once() |
1211
|
|
|
)->method( |
1212
|
|
|
'load' |
1213
|
|
|
)->with( |
1214
|
|
|
$this->equalTo(23), |
1215
|
|
|
$this->equalTo(32) |
1216
|
|
|
)->will( |
1217
|
|
|
$this->returnValue(new Content()) |
1218
|
|
|
); |
1219
|
|
|
|
1220
|
|
|
$mapperMock->expects( |
|
|
|
|
1221
|
|
|
$this->once() |
1222
|
|
|
)->method( |
1223
|
|
|
'createCreateStructFromContent' |
1224
|
|
|
)->with( |
1225
|
|
|
$this->isInstanceOf(Content::class) |
1226
|
|
|
)->will( |
1227
|
|
|
$this->returnValue(new CreateStruct()) |
1228
|
|
|
); |
1229
|
|
|
|
1230
|
|
|
$handler->expects( |
1231
|
|
|
$this->once() |
1232
|
|
|
)->method( |
1233
|
|
|
'internalCreate' |
1234
|
|
|
)->with( |
1235
|
|
|
$this->isInstanceOf(CreateStruct::class), |
1236
|
|
|
$this->equalTo(32) |
1237
|
|
|
)->will( |
1238
|
|
|
$this->returnValue( |
1239
|
|
|
new Content( |
1240
|
|
|
[ |
1241
|
|
|
'versionInfo' => new VersionInfo(['contentInfo' => new ContentInfo(['id' => 24])]), |
1242
|
|
|
] |
1243
|
|
|
) |
1244
|
|
|
) |
1245
|
|
|
); |
1246
|
|
|
|
1247
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1248
|
|
|
->method('copyRelations') |
1249
|
|
|
->with( |
1250
|
|
|
$this->equalTo(23), |
1251
|
|
|
$this->equalTo(24), |
1252
|
|
|
$this->equalTo(32) |
1253
|
|
|
) |
1254
|
|
|
->will($this->returnValue(null)); |
1255
|
|
|
|
1256
|
|
|
$result = $handler->copy(23, 32); |
1257
|
|
|
|
1258
|
|
|
$this->assertInstanceOf( |
1259
|
|
|
Content::class, |
1260
|
|
|
$result |
1261
|
|
|
); |
1262
|
|
|
} |
1263
|
|
|
|
1264
|
|
|
/** |
1265
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy |
1266
|
|
|
*/ |
1267
|
|
|
public function testCopyAllVersions() |
1268
|
|
|
{ |
1269
|
|
|
$handler = $this->getPartlyMockedHandler( |
1270
|
|
|
array( |
1271
|
|
|
'loadContentInfo', |
1272
|
|
|
'load', |
1273
|
|
|
'internalCreate', |
1274
|
|
|
'listVersions', |
1275
|
|
|
) |
1276
|
|
|
); |
1277
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1278
|
|
|
$mapperMock = $this->getMapperMock(); |
1279
|
|
|
$fieldHandlerMock = $this->getFieldHandlerMock(); |
1280
|
|
|
$contentTypeHandlerMock = $this->getContentTypeHandlerMock(); |
1281
|
|
|
$contentTypeMock = $this->createMock(Type::class); |
1282
|
|
|
$time = time(); |
1283
|
|
|
$createStructStub = new CreateStruct( |
1284
|
|
|
array( |
1285
|
|
|
'modified' => $time, |
1286
|
|
|
'typeId' => 4242, |
1287
|
|
|
) |
1288
|
|
|
); |
1289
|
|
|
|
1290
|
|
|
$contentTypeHandlerMock->expects($this->once()) |
1291
|
|
|
->method('load') |
1292
|
|
|
->with($createStructStub->typeId) |
1293
|
|
|
->will($this->returnValue($contentTypeMock)); |
1294
|
|
|
|
1295
|
|
|
$handler->expects($this->once()) |
1296
|
|
|
->method('loadContentInfo') |
1297
|
|
|
->with($this->equalTo(23)) |
1298
|
|
|
->will($this->returnValue(new ContentInfo(array('currentVersionNo' => 2)))); |
1299
|
|
|
|
1300
|
|
|
$handler->expects($this->at(1)) |
1301
|
|
|
->method('load') |
1302
|
|
|
->with($this->equalTo(23), $this->equalTo(2)) |
1303
|
|
|
->will($this->returnValue(new Content())); |
1304
|
|
|
|
1305
|
|
|
$mapperMock->expects($this->once()) |
|
|
|
|
1306
|
|
|
->method('createCreateStructFromContent') |
1307
|
|
|
->with($this->isInstanceOf(Content::class)) |
1308
|
|
|
->will( |
1309
|
|
|
$this->returnValue($createStructStub) |
1310
|
|
|
); |
1311
|
|
|
|
1312
|
|
|
$handler->expects($this->once()) |
1313
|
|
|
->method('internalCreate') |
1314
|
|
|
->with( |
1315
|
|
|
$this->isInstanceOf(CreateStruct::class), |
1316
|
|
|
$this->equalTo(2) |
1317
|
|
|
)->will( |
1318
|
|
|
$this->returnValue( |
1319
|
|
|
new Content( |
1320
|
|
|
array( |
1321
|
|
|
'versionInfo' => new VersionInfo( |
1322
|
|
|
array( |
1323
|
|
|
'contentInfo' => new ContentInfo(array('id' => 24)), |
1324
|
|
|
) |
1325
|
|
|
), |
1326
|
|
|
) |
1327
|
|
|
) |
1328
|
|
|
) |
1329
|
|
|
); |
1330
|
|
|
|
1331
|
|
|
$handler->expects($this->once()) |
1332
|
|
|
->method('listVersions') |
1333
|
|
|
->with($this->equalTo(23)) |
1334
|
|
|
->will( |
1335
|
|
|
$this->returnValue( |
1336
|
|
|
array( |
1337
|
|
|
new VersionInfo(array('versionNo' => 1)), |
1338
|
|
|
new VersionInfo(array('versionNo' => 2)), |
1339
|
|
|
) |
1340
|
|
|
) |
1341
|
|
|
); |
1342
|
|
|
|
1343
|
|
|
$versionInfo = new VersionInfo( |
1344
|
|
|
array( |
1345
|
|
|
'names' => array('eng-US' => 'Test'), |
1346
|
|
|
'contentInfo' => new ContentInfo( |
1347
|
|
|
array( |
1348
|
|
|
'id' => 24, |
1349
|
|
|
'alwaysAvailable' => true, |
1350
|
|
|
) |
1351
|
|
|
), |
1352
|
|
|
) |
1353
|
|
|
); |
1354
|
|
|
$handler->expects($this->at(4)) |
1355
|
|
|
->method('load') |
1356
|
|
|
->with($this->equalTo(23), $this->equalTo(1)) |
1357
|
|
|
->will( |
1358
|
|
|
$this->returnValue( |
1359
|
|
|
new Content( |
1360
|
|
|
array( |
1361
|
|
|
'versionInfo' => $versionInfo, |
1362
|
|
|
'fields' => array(), |
1363
|
|
|
) |
1364
|
|
|
) |
1365
|
|
|
) |
1366
|
|
|
); |
1367
|
|
|
|
1368
|
|
|
$versionInfo->creationDate = $time; |
1369
|
|
|
$versionInfo->modificationDate = $time; |
1370
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1371
|
|
|
->method('insertVersion') |
1372
|
|
|
->with( |
1373
|
|
|
$this->equalTo($versionInfo), |
1374
|
|
|
$this->isType('array') |
1375
|
|
|
)->will($this->returnValue(42)); |
1376
|
|
|
|
1377
|
|
|
$versionInfo = clone $versionInfo; |
1378
|
|
|
$versionInfo->id = 42; |
1379
|
|
|
$fieldHandlerMock->expects($this->once()) |
|
|
|
|
1380
|
|
|
->method('createNewFields') |
1381
|
|
|
->with( |
1382
|
|
|
$this->equalTo( |
1383
|
|
|
new Content( |
1384
|
|
|
array( |
1385
|
|
|
'versionInfo' => $versionInfo, |
1386
|
|
|
'fields' => array(), |
1387
|
|
|
) |
1388
|
|
|
) |
1389
|
|
|
), |
1390
|
|
|
$this->isInstanceOf(Type::class) |
1391
|
|
|
); |
1392
|
|
|
|
1393
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1394
|
|
|
->method('setName') |
1395
|
|
|
->with( |
1396
|
|
|
$this->equalTo(24), |
1397
|
|
|
$this->equalTo(1), |
1398
|
|
|
$this->equalTo('Test'), |
1399
|
|
|
$this->equalTo('eng-US') |
1400
|
|
|
); |
1401
|
|
|
|
1402
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1403
|
|
|
->method('copyRelations') |
1404
|
|
|
->with( |
1405
|
|
|
$this->equalTo(23), |
1406
|
|
|
$this->equalTo(24), |
1407
|
|
|
$this->equalTo(null) |
1408
|
|
|
) |
1409
|
|
|
->will($this->returnValue(null)); |
1410
|
|
|
|
1411
|
|
|
$result = $handler->copy(23); |
1412
|
|
|
|
1413
|
|
|
$this->assertInstanceOf( |
1414
|
|
|
Content::class, |
1415
|
|
|
$result |
1416
|
|
|
); |
1417
|
|
|
} |
1418
|
|
|
|
1419
|
|
|
/** |
1420
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException |
1421
|
|
|
*/ |
1422
|
|
|
public function testCopyThrowsNotFoundExceptionContentNotFound() |
1423
|
|
|
{ |
1424
|
|
|
$handler = $this->getContentHandler(); |
1425
|
|
|
|
1426
|
|
|
$treeHandlerMock = $this->getTreeHandlerMock(); |
1427
|
|
|
$treeHandlerMock |
1428
|
|
|
->expects($this->once()) |
1429
|
|
|
->method('loadContentInfo') |
1430
|
|
|
->with($this->equalTo(23)) |
1431
|
|
|
->will( |
1432
|
|
|
$this->throwException(new NotFoundException('ContentInfo', 23)) |
1433
|
|
|
); |
1434
|
|
|
|
1435
|
|
|
$handler->copy(23); |
1436
|
|
|
} |
1437
|
|
|
|
1438
|
|
|
/** |
1439
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::copy |
1440
|
|
|
* @expectedException \eZ\Publish\Core\Base\Exceptions\NotFoundException |
1441
|
|
|
*/ |
1442
|
|
View Code Duplication |
public function testCopyThrowsNotFoundExceptionVersionNotFound() |
1443
|
|
|
{ |
1444
|
|
|
$handler = $this->getContentHandler(); |
1445
|
|
|
|
1446
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1447
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1448
|
|
|
->method('load') |
1449
|
|
|
->with($this->equalTo(23, 32)) |
1450
|
|
|
->will($this->returnValue(array())); |
1451
|
|
|
|
1452
|
|
|
$result = $handler->copy(23, 32); |
|
|
|
|
1453
|
|
|
} |
1454
|
|
|
|
1455
|
|
|
/** |
1456
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Handler::setStatus |
1457
|
|
|
*/ |
1458
|
|
View Code Duplication |
public function testSetStatus() |
1459
|
|
|
{ |
1460
|
|
|
$handler = $this->getContentHandler(); |
1461
|
|
|
|
1462
|
|
|
$mapperMock = $this->getMapperMock(); |
|
|
|
|
1463
|
|
|
$gatewayMock = $this->getGatewayMock(); |
1464
|
|
|
|
1465
|
|
|
$gatewayMock->expects($this->once()) |
|
|
|
|
1466
|
|
|
->method('setStatus') |
1467
|
|
|
->with(23, 5, 2) |
1468
|
|
|
->will($this->returnValue(true)); |
1469
|
|
|
|
1470
|
|
|
$this->assertTrue( |
1471
|
|
|
$handler->setStatus(23, 2, 5) |
1472
|
|
|
); |
1473
|
|
|
} |
1474
|
|
|
|
1475
|
|
|
/** |
1476
|
|
|
* Returns the handler to test. |
1477
|
|
|
* |
1478
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler |
1479
|
|
|
*/ |
1480
|
|
|
protected function getContentHandler() |
1481
|
|
|
{ |
1482
|
|
|
if (!isset($this->contentHandler)) { |
1483
|
|
|
$this->contentHandler = new Handler( |
1484
|
|
|
$this->getGatewayMock(), |
1485
|
|
|
$this->getLocationGatewayMock(), |
1486
|
|
|
$this->getMapperMock(), |
1487
|
|
|
$this->getFieldHandlerMock(), |
1488
|
|
|
$this->getSlugConverterMock(), |
1489
|
|
|
$this->getUrlAliasGatewayMock(), |
1490
|
|
|
$this->getContentTypeHandlerMock(), |
|
|
|
|
1491
|
|
|
$this->getTreeHandlerMock() |
|
|
|
|
1492
|
|
|
); |
1493
|
|
|
} |
1494
|
|
|
|
1495
|
|
|
return $this->contentHandler; |
1496
|
|
|
} |
1497
|
|
|
|
1498
|
|
|
/** |
1499
|
|
|
* Returns the handler to test with $methods mocked. |
1500
|
|
|
* |
1501
|
|
|
* @param string[] $methods |
1502
|
|
|
* |
1503
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Handler |
1504
|
|
|
*/ |
1505
|
|
|
protected function getPartlyMockedHandler(array $methods) |
1506
|
|
|
{ |
1507
|
|
|
return $this->getMockBuilder(Handler::class) |
1508
|
|
|
->setMethods($methods) |
1509
|
|
|
->setConstructorArgs( |
1510
|
|
|
array( |
1511
|
|
|
$this->getGatewayMock(), |
1512
|
|
|
$this->getLocationGatewayMock(), |
1513
|
|
|
$this->getMapperMock(), |
1514
|
|
|
$this->getFieldHandlerMock(), |
1515
|
|
|
$this->getSlugConverterMock(), |
1516
|
|
|
$this->getUrlAliasGatewayMock(), |
1517
|
|
|
$this->getContentTypeHandlerMock(), |
1518
|
|
|
$this->getTreeHandlerMock(), |
1519
|
|
|
) |
1520
|
|
|
) |
1521
|
|
|
->getMock(); |
1522
|
|
|
} |
1523
|
|
|
|
1524
|
|
|
/** |
1525
|
|
|
* Returns a TreeHandler mock. |
1526
|
|
|
* |
1527
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler |
1528
|
|
|
*/ |
1529
|
|
|
protected function getTreeHandlerMock() |
1530
|
|
|
{ |
1531
|
|
|
if (!isset($this->treeHandlerMock)) { |
1532
|
|
|
$this->treeHandlerMock = $this->createMock(TreeHandler::class); |
|
|
|
|
1533
|
|
|
} |
1534
|
|
|
|
1535
|
|
|
return $this->treeHandlerMock; |
1536
|
|
|
} |
1537
|
|
|
|
1538
|
|
|
/** |
1539
|
|
|
* Returns a ContentTypeHandler mock. |
1540
|
|
|
* |
1541
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject|\eZ\Publish\Core\Persistence\Legacy\Content\Type\Handler |
1542
|
|
|
*/ |
1543
|
|
|
protected function getContentTypeHandlerMock() |
1544
|
|
|
{ |
1545
|
|
|
if (!isset($this->contentTypeHandlerMock)) { |
1546
|
|
|
$this->contentTypeHandlerMock = $this->createMock(ContentTypeHandler::class); |
|
|
|
|
1547
|
|
|
} |
1548
|
|
|
|
1549
|
|
|
return $this->contentTypeHandlerMock; |
1550
|
|
|
} |
1551
|
|
|
|
1552
|
|
|
/** |
1553
|
|
|
* Returns a FieldHandler mock. |
1554
|
|
|
* |
1555
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\FieldHandler |
1556
|
|
|
*/ |
1557
|
|
|
protected function getFieldHandlerMock() |
1558
|
|
|
{ |
1559
|
|
|
if (!isset($this->fieldHandlerMock)) { |
1560
|
|
|
$this->fieldHandlerMock = $this->createMock(FieldHandler::class); |
|
|
|
|
1561
|
|
|
} |
1562
|
|
|
|
1563
|
|
|
return $this->fieldHandlerMock; |
|
|
|
|
1564
|
|
|
} |
1565
|
|
|
|
1566
|
|
|
/** |
1567
|
|
|
* Returns a Mapper mock. |
1568
|
|
|
* |
1569
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Mapper |
1570
|
|
|
*/ |
1571
|
|
|
protected function getMapperMock() |
1572
|
|
|
{ |
1573
|
|
|
if (!isset($this->mapperMock)) { |
1574
|
|
|
$this->mapperMock = $this->createMock(Mapper::class); |
|
|
|
|
1575
|
|
|
} |
1576
|
|
|
|
1577
|
|
|
return $this->mapperMock; |
|
|
|
|
1578
|
|
|
} |
1579
|
|
|
|
1580
|
|
|
/** |
1581
|
|
|
* Returns a Location Gateway mock. |
1582
|
|
|
* |
1583
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway |
1584
|
|
|
*/ |
1585
|
|
|
protected function getLocationGatewayMock() |
1586
|
|
|
{ |
1587
|
|
|
if (!isset($this->locationGatewayMock)) { |
1588
|
|
|
$this->locationGatewayMock = $this->createMock(LocationGateway::class); |
|
|
|
|
1589
|
|
|
} |
1590
|
|
|
|
1591
|
|
|
return $this->locationGatewayMock; |
|
|
|
|
1592
|
|
|
} |
1593
|
|
|
|
1594
|
|
|
/** |
1595
|
|
|
* Returns a Content Type gateway mock. |
1596
|
|
|
* |
1597
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Type\Gateway |
1598
|
|
|
*/ |
1599
|
|
|
protected function getTypeGatewayMock() |
1600
|
|
|
{ |
1601
|
|
|
if (!isset($this->typeGatewayMock)) { |
1602
|
|
|
$this->typeGatewayMock = $this->createMock(ContentTypeGateway::class); |
|
|
|
|
1603
|
|
|
} |
1604
|
|
|
|
1605
|
|
|
return $this->typeGatewayMock; |
|
|
|
|
1606
|
|
|
} |
1607
|
|
|
|
1608
|
|
|
/** |
1609
|
|
|
* Returns a mock object for the Content Gateway. |
1610
|
|
|
* |
1611
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Gateway |
1612
|
|
|
*/ |
1613
|
|
|
protected function getGatewayMock() |
1614
|
|
|
{ |
1615
|
|
|
if (!isset($this->gatewayMock)) { |
1616
|
|
|
$this->gatewayMock = $this->getMockForAbstractClass(ContentGateway::class); |
|
|
|
|
1617
|
|
|
} |
1618
|
|
|
|
1619
|
|
|
return $this->gatewayMock; |
|
|
|
|
1620
|
|
|
} |
1621
|
|
|
|
1622
|
|
|
/** |
1623
|
|
|
* Returns a mock object for the UrlAlias Handler. |
1624
|
|
|
* |
1625
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\SlugConverter |
1626
|
|
|
*/ |
1627
|
|
|
protected function getSlugConverterMock() |
1628
|
|
|
{ |
1629
|
|
|
if (!isset($this->slugConverterMock)) { |
1630
|
|
|
$this->slugConverterMock = $this->createMock(SlugConverter::class); |
|
|
|
|
1631
|
|
|
} |
1632
|
|
|
|
1633
|
|
|
return $this->slugConverterMock; |
|
|
|
|
1634
|
|
|
} |
1635
|
|
|
|
1636
|
|
|
/** |
1637
|
|
|
* Returns a mock object for the UrlAlias Gateway. |
1638
|
|
|
* |
1639
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway |
1640
|
|
|
*/ |
1641
|
|
|
protected function getUrlAliasGatewayMock() |
1642
|
|
|
{ |
1643
|
|
|
if (!isset($this->urlAliasGatewayMock)) { |
1644
|
|
|
$this->urlAliasGatewayMock = $this->getMockForAbstractClass(UrlAliasGateway::class); |
|
|
|
|
1645
|
|
|
} |
1646
|
|
|
|
1647
|
|
|
return $this->urlAliasGatewayMock; |
|
|
|
|
1648
|
|
|
} |
1649
|
|
|
} |
1650
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.