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