1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* File contains: eZ\Publish\Core\Persistence\Legacy\Tests\Content\Location\Gateway\DoctrineDatabaseTest 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\Location\Gateway; |
10
|
|
|
|
11
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Tests\Content\LanguageAwareTestCase; |
12
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase; |
13
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query\SortClause; |
14
|
|
|
use eZ\Publish\API\Repository\Values\Content\Query; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Test case for eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase. |
18
|
|
|
*/ |
19
|
|
|
class DoctrineDatabaseTrashTest extends LanguageAwareTestCase |
20
|
|
|
{ |
21
|
|
|
protected function getLocationGateway() |
22
|
|
|
{ |
23
|
|
|
$dbHandler = $this->getDatabaseHandler(); |
24
|
|
|
|
25
|
|
|
return new DoctrineDatabase( |
26
|
|
|
$dbHandler, |
27
|
|
|
$this->getLanguageMaskGenerator() |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::trashLocation |
33
|
|
|
* |
34
|
|
|
* @todo test updated content status |
35
|
|
|
*/ |
36
|
|
|
public function testTrashLocation() |
37
|
|
|
{ |
38
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
39
|
|
|
$handler = $this->getLocationGateway(); |
40
|
|
|
$handler->trashLocation(71); |
41
|
|
|
|
42
|
|
|
$query = $this->handler->createSelectQuery(); |
43
|
|
|
$this->assertQueryResult( |
44
|
|
|
[ |
45
|
|
|
[1, 0], |
46
|
|
|
[2, 0], |
47
|
|
|
[69, 0], |
48
|
|
|
[70, 0], |
49
|
|
|
], |
50
|
|
|
$query |
51
|
|
|
->select('node_id', 'priority') |
52
|
|
|
->from('ezcontentobject_tree') |
53
|
|
|
->where($query->expr->in('node_id', [1, 2, 69, 70, 71])) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::trashLocation |
59
|
|
|
*/ |
60
|
|
View Code Duplication |
public function testTrashLocationUpdateTrashTable() |
61
|
|
|
{ |
62
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
63
|
|
|
$handler = $this->getLocationGateway(); |
64
|
|
|
$handler->trashLocation(71); |
65
|
|
|
|
66
|
|
|
$query = $this->handler->createSelectQuery(); |
67
|
|
|
$this->assertQueryResult( |
68
|
|
|
[ |
69
|
|
|
[71, '/1/2/69/70/71/'], |
70
|
|
|
], |
71
|
|
|
$query |
72
|
|
|
->select('node_id', 'path_string') |
73
|
|
|
->from('ezcontentobject_trash') |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
View Code Duplication |
public static function getUntrashedLocationValues() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
['contentobject_is_published', 1], |
81
|
|
|
['contentobject_version', 1], |
82
|
|
|
['depth', 4], |
83
|
|
|
['is_hidden', 0], |
84
|
|
|
['is_invisible', 0], |
85
|
|
|
['main_node_id', 228], |
86
|
|
|
['node_id', 228], |
87
|
|
|
['parent_node_id', 70], |
88
|
|
|
['path_identification_string', ''], |
89
|
|
|
['path_string', '/1/2/69/70/228/'], |
90
|
|
|
['priority', 0], |
91
|
|
|
['remote_id', '087adb763245e0cdcac593fb4a5996cf'], |
92
|
|
|
['sort_field', 1], |
93
|
|
|
['sort_order', 1], |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::untrashLocation |
99
|
|
|
* @dataProvider getUntrashedLocationValues |
100
|
|
|
*/ |
101
|
|
View Code Duplication |
public function testUntrashLocationDefault($property, $value) |
102
|
|
|
{ |
103
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
104
|
|
|
$handler = $this->getLocationGateway(); |
105
|
|
|
$handler->trashLocation(71); |
106
|
|
|
|
107
|
|
|
$handler->untrashLocation(71); |
108
|
|
|
|
109
|
|
|
$query = $this->handler->createSelectQuery(); |
110
|
|
|
$this->assertQueryResult( |
111
|
|
|
[[$value]], |
112
|
|
|
$query |
113
|
|
|
->select($property) |
114
|
|
|
->from('ezcontentobject_tree') |
115
|
|
|
->where($query->expr->in('contentobject_id', [69])) |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::untrashLocation |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public function testUntrashLocationNewParent() |
123
|
|
|
{ |
124
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
125
|
|
|
$handler = $this->getLocationGateway(); |
126
|
|
|
$handler->trashLocation(71); |
127
|
|
|
|
128
|
|
|
$handler->untrashLocation(71, 1); |
129
|
|
|
|
130
|
|
|
$query = $this->handler->createSelectQuery(); |
131
|
|
|
$this->assertQueryResult( |
132
|
|
|
[['228', '1', '/1/228/']], |
133
|
|
|
$query |
134
|
|
|
->select('node_id', 'parent_node_id', 'path_string') |
135
|
|
|
->from('ezcontentobject_tree') |
136
|
|
|
->where($query->expr->in('contentobject_id', [69])) |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::untrashLocation |
142
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
143
|
|
|
*/ |
144
|
|
|
public function testUntrashInvalidLocation() |
145
|
|
|
{ |
146
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
147
|
|
|
$handler = $this->getLocationGateway(); |
148
|
|
|
|
149
|
|
|
$handler->untrashLocation(23); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::untrashLocation |
154
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
155
|
|
|
*/ |
156
|
|
|
public function testUntrashLocationInvalidParent() |
157
|
|
|
{ |
158
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
159
|
|
|
$handler = $this->getLocationGateway(); |
160
|
|
|
$handler->trashLocation(71); |
161
|
|
|
|
162
|
|
|
$handler->untrashLocation(71, 1337); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::untrashLocation |
167
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
168
|
|
|
*/ |
169
|
|
|
public function testUntrashLocationInvalidOldParent() |
170
|
|
|
{ |
171
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
172
|
|
|
$handler = $this->getLocationGateway(); |
173
|
|
|
$handler->trashLocation(71); |
174
|
|
|
$handler->trashLocation(70); |
175
|
|
|
|
176
|
|
|
$handler->untrashLocation(70); |
177
|
|
|
$handler->untrashLocation(71); |
178
|
|
|
} |
179
|
|
|
|
180
|
|
View Code Duplication |
public static function getLoadTrashValues() |
181
|
|
|
{ |
182
|
|
|
return [ |
183
|
|
|
['node_id', 71], |
184
|
|
|
['priority', 0], |
185
|
|
|
['is_hidden', 0], |
186
|
|
|
['is_invisible', 0], |
187
|
|
|
['remote_id', '087adb763245e0cdcac593fb4a5996cf'], |
188
|
|
|
['contentobject_id', 69], |
189
|
|
|
['parent_node_id', 70], |
190
|
|
|
['path_identification_string', 'products/software/os_type_i'], |
191
|
|
|
['path_string', '/1/2/69/70/71/'], |
192
|
|
|
['modified_subnode', 1311065013], |
193
|
|
|
['main_node_id', 71], |
194
|
|
|
['depth', 4], |
195
|
|
|
['sort_field', 1], |
196
|
|
|
['sort_order', 1], |
197
|
|
|
]; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::loadTrashByLocation |
202
|
|
|
* @dataProvider getLoadTrashValues |
203
|
|
|
*/ |
204
|
|
View Code Duplication |
public function testLoadTrashByLocationId($field, $value) |
205
|
|
|
{ |
206
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
207
|
|
|
$handler = $this->getLocationGateway(); |
208
|
|
|
$handler->trashLocation(71); |
209
|
|
|
|
210
|
|
|
$data = $handler->loadTrashByLocation(71); |
211
|
|
|
|
212
|
|
|
$this->assertEquals( |
213
|
|
|
$value, |
214
|
|
|
$data[$field], |
215
|
|
|
"Value in property $field not as expected." |
216
|
|
|
); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::countTrashed |
221
|
|
|
*/ |
222
|
|
|
public function testCountTrashed() |
223
|
|
|
{ |
224
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
225
|
|
|
$handler = $this->getLocationGateway(); |
226
|
|
|
|
227
|
|
|
$this->assertEquals( |
228
|
|
|
0, |
229
|
|
|
$handler->countTrashed() |
230
|
|
|
); |
231
|
|
|
|
232
|
|
|
$this->trashSubtree(); |
233
|
|
|
|
234
|
|
|
$this->assertEquals( |
235
|
|
|
8, |
236
|
|
|
$handler->countTrashed() |
237
|
|
|
); |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
242
|
|
|
*/ |
243
|
|
View Code Duplication |
public function testListEmptyTrash() |
244
|
|
|
{ |
245
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
246
|
|
|
$handler = $this->getLocationGateway(); |
247
|
|
|
|
248
|
|
|
$this->assertEquals( |
249
|
|
|
[], |
250
|
|
|
$handler->listTrashed(0, null, []) |
251
|
|
|
); |
252
|
|
|
} |
253
|
|
|
|
254
|
|
|
protected function trashSubtree() |
255
|
|
|
{ |
256
|
|
|
$handler = $this->getLocationGateway(); |
257
|
|
|
$handler->trashLocation(69); |
258
|
|
|
$handler->trashLocation(70); |
259
|
|
|
$handler->trashLocation(71); |
260
|
|
|
$handler->trashLocation(72); |
261
|
|
|
$handler->trashLocation(73); |
262
|
|
|
$handler->trashLocation(74); |
263
|
|
|
$handler->trashLocation(75); |
264
|
|
|
$handler->trashLocation(76); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
/** |
268
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
269
|
|
|
*/ |
270
|
|
View Code Duplication |
public function testListFullTrash() |
271
|
|
|
{ |
272
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
273
|
|
|
$handler = $this->getLocationGateway(); |
274
|
|
|
$this->trashSubtree(); |
275
|
|
|
|
276
|
|
|
$this->assertEquals( |
277
|
|
|
8, |
278
|
|
|
count($handler->listTrashed(0, null, [])) |
279
|
|
|
); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
/** |
283
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
284
|
|
|
*/ |
285
|
|
View Code Duplication |
public function testListTrashLimited() |
286
|
|
|
{ |
287
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
288
|
|
|
$handler = $this->getLocationGateway(); |
289
|
|
|
$this->trashSubtree(); |
290
|
|
|
|
291
|
|
|
$this->assertEquals( |
292
|
|
|
5, |
293
|
|
|
count($handler->listTrashed(0, 5, [])) |
294
|
|
|
); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
public static function getTrashValues() |
298
|
|
|
{ |
299
|
|
|
return [ |
300
|
|
|
['contentobject_id', 67], |
301
|
|
|
['contentobject_version', 1], |
302
|
|
|
['depth', 2], |
303
|
|
|
['is_hidden', 0], |
304
|
|
|
['is_invisible', 0], |
305
|
|
|
['main_node_id', 69], |
306
|
|
|
['modified_subnode', 1311065014], |
307
|
|
|
['node_id', 69], |
308
|
|
|
['parent_node_id', 2], |
309
|
|
|
['path_identification_string', 'products'], |
310
|
|
|
['path_string', '/1/2/69/'], |
311
|
|
|
['priority', 0], |
312
|
|
|
['remote_id', '9cec85d730eec7578190ee95ce5a36f5'], |
313
|
|
|
['sort_field', 2], |
314
|
|
|
['sort_order', 1], |
315
|
|
|
]; |
316
|
|
|
} |
317
|
|
|
|
318
|
|
|
/** |
319
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
320
|
|
|
* @dataProvider getTrashValues |
321
|
|
|
*/ |
322
|
|
View Code Duplication |
public function testListTrashItem($key, $value) |
323
|
|
|
{ |
324
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
325
|
|
|
$handler = $this->getLocationGateway(); |
326
|
|
|
$this->trashSubtree(); |
327
|
|
|
|
328
|
|
|
$trashList = $handler->listTrashed(0, 1, []); |
329
|
|
|
$this->assertEquals($value, $trashList[0][$key]); |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
/** |
333
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
334
|
|
|
*/ |
335
|
|
View Code Duplication |
public function testListTrashSortedPathStringDesc() |
336
|
|
|
{ |
337
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
338
|
|
|
$handler = $this->getLocationGateway(); |
339
|
|
|
$this->trashSubtree(); |
340
|
|
|
|
341
|
|
|
$this->assertEquals( |
342
|
|
|
[ |
343
|
|
|
'/1/2/69/76/', |
344
|
|
|
'/1/2/69/72/75/', |
345
|
|
|
'/1/2/69/72/74/', |
346
|
|
|
'/1/2/69/72/73/', |
347
|
|
|
'/1/2/69/72/', |
348
|
|
|
'/1/2/69/70/71/', |
349
|
|
|
'/1/2/69/70/', |
350
|
|
|
'/1/2/69/', |
351
|
|
|
], |
352
|
|
|
array_map( |
353
|
|
|
function ($trashItem) { |
354
|
|
|
return $trashItem['path_string']; |
355
|
|
|
}, |
356
|
|
|
$trashList = $handler->listTrashed( |
357
|
|
|
0, |
358
|
|
|
null, |
359
|
|
|
[ |
360
|
|
|
new SortClause\Location\Path(Query::SORT_DESC), |
361
|
|
|
] |
362
|
|
|
) |
363
|
|
|
) |
364
|
|
|
); |
365
|
|
|
} |
366
|
|
|
|
367
|
|
|
/** |
368
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::listTrashed |
369
|
|
|
*/ |
370
|
|
View Code Duplication |
public function testListTrashSortedDepth() |
371
|
|
|
{ |
372
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
373
|
|
|
$handler = $this->getLocationGateway(); |
374
|
|
|
$this->trashSubtree(); |
375
|
|
|
|
376
|
|
|
$this->assertEquals( |
377
|
|
|
[ |
378
|
|
|
'/1/2/69/', |
379
|
|
|
'/1/2/69/76/', |
380
|
|
|
'/1/2/69/72/', |
381
|
|
|
'/1/2/69/70/', |
382
|
|
|
'/1/2/69/72/75/', |
383
|
|
|
'/1/2/69/72/74/', |
384
|
|
|
'/1/2/69/72/73/', |
385
|
|
|
'/1/2/69/70/71/', |
386
|
|
|
], |
387
|
|
|
array_map( |
388
|
|
|
function ($trashItem) { |
389
|
|
|
return $trashItem['path_string']; |
390
|
|
|
}, |
391
|
|
|
$trashList = $handler->listTrashed( |
392
|
|
|
0, |
393
|
|
|
null, |
394
|
|
|
[ |
395
|
|
|
new SortClause\Location\Depth(), |
396
|
|
|
new SortClause\Location\Path(Query::SORT_DESC), |
397
|
|
|
] |
398
|
|
|
) |
399
|
|
|
) |
400
|
|
|
); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::cleanupTrash |
405
|
|
|
*/ |
406
|
|
|
public function testCleanupTrash() |
407
|
|
|
{ |
408
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
409
|
|
|
$handler = $this->getLocationGateway(); |
410
|
|
|
$this->trashSubtree(); |
411
|
|
|
$handler->cleanupTrash(); |
412
|
|
|
|
413
|
|
|
$query = $this->handler->createSelectQuery(); |
414
|
|
|
$this->assertQueryResult( |
415
|
|
|
[], |
416
|
|
|
$query |
417
|
|
|
->select('*') |
418
|
|
|
->from('ezcontentobject_trash') |
419
|
|
|
); |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::removeElementFromTrash |
424
|
|
|
*/ |
425
|
|
|
public function testRemoveElementFromTrash() |
426
|
|
|
{ |
427
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
428
|
|
|
$handler = $this->getLocationGateway(); |
429
|
|
|
$this->trashSubtree(); |
430
|
|
|
$handler->removeElementFromTrash(71); |
431
|
|
|
|
432
|
|
|
$query = $this->handler->createSelectQuery(); |
433
|
|
|
$this->assertQueryResult( |
434
|
|
|
[], |
435
|
|
|
$query |
436
|
|
|
->select('*') |
437
|
|
|
->from('ezcontentobject_trash') |
438
|
|
|
->where($query->expr->eq('node_id', 71)) |
439
|
|
|
); |
440
|
|
|
} |
441
|
|
|
|
442
|
|
|
/** |
443
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::countLocationsByContentId |
444
|
|
|
*/ |
445
|
|
|
public function testCountLocationsByContentId() |
446
|
|
|
{ |
447
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
448
|
|
|
$handler = $this->getLocationGateway(); |
449
|
|
|
|
450
|
|
|
self::assertSame(0, $handler->countLocationsByContentId(123456789)); |
451
|
|
|
self::assertSame(1, $handler->countLocationsByContentId(67)); |
452
|
|
|
|
453
|
|
|
// Insert a new node and count again |
454
|
|
|
$query = $this->handler->createInsertQuery(); |
455
|
|
|
$query |
456
|
|
|
->insertInto('ezcontentobject_tree') |
457
|
|
|
->set('contentobject_id', $query->bindValue(67, null, \PDO::PARAM_INT)) |
458
|
|
|
->set('contentobject_version', $query->bindValue(1, null, \PDO::PARAM_INT)) |
459
|
|
|
->set('path_string', $query->bindValue('/1/2/96')) |
460
|
|
|
->set('parent_node_id', $query->bindValue(96, null, \PDO::PARAM_INT)) |
461
|
|
|
->set('remote_id', $query->bindValue('some_remote_id')); |
462
|
|
|
$query->prepare()->execute(); |
463
|
|
|
self::assertSame(2, $handler->countLocationsByContentId(67)); |
464
|
|
|
} |
465
|
|
|
} |
466
|
|
|
|