1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\LocationHandlerTest 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\Core\Persistence\Legacy\Content\Location\Handler; |
13
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway; |
14
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\UpdateStruct; |
15
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct; |
16
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location; |
17
|
|
|
use eZ\Publish\SPI\Persistence\Content\VersionInfo; |
18
|
|
|
use eZ\Publish\SPI\Persistence\Content\ContentInfo; |
19
|
|
|
use eZ\Publish\SPI\Persistence\Content; |
20
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper; |
21
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler; |
22
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Handler as ContentHandler; |
23
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState; |
24
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Handler as ObjectStateHandler; |
25
|
|
|
use eZ\Publish\SPI\Persistence\Content\ObjectState\Group as ObjectStateGroup; |
26
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler as LocationHandler; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Test case for LocationHandlerTest. |
30
|
|
|
*/ |
31
|
|
|
class LocationHandlerTest extends TestCase |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Mocked location gateway instance. |
35
|
|
|
* |
36
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway |
37
|
|
|
*/ |
38
|
|
|
protected $locationGateway; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Mocked location mapper instance. |
42
|
|
|
* |
43
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Location\Mapper |
44
|
|
|
*/ |
45
|
|
|
protected $locationMapper; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Mocked content handler instance. |
49
|
|
|
* |
50
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\Handler |
51
|
|
|
*/ |
52
|
|
|
protected $contentHandler; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Mocked object state handler instance. |
56
|
|
|
* |
57
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\ObjectState\Handler|\PHPUnit_Framework_MockObject_MockObject |
58
|
|
|
*/ |
59
|
|
|
protected $objectStateHandler; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Mocked Tree handler instance. |
63
|
|
|
* |
64
|
|
|
* @var \eZ\Publish\Core\Persistence\Legacy\Content\TreeHandler|\PHPUnit_Framework_MockObject_MockObject |
65
|
|
|
*/ |
66
|
|
|
protected $treeHandler; |
67
|
|
|
|
68
|
|
View Code Duplication |
public function setUp() |
69
|
|
|
{ |
70
|
|
|
parent::setUp(); |
71
|
|
|
|
72
|
|
|
$this->locationGateway = $this->createMock(Gateway::class); |
|
|
|
|
73
|
|
|
$this->locationMapper = $this->createMock(Mapper::class); |
|
|
|
|
74
|
|
|
$this->treeHandler = $this->createMock(TreeHandler::class); |
75
|
|
|
$this->contentHandler = $this->createMock(ContentHandler::class); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
protected function getLocationHandler() |
79
|
|
|
{ |
80
|
|
|
$dbHandler = $this->getDatabaseHandler(); |
|
|
|
|
81
|
|
|
|
82
|
|
|
return new Handler( |
83
|
|
|
$this->locationGateway, |
84
|
|
|
$this->locationMapper, |
85
|
|
|
$this->contentHandler, |
86
|
|
|
$this->createMock(ObjectStateHandler::class), |
87
|
|
|
$this->treeHandler |
88
|
|
|
); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function testLoadLocation() |
92
|
|
|
{ |
93
|
|
|
$handler = $this->getLocationHandler(); |
94
|
|
|
|
95
|
|
|
$this->treeHandler |
96
|
|
|
->expects($this->once()) |
97
|
|
|
->method('loadLocation') |
98
|
|
|
->with(77) |
99
|
|
|
->will($this->returnValue(new \eZ\Publish\SPI\Persistence\Content\Location())); |
100
|
|
|
|
101
|
|
|
$location = $handler->load(77); |
102
|
|
|
|
103
|
|
|
$this->assertTrue($location instanceof \eZ\Publish\SPI\Persistence\Content\Location); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testLoadLocationSubtree() |
107
|
|
|
{ |
108
|
|
|
$this->locationGateway |
|
|
|
|
109
|
|
|
->expects($this->once()) |
110
|
|
|
->method('getSubtreeContent') |
111
|
|
|
->with(77, true) |
112
|
|
|
->will( |
113
|
|
|
$this->returnValue( |
114
|
|
|
array( |
115
|
|
|
array(77 => 100), |
116
|
|
|
array(78 => 101), |
117
|
|
|
) |
118
|
|
|
) |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
$this->assertEquals(2, count($this->getLocationHandler()->loadSubtreeIds(77))); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
View Code Duplication |
public function testLoadLocationByRemoteId() |
125
|
|
|
{ |
126
|
|
|
$handler = $this->getLocationHandler(); |
127
|
|
|
|
128
|
|
|
$this->locationGateway |
|
|
|
|
129
|
|
|
->expects($this->once()) |
130
|
|
|
->method('getBasicNodeDataByRemoteId') |
131
|
|
|
->with('abc123') |
132
|
|
|
->will( |
133
|
|
|
$this->returnValue( |
134
|
|
|
array( |
135
|
|
|
'node_id' => 77, |
136
|
|
|
) |
137
|
|
|
) |
138
|
|
|
); |
139
|
|
|
|
140
|
|
|
$this->locationMapper |
|
|
|
|
141
|
|
|
->expects($this->once()) |
142
|
|
|
->method('createLocationFromRow') |
143
|
|
|
->with(array('node_id' => 77)) |
144
|
|
|
->will($this->returnValue(new \eZ\Publish\SPI\Persistence\Content\Location())); |
145
|
|
|
|
146
|
|
|
$location = $handler->loadByRemoteId('abc123'); |
147
|
|
|
|
148
|
|
|
$this->assertTrue($location instanceof \eZ\Publish\SPI\Persistence\Content\Location); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
View Code Duplication |
public function testLoadLocationsByContent() |
152
|
|
|
{ |
153
|
|
|
$handler = $this->getLocationHandler(); |
154
|
|
|
|
155
|
|
|
$this->locationGateway |
|
|
|
|
156
|
|
|
->expects($this->once()) |
157
|
|
|
->method('loadLocationDataByContent') |
158
|
|
|
->with(23, 42) |
159
|
|
|
->will( |
160
|
|
|
$this->returnValue( |
161
|
|
|
array() |
162
|
|
|
) |
163
|
|
|
); |
164
|
|
|
|
165
|
|
|
$this->locationMapper |
|
|
|
|
166
|
|
|
->expects($this->once()) |
167
|
|
|
->method('createLocationsFromRows') |
168
|
|
|
->with(array()) |
169
|
|
|
->will($this->returnValue(array('a', 'b'))); |
170
|
|
|
|
171
|
|
|
$locations = $handler->loadLocationsByContent(23, 42); |
172
|
|
|
|
173
|
|
|
$this->assertInternalType('array', $locations); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
View Code Duplication |
public function loadParentLocationsForDraftContent() |
177
|
|
|
{ |
178
|
|
|
$handler = $this->getLocationHandler(); |
179
|
|
|
|
180
|
|
|
$this->locationGateway |
|
|
|
|
181
|
|
|
->expects($this->once()) |
182
|
|
|
->method('loadParentLocationsDataForDraftContent') |
183
|
|
|
->with(23) |
184
|
|
|
->will( |
185
|
|
|
$this->returnValue( |
186
|
|
|
array() |
187
|
|
|
) |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
$this->locationMapper |
|
|
|
|
191
|
|
|
->expects($this->once()) |
192
|
|
|
->method('createLocationsFromRows') |
193
|
|
|
->with(array()) |
194
|
|
|
->will($this->returnValue(array('a', 'b'))); |
195
|
|
|
|
196
|
|
|
$locations = $handler->loadParentLocationsForDraftContent(23); |
197
|
|
|
|
198
|
|
|
$this->assertInternalType('array', $locations); |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function testMoveSubtree() |
202
|
|
|
{ |
203
|
|
|
$handler = $this->getLocationHandler(); |
204
|
|
|
|
205
|
|
|
$sourceData = array( |
206
|
|
|
'node_id' => 69, |
207
|
|
|
'path_string' => '/1/2/69/', |
208
|
|
|
'parent_node_id' => 2, |
209
|
|
|
'contentobject_id' => 67, |
210
|
|
|
); |
211
|
|
|
$this->locationGateway |
|
|
|
|
212
|
|
|
->expects($this->at(0)) |
213
|
|
|
->method('getBasicNodeData') |
214
|
|
|
->with(69) |
215
|
|
|
->will($this->returnValue($sourceData)); |
216
|
|
|
|
217
|
|
|
$destinationData = array( |
218
|
|
|
'node_id' => 77, |
219
|
|
|
'path_string' => '/1/2/77/', |
220
|
|
|
'contentobject_id' => 68, |
221
|
|
|
); |
222
|
|
|
$this->locationGateway |
|
|
|
|
223
|
|
|
->expects($this->at(1)) |
224
|
|
|
->method('getBasicNodeData') |
225
|
|
|
->with(77) |
226
|
|
|
->will($this->returnValue($destinationData)); |
227
|
|
|
|
228
|
|
|
$this->locationGateway |
|
|
|
|
229
|
|
|
->expects($this->once()) |
230
|
|
|
->method('moveSubtreeNodes') |
231
|
|
|
->with($sourceData, $destinationData); |
232
|
|
|
|
233
|
|
|
$this->locationGateway |
|
|
|
|
234
|
|
|
->expects($this->once()) |
235
|
|
|
->method('updateNodeAssignment') |
236
|
|
|
->with(67, 2, 77, 5); |
237
|
|
|
|
238
|
|
|
$this->treeHandler |
239
|
|
|
->expects($this->at(0)) |
240
|
|
|
->method('loadLocation') |
241
|
|
|
->with($sourceData['node_id']) |
242
|
|
|
->will($this->returnValue( |
243
|
|
|
new Location( |
244
|
|
|
array( |
245
|
|
|
'id' => $sourceData['node_id'], |
246
|
|
|
'contentId' => $sourceData['contentobject_id'], |
247
|
|
|
) |
248
|
|
|
) |
249
|
|
|
)); |
250
|
|
|
|
251
|
|
|
$this->treeHandler |
252
|
|
|
->expects($this->at(1)) |
253
|
|
|
->method('loadLocation') |
254
|
|
|
->with($destinationData['node_id']) |
255
|
|
|
->will($this->returnValue(new Location(array('contentId' => $destinationData['contentobject_id'])))); |
256
|
|
|
|
257
|
|
|
$this->contentHandler |
|
|
|
|
258
|
|
|
->expects($this->at(0)) |
259
|
|
|
->method('loadContentInfo') |
260
|
|
|
->with($destinationData['contentobject_id']) |
261
|
|
|
->will($this->returnValue(new ContentInfo(array('sectionId' => 12345)))); |
262
|
|
|
|
263
|
|
|
$this->contentHandler |
|
|
|
|
264
|
|
|
->expects($this->at(1)) |
265
|
|
|
->method('loadContentInfo') |
266
|
|
|
->with($sourceData['contentobject_id']) |
267
|
|
|
->will($this->returnValue(new ContentInfo(array('mainLocationId' => 69)))); |
268
|
|
|
|
269
|
|
|
$this->treeHandler |
270
|
|
|
->expects($this->once()) |
271
|
|
|
->method('setSectionForSubtree') |
272
|
|
|
->with(69, 12345); |
273
|
|
|
|
274
|
|
|
$handler->move(69, 77); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
public function testHideUpdateHidden() |
278
|
|
|
{ |
279
|
|
|
$handler = $this->getLocationHandler(); |
280
|
|
|
|
281
|
|
|
$this->locationGateway |
|
|
|
|
282
|
|
|
->expects($this->at(0)) |
283
|
|
|
->method('getBasicNodeData') |
284
|
|
|
->with(69) |
285
|
|
|
->will( |
286
|
|
|
$this->returnValue( |
287
|
|
|
array( |
288
|
|
|
'node_id' => 69, |
289
|
|
|
'path_string' => '/1/2/69/', |
290
|
|
|
'contentobject_id' => 67, |
291
|
|
|
) |
292
|
|
|
) |
293
|
|
|
); |
294
|
|
|
|
295
|
|
|
$this->locationGateway |
|
|
|
|
296
|
|
|
->expects($this->once()) |
297
|
|
|
->method('hideSubtree') |
298
|
|
|
->with('/1/2/69/'); |
299
|
|
|
|
300
|
|
|
$handler->hide(69); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @depends testHideUpdateHidden |
305
|
|
|
*/ |
306
|
|
|
public function testHideUnhideUpdateHidden() |
307
|
|
|
{ |
308
|
|
|
$handler = $this->getLocationHandler(); |
309
|
|
|
|
310
|
|
|
$this->locationGateway |
|
|
|
|
311
|
|
|
->expects($this->at(0)) |
312
|
|
|
->method('getBasicNodeData') |
313
|
|
|
->with(69) |
314
|
|
|
->will( |
315
|
|
|
$this->returnValue( |
316
|
|
|
array( |
317
|
|
|
'node_id' => 69, |
318
|
|
|
'path_string' => '/1/2/69/', |
319
|
|
|
'contentobject_id' => 67, |
320
|
|
|
) |
321
|
|
|
) |
322
|
|
|
); |
323
|
|
|
|
324
|
|
|
$this->locationGateway |
|
|
|
|
325
|
|
|
->expects($this->once()) |
326
|
|
|
->method('unhideSubtree') |
327
|
|
|
->with('/1/2/69/'); |
328
|
|
|
|
329
|
|
|
$handler->unhide(69); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
public function testSwapLocations() |
333
|
|
|
{ |
334
|
|
|
$handler = $this->getLocationHandler(); |
335
|
|
|
|
336
|
|
|
$this->locationGateway |
|
|
|
|
337
|
|
|
->expects($this->once()) |
338
|
|
|
->method('swap') |
339
|
|
|
->with(70, 78); |
340
|
|
|
|
341
|
|
|
$handler->swap(70, 78); |
342
|
|
|
} |
343
|
|
|
|
344
|
|
|
public function testCreateLocation() |
345
|
|
|
{ |
346
|
|
|
$handler = $this->getLocationHandler(); |
347
|
|
|
|
348
|
|
|
$createStruct = new CreateStruct(); |
349
|
|
|
$createStruct->parentId = 77; |
350
|
|
|
|
351
|
|
|
$this->locationGateway |
|
|
|
|
352
|
|
|
->expects($this->once()) |
353
|
|
|
->method('getBasicNodeData') |
354
|
|
|
->with(77) |
355
|
|
|
->will( |
356
|
|
|
$this->returnValue( |
357
|
|
|
$parentInfo = array( |
358
|
|
|
'node_id' => 77, |
359
|
|
|
'path_string' => '/1/2/77/', |
360
|
|
|
) |
361
|
|
|
) |
362
|
|
|
); |
363
|
|
|
|
364
|
|
|
$this->locationGateway |
|
|
|
|
365
|
|
|
->expects($this->once()) |
366
|
|
|
->method('create') |
367
|
|
|
->with($createStruct, $parentInfo) |
368
|
|
|
->will($this->returnValue($createStruct)); |
369
|
|
|
|
370
|
|
|
$this->locationGateway |
|
|
|
|
371
|
|
|
->expects($this->once()) |
372
|
|
|
->method('createNodeAssignment') |
373
|
|
|
->with($createStruct, 77, 2); |
374
|
|
|
|
375
|
|
|
$handler->create($createStruct); |
376
|
|
|
} |
377
|
|
|
|
378
|
|
|
public function testUpdateLocation() |
379
|
|
|
{ |
380
|
|
|
$handler = $this->getLocationHandler(); |
381
|
|
|
|
382
|
|
|
$updateStruct = new UpdateStruct(); |
383
|
|
|
$updateStruct->priority = 77; |
384
|
|
|
|
385
|
|
|
$this->locationGateway |
|
|
|
|
386
|
|
|
->expects($this->once()) |
387
|
|
|
->method('update') |
388
|
|
|
->with($updateStruct, 23); |
389
|
|
|
|
390
|
|
|
$handler->update($updateStruct, 23); |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
public function testSetSectionForSubtree() |
394
|
|
|
{ |
395
|
|
|
$handler = $this->getLocationHandler(); |
396
|
|
|
|
397
|
|
|
$this->treeHandler |
398
|
|
|
->expects($this->once()) |
399
|
|
|
->method('setSectionForSubtree') |
400
|
|
|
->with(69, 3); |
401
|
|
|
|
402
|
|
|
$handler->setSectionForSubtree(69, 3); |
403
|
|
|
} |
404
|
|
|
|
405
|
|
View Code Duplication |
public function testMarkSubtreeModified() |
406
|
|
|
{ |
407
|
|
|
$handler = $this->getLocationHandler(); |
408
|
|
|
|
409
|
|
|
$this->locationGateway |
|
|
|
|
410
|
|
|
->expects($this->at(0)) |
411
|
|
|
->method('getBasicNodeData') |
412
|
|
|
->with(69) |
413
|
|
|
->will( |
414
|
|
|
$this->returnValue( |
415
|
|
|
array( |
416
|
|
|
'node_id' => 69, |
417
|
|
|
'path_string' => '/1/2/69/', |
418
|
|
|
'contentobject_id' => 67, |
419
|
|
|
) |
420
|
|
|
) |
421
|
|
|
); |
422
|
|
|
|
423
|
|
|
$this->locationGateway |
|
|
|
|
424
|
|
|
->expects($this->at(1)) |
425
|
|
|
->method('updateSubtreeModificationTime') |
426
|
|
|
->with('/1/2/69/'); |
427
|
|
|
|
428
|
|
|
$handler->markSubtreeModified(69); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler::changeMainLocation |
433
|
|
|
*/ |
434
|
|
|
public function testChangeMainLocation() |
435
|
|
|
{ |
436
|
|
|
$handler = $this->getLocationHandler(); |
437
|
|
|
|
438
|
|
|
$this->treeHandler |
439
|
|
|
->expects($this->once()) |
440
|
|
|
->method('changeMainLocation') |
441
|
|
|
->with(12, 34); |
442
|
|
|
|
443
|
|
|
$handler->changeMainLocation(12, 34); |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Test for the removeSubtree() method. |
448
|
|
|
* |
449
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler::removeSubtree |
450
|
|
|
*/ |
451
|
|
|
public function testRemoveSubtree() |
452
|
|
|
{ |
453
|
|
|
$handler = $this->getLocationHandler(); |
454
|
|
|
|
455
|
|
|
$this->treeHandler |
456
|
|
|
->expects($this->once()) |
457
|
|
|
->method('removeSubtree') |
458
|
|
|
->with(42); |
459
|
|
|
|
460
|
|
|
$handler->removeSubtree(42); |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Test for the copySubtree() method. |
465
|
|
|
* |
466
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler::copySubtree |
467
|
|
|
*/ |
468
|
|
|
public function testCopySubtree() |
469
|
|
|
{ |
470
|
|
|
$handler = $this->getPartlyMockedHandler( |
471
|
|
|
array( |
472
|
|
|
'load', |
473
|
|
|
'changeMainLocation', |
474
|
|
|
'setSectionForSubtree', |
475
|
|
|
'create', |
476
|
|
|
) |
477
|
|
|
); |
478
|
|
|
$subtreeContentRows = array( |
479
|
|
|
array('node_id' => 10, 'main_node_id' => 1, 'parent_node_id' => 3, 'contentobject_id' => 21, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_10', 'sort_field' => 2, 'sort_order' => 1), |
480
|
|
|
array('node_id' => 11, 'main_node_id' => 11, 'parent_node_id' => 10, 'contentobject_id' => 211, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_11', 'sort_field' => 2, 'sort_order' => 1), |
481
|
|
|
array('node_id' => 12, 'main_node_id' => 15, 'parent_node_id' => 10, 'contentobject_id' => 215, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_12', 'sort_field' => 2, 'sort_order' => 1), |
482
|
|
|
array('node_id' => 13, 'main_node_id' => 2, 'parent_node_id' => 10, 'contentobject_id' => 22, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_13', 'sort_field' => 2, 'sort_order' => 1), |
483
|
|
|
array('node_id' => 14, 'main_node_id' => 11, 'parent_node_id' => 13, 'contentobject_id' => 211, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_14', 'sort_field' => 2, 'sort_order' => 1), |
484
|
|
|
array('node_id' => 15, 'main_node_id' => 15, 'parent_node_id' => 13, 'contentobject_id' => 215, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_15', 'sort_field' => 2, 'sort_order' => 1), |
485
|
|
|
array('node_id' => 16, 'main_node_id' => 16, 'parent_node_id' => 15, 'contentobject_id' => 216, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 0, 'priority' => 0, 'path_identification_string' => 'test_16', 'sort_field' => 2, 'sort_order' => 1), |
486
|
|
|
); |
487
|
|
|
$destinationData = array('node_id' => 5, 'main_node_id' => 5, 'parent_node_id' => 4, 'contentobject_id' => 200, 'contentobject_version' => 1, 'is_hidden' => 0, 'is_invisible' => 1, 'path_identification_string' => 'test_destination'); |
488
|
|
|
$mainLocationsMap = array(true, true, true, true, 1011, 1012, true); |
489
|
|
|
$updateMainLocationsMap = array(1215 => 1015); |
490
|
|
|
$offset = 1000; |
491
|
|
|
|
492
|
|
|
$this->locationGateway |
|
|
|
|
493
|
|
|
->expects($this->once()) |
494
|
|
|
->method('getSubtreeContent') |
495
|
|
|
->with($subtreeContentRows[0]['node_id']) |
496
|
|
|
->will($this->returnValue($subtreeContentRows)); |
497
|
|
|
$this->locationGateway |
|
|
|
|
498
|
|
|
->expects($this->once()) |
499
|
|
|
->method('getBasicNodeData') |
500
|
|
|
->with($destinationData['node_id']) |
501
|
|
|
->will($this->returnValue($destinationData)); |
502
|
|
|
|
503
|
|
|
$objectStateHandlerCall = 0; |
504
|
|
|
$this->objectStateHandler->expects($this->at($objectStateHandlerCall++)) |
505
|
|
|
->method('loadAllGroups') |
506
|
|
|
->will( |
507
|
|
|
$this->returnValue( |
508
|
|
|
array( |
509
|
|
|
new ObjectStateGroup(array('id' => 10)), |
510
|
|
|
new ObjectStateGroup(array('id' => 20)), |
511
|
|
|
) |
512
|
|
|
) |
513
|
|
|
); |
514
|
|
|
$this->objectStateHandler->expects($this->at($objectStateHandlerCall++)) |
515
|
|
|
->method('loadObjectStates') |
516
|
|
|
->with($this->equalTo(10)) |
517
|
|
|
->will( |
518
|
|
|
$this->returnValue( |
519
|
|
|
array( |
520
|
|
|
new ObjectState(array('id' => 11, 'groupId' => 10)), |
521
|
|
|
new ObjectState(array('id' => 12, 'groupId' => 10)), |
522
|
|
|
) |
523
|
|
|
) |
524
|
|
|
); |
525
|
|
|
$this->objectStateHandler->expects($this->at($objectStateHandlerCall++)) |
526
|
|
|
->method('loadObjectStates') |
527
|
|
|
->with($this->equalTo(20)) |
528
|
|
|
->will( |
529
|
|
|
$this->returnValue( |
530
|
|
|
array( |
531
|
|
|
new ObjectState(array('id' => 21, 'groupId' => 20)), |
532
|
|
|
new ObjectState(array('id' => 22, 'groupId' => 20)), |
533
|
|
|
) |
534
|
|
|
) |
535
|
|
|
); |
536
|
|
|
$defaultObjectStates = array( |
537
|
|
|
new ObjectState(array('id' => 11, 'groupId' => 10)), |
538
|
|
|
new ObjectState(array('id' => 21, 'groupId' => 20)), |
539
|
|
|
); |
540
|
|
|
|
541
|
|
|
$contentIds = array_values( |
542
|
|
|
array_unique( |
543
|
|
|
array_map( |
544
|
|
|
function ($row) { |
545
|
|
|
return $row['contentobject_id']; |
546
|
|
|
}, |
547
|
|
|
$subtreeContentRows |
548
|
|
|
) |
549
|
|
|
) |
550
|
|
|
); |
551
|
|
|
foreach ($contentIds as $index => $contentId) { |
552
|
|
|
$this->contentHandler |
|
|
|
|
553
|
|
|
->expects($this->at($index * 2)) |
554
|
|
|
->method('copy') |
555
|
|
|
->with($contentId, 1) |
556
|
|
|
->will( |
557
|
|
|
$this->returnValue( |
558
|
|
|
new Content( |
559
|
|
|
array( |
560
|
|
|
'versionInfo' => new VersionInfo( |
561
|
|
|
array( |
562
|
|
|
'contentInfo' => new ContentInfo( |
563
|
|
|
array( |
564
|
|
|
'id' => $contentId + $offset, |
565
|
|
|
'currentVersionNo' => 1, |
566
|
|
|
) |
567
|
|
|
), |
568
|
|
|
) |
569
|
|
|
), |
570
|
|
|
) |
571
|
|
|
) |
572
|
|
|
) |
573
|
|
|
); |
574
|
|
|
|
575
|
|
|
foreach ($defaultObjectStates as $objectState) { |
576
|
|
|
$this->objectStateHandler->expects($this->at($objectStateHandlerCall++)) |
577
|
|
|
->method('setContentState') |
578
|
|
|
->with( |
579
|
|
|
$contentId + $offset, |
580
|
|
|
$objectState->groupId, |
581
|
|
|
$objectState->id |
582
|
|
|
); |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
$this->contentHandler |
|
|
|
|
586
|
|
|
->expects($this->at($index * 2 + 1)) |
587
|
|
|
->method('publish') |
588
|
|
|
->with( |
589
|
|
|
$contentId + $offset, |
590
|
|
|
1, |
591
|
|
|
$this->isInstanceOf(Content\MetadataUpdateStruct::class) |
592
|
|
|
) |
593
|
|
|
->will( |
594
|
|
|
$this->returnValue( |
595
|
|
|
new Content( |
596
|
|
|
array( |
597
|
|
|
'versionInfo' => new VersionInfo( |
598
|
|
|
array( |
599
|
|
|
'contentInfo' => new ContentInfo( |
600
|
|
|
array( |
601
|
|
|
'id' => ($contentId + $offset), |
602
|
|
|
) |
603
|
|
|
), |
604
|
|
|
) |
605
|
|
|
), |
606
|
|
|
) |
607
|
|
|
) |
608
|
|
|
) |
609
|
|
|
); |
610
|
|
|
} |
611
|
|
|
$lastContentHandlerIndex = $index * 2 + 1; |
|
|
|
|
612
|
|
|
|
613
|
|
|
$pathStrings = array($destinationData['node_id'] => $destinationData['path_identification_string']); |
614
|
|
|
foreach ($subtreeContentRows as $index => $row) { |
615
|
|
|
$mapper = new Mapper(); |
616
|
|
|
$createStruct = $mapper->getLocationCreateStruct($row); |
617
|
|
|
$this->locationMapper |
|
|
|
|
618
|
|
|
->expects($this->at($index)) |
619
|
|
|
->method('getLocationCreateStruct') |
620
|
|
|
->with($row) |
621
|
|
|
->will($this->returnValue($createStruct)); |
622
|
|
|
|
623
|
|
|
$createStruct = clone $createStruct; |
624
|
|
|
$createStruct->contentId = $createStruct->contentId + $offset; |
625
|
|
|
$createStruct->parentId = $index === 0 ? $destinationData['node_id'] : $createStruct->parentId + $offset; |
626
|
|
|
$createStruct->invisible = true; |
627
|
|
|
$createStruct->mainLocationId = $mainLocationsMap[$index]; |
628
|
|
|
$createStruct->pathIdentificationString = $pathStrings[$createStruct->parentId] . '/' . $row['path_identification_string']; |
|
|
|
|
629
|
|
|
$pathStrings[$row['node_id'] + $offset] = $createStruct->pathIdentificationString; |
|
|
|
|
630
|
|
|
$handler |
|
|
|
|
631
|
|
|
->expects($this->at($index)) |
632
|
|
|
->method('create') |
633
|
|
|
->with($createStruct) |
634
|
|
|
->will( |
635
|
|
|
$this->returnValue( |
636
|
|
|
new Location( |
637
|
|
|
array( |
638
|
|
|
'id' => $row['node_id'] + $offset, |
639
|
|
|
'contentId' => $row['contentobject_id'], |
640
|
|
|
'hidden' => false, |
641
|
|
|
'invisible' => true, |
642
|
|
|
'pathIdentificationString' => $createStruct->pathIdentificationString, |
|
|
|
|
643
|
|
|
) |
644
|
|
|
) |
645
|
|
|
) |
646
|
|
|
); |
647
|
|
|
} |
648
|
|
|
|
649
|
|
|
foreach ($updateMainLocationsMap as $contentId => $locationId) { |
650
|
|
|
$handler |
|
|
|
|
651
|
|
|
->expects($this->any()) |
652
|
|
|
->method('changeMainLocation') |
653
|
|
|
->with($contentId, $locationId); |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
$handler |
|
|
|
|
657
|
|
|
->expects($this->once()) |
658
|
|
|
->method('load') |
659
|
|
|
->with($destinationData['node_id']) |
660
|
|
|
->will($this->returnValue(new Location(array('contentId' => $destinationData['contentobject_id'])))); |
661
|
|
|
|
662
|
|
|
$this->contentHandler |
|
|
|
|
663
|
|
|
->expects($this->at($lastContentHandlerIndex + 1)) |
664
|
|
|
->method('loadContentInfo') |
665
|
|
|
->with($destinationData['contentobject_id']) |
666
|
|
|
->will($this->returnValue(new ContentInfo(array('sectionId' => 12345)))); |
667
|
|
|
|
668
|
|
|
$this->contentHandler |
|
|
|
|
669
|
|
|
->expects($this->at($lastContentHandlerIndex + 2)) |
670
|
|
|
->method('loadContentInfo') |
671
|
|
|
->with(21) |
672
|
|
|
->will($this->returnValue(new ContentInfo(array('mainLocationId' => 1010)))); |
673
|
|
|
|
674
|
|
|
$handler |
|
|
|
|
675
|
|
|
->expects($this->once()) |
676
|
|
|
->method('setSectionForSubtree') |
677
|
|
|
->with($subtreeContentRows[0]['node_id'] + $offset, 12345); |
678
|
|
|
|
679
|
|
|
$handler->copySubtree( |
680
|
|
|
$subtreeContentRows[0]['node_id'], |
681
|
|
|
$destinationData['node_id'] |
682
|
|
|
); |
683
|
|
|
} |
684
|
|
|
|
685
|
|
|
/** |
686
|
|
|
* Returns the handler to test with $methods mocked. |
687
|
|
|
* |
688
|
|
|
* @param string[] $methods |
689
|
|
|
* |
690
|
|
|
* @return \eZ\Publish\Core\Persistence\Legacy\Content\Location\Handler |
691
|
|
|
*/ |
692
|
|
|
protected function getPartlyMockedHandler(array $methods) |
693
|
|
|
{ |
694
|
|
|
return $this->getMockBuilder(LocationHandler::class) |
695
|
|
|
->setMethods($methods) |
696
|
|
|
->setConstructorArgs( |
697
|
|
|
array( |
698
|
|
|
$this->locationGateway = $this->createMock(Gateway::class), |
|
|
|
|
699
|
|
|
$this->locationMapper = $this->createMock(Mapper::class), |
|
|
|
|
700
|
|
|
$this->contentHandler = $this->createMock(ContentHandler::class), |
|
|
|
|
701
|
|
|
$this->objectStateHandler = $this->createMock(ObjectStateHandler::class), |
702
|
|
|
$this->treeHandler = $this->createMock(TreeHandler::class), |
703
|
|
|
) |
704
|
|
|
) |
705
|
|
|
->getMock(); |
706
|
|
|
} |
707
|
|
|
} |
708
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..