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\SPI\Persistence\Content\Location; |
13
|
|
|
use eZ\Publish\SPI\Persistence\Content\Location\CreateStruct; |
14
|
|
|
use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase; |
15
|
|
|
use eZ\Publish\Core\Base\Exceptions\NotFoundException; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Test case for eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase. |
19
|
|
|
*/ |
20
|
|
|
class DoctrineDatabaseTest extends LanguageAwareTestCase |
21
|
|
|
{ |
22
|
|
|
protected function getLocationGateway() |
23
|
|
|
{ |
24
|
|
|
$dbHandler = $this->getDatabaseHandler(); |
25
|
|
|
|
26
|
|
|
return new DoctrineDatabase( |
27
|
|
|
$dbHandler, |
28
|
|
|
$this->getLanguageMaskGenerator() |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
private static function getLoadLocationValues(): array |
33
|
|
|
{ |
34
|
|
|
return [ |
35
|
|
|
'node_id' => 77, |
36
|
|
|
'priority' => 0, |
37
|
|
|
'is_hidden' => 0, |
38
|
|
|
'is_invisible' => 0, |
39
|
|
|
'remote_id' => 'dbc2f3c8716c12f32c379dbf0b1cb133', |
40
|
|
|
'contentobject_id' => 75, |
41
|
|
|
'parent_node_id' => 2, |
42
|
|
|
'path_identification_string' => 'solutions', |
43
|
|
|
'path_string' => '/1/2/77/', |
44
|
|
|
'modified_subnode' => 1311065017, |
45
|
|
|
'main_node_id' => 77, |
46
|
|
|
'depth' => 2, |
47
|
|
|
'sort_field' => 2, |
48
|
|
|
'sort_order' => 1, |
49
|
|
|
]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
private function assertLoadLocationProperties(array $locationData): void |
53
|
|
|
{ |
54
|
|
|
foreach (self::getLoadLocationValues() as $field => $expectedValue) { |
55
|
|
|
self::assertEquals( |
56
|
|
|
$expectedValue, |
57
|
|
|
$locationData[$field], |
58
|
|
|
"Value in property $field not as expected." |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testLoadLocationByRemoteId() |
64
|
|
|
{ |
65
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
66
|
|
|
$handler = $this->getLocationGateway(); |
67
|
|
|
$data = $handler->getBasicNodeDataByRemoteId('dbc2f3c8716c12f32c379dbf0b1cb133'); |
68
|
|
|
|
69
|
|
|
self::assertLoadLocationProperties($data); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function testLoadLocation() |
73
|
|
|
{ |
74
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
75
|
|
|
$handler = $this->getLocationGateway(); |
76
|
|
|
$data = $handler->getBasicNodeData(77); |
77
|
|
|
|
78
|
|
|
self::assertLoadLocationProperties($data); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
View Code Duplication |
public function testLoadLocationList() |
82
|
|
|
{ |
83
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
84
|
|
|
$handler = $this->getLocationGateway(); |
85
|
|
|
$locationsData = $handler->getNodeDataList([77]); |
86
|
|
|
|
87
|
|
|
self::assertCount(1, $locationsData); |
88
|
|
|
|
89
|
|
|
$locationRow = reset($locationsData); |
90
|
|
|
|
91
|
|
|
self::assertLoadLocationProperties($locationRow); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException |
96
|
|
|
*/ |
97
|
|
|
public function testLoadInvalidLocation() |
98
|
|
|
{ |
99
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
100
|
|
|
$handler = $this->getLocationGateway(); |
101
|
|
|
$handler->getBasicNodeData(1337); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
View Code Duplication |
public function testLoadLocationDataByContent() |
105
|
|
|
{ |
106
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
107
|
|
|
|
108
|
|
|
$gateway = $this->getLocationGateway(); |
109
|
|
|
|
110
|
|
|
$locationsData = $gateway->loadLocationDataByContent(75); |
111
|
|
|
|
112
|
|
|
self::assertCount(1, $locationsData); |
113
|
|
|
|
114
|
|
|
$locationRow = reset($locationsData); |
115
|
|
|
|
116
|
|
|
self::assertLoadLocationProperties($locationRow); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
View Code Duplication |
public function testLoadParentLocationDataForDraftContentAll() |
120
|
|
|
{ |
121
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
122
|
|
|
|
123
|
|
|
$gateway = $this->getLocationGateway(); |
124
|
|
|
|
125
|
|
|
$locationsData = $gateway->loadParentLocationsDataForDraftContent(226); |
126
|
|
|
|
127
|
|
|
$this->assertCount(1, $locationsData); |
128
|
|
|
|
129
|
|
|
$locationRow = reset($locationsData); |
130
|
|
|
|
131
|
|
|
self::assertLoadLocationProperties($locationRow); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function testLoadLocationDataByContentLimitSubtree() |
135
|
|
|
{ |
136
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
137
|
|
|
|
138
|
|
|
$gateway = $this->getLocationGateway(); |
139
|
|
|
|
140
|
|
|
$locationsData = $gateway->loadLocationDataByContent(75, 3); |
141
|
|
|
|
142
|
|
|
$this->assertCount(0, $locationsData); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
View Code Duplication |
public function testMoveSubtreePathUpdate() |
146
|
|
|
{ |
147
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
148
|
|
|
$handler = $this->getLocationGateway(); |
149
|
|
|
$handler->moveSubtreeNodes( |
150
|
|
|
array( |
151
|
|
|
'path_string' => '/1/2/69/', |
152
|
|
|
'path_identification_string' => 'products', |
153
|
|
|
'is_hidden' => 0, |
154
|
|
|
'is_invisible' => 0, |
155
|
|
|
), |
156
|
|
|
array( |
157
|
|
|
'path_string' => '/1/2/77/', |
158
|
|
|
'path_identification_string' => 'solutions', |
159
|
|
|
'is_hidden' => 0, |
160
|
|
|
'is_invisible' => 0, |
161
|
|
|
) |
162
|
|
|
); |
163
|
|
|
|
164
|
|
|
/** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ |
165
|
|
|
$query = $this->handler->createSelectQuery(); |
166
|
|
|
$this->assertQueryResult( |
167
|
|
|
array( |
168
|
|
|
array(65, '/1/2/', '', 1, 1, 0, 0), |
169
|
|
|
array(67, '/1/2/77/69/', 'solutions/products', 77, 3, 0, 0), |
170
|
|
|
array(69, '/1/2/77/69/70/71/', 'solutions/products/software/os_type_i', 70, 5, 0, 0), |
171
|
|
|
array(73, '/1/2/77/69/72/75/', 'solutions/products/boxes/cd_dvd_box_iii', 72, 5, 0, 0), |
172
|
|
|
array(75, '/1/2/77/', 'solutions', 2, 2, 0, 0), |
173
|
|
|
), |
174
|
|
|
$query |
175
|
|
|
->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') |
176
|
|
|
->from('ezcontentobject_tree') |
177
|
|
|
->where($query->expr->in('node_id', array(69, 71, 75, 77, 2))) |
178
|
|
|
->orderBy('contentobject_id') |
179
|
|
|
); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
View Code Duplication |
public function testMoveHiddenDestinationUpdate() |
183
|
|
|
{ |
184
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
185
|
|
|
$handler = $this->getLocationGateway(); |
186
|
|
|
$handler->hideSubtree('/1/2/77/'); |
187
|
|
|
$handler->moveSubtreeNodes( |
188
|
|
|
array( |
189
|
|
|
'path_string' => '/1/2/69/', |
190
|
|
|
'path_identification_string' => 'products', |
191
|
|
|
'is_hidden' => 0, |
192
|
|
|
'is_invisible' => 0, |
193
|
|
|
), |
194
|
|
|
array( |
195
|
|
|
'path_string' => '/1/2/77/', |
196
|
|
|
'path_identification_string' => 'solutions', |
197
|
|
|
'is_hidden' => 1, |
198
|
|
|
'is_invisible' => 1, |
199
|
|
|
) |
200
|
|
|
); |
201
|
|
|
|
202
|
|
|
/** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ |
203
|
|
|
$query = $this->handler->createSelectQuery(); |
204
|
|
|
$this->assertQueryResult( |
205
|
|
|
array( |
206
|
|
|
array(65, '/1/2/', '', 1, 1, 0, 0), |
207
|
|
|
array(67, '/1/2/77/69/', 'solutions/products', 77, 3, 0, 1), |
208
|
|
|
array(69, '/1/2/77/69/70/71/', 'solutions/products/software/os_type_i', 70, 5, 0, 1), |
209
|
|
|
array(73, '/1/2/77/69/72/75/', 'solutions/products/boxes/cd_dvd_box_iii', 72, 5, 0, 1), |
210
|
|
|
array(75, '/1/2/77/', 'solutions', 2, 2, 1, 1), |
211
|
|
|
), |
212
|
|
|
$query |
213
|
|
|
->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') |
214
|
|
|
->from('ezcontentobject_tree') |
215
|
|
|
->where($query->expr->in('node_id', array(69, 71, 75, 77, 2))) |
216
|
|
|
->orderBy('contentobject_id') |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
View Code Duplication |
public function testMoveHiddenSourceUpdate() |
221
|
|
|
{ |
222
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
223
|
|
|
$handler = $this->getLocationGateway(); |
224
|
|
|
$handler->hideSubtree('/1/2/69/'); |
225
|
|
|
$handler->moveSubtreeNodes( |
226
|
|
|
array( |
227
|
|
|
'path_string' => '/1/2/69/', |
228
|
|
|
'path_identification_string' => 'products', |
229
|
|
|
'is_hidden' => 1, |
230
|
|
|
'is_invisible' => 1, |
231
|
|
|
), |
232
|
|
|
array( |
233
|
|
|
'path_string' => '/1/2/77/', |
234
|
|
|
'path_identification_string' => 'solutions', |
235
|
|
|
'is_hidden' => 0, |
236
|
|
|
'is_invisible' => 0, |
237
|
|
|
) |
238
|
|
|
); |
239
|
|
|
|
240
|
|
|
/** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ |
241
|
|
|
$query = $this->handler->createSelectQuery(); |
242
|
|
|
$this->assertQueryResult( |
243
|
|
|
array( |
244
|
|
|
array(65, '/1/2/', '', 1, 1, 0, 0), |
245
|
|
|
array(67, '/1/2/77/69/', 'solutions/products', 77, 3, 1, 1), |
246
|
|
|
array(69, '/1/2/77/69/70/71/', 'solutions/products/software/os_type_i', 70, 5, 0, 1), |
247
|
|
|
array(73, '/1/2/77/69/72/75/', 'solutions/products/boxes/cd_dvd_box_iii', 72, 5, 0, 1), |
248
|
|
|
array(75, '/1/2/77/', 'solutions', 2, 2, 0, 0), |
249
|
|
|
), |
250
|
|
|
$query |
251
|
|
|
->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') |
252
|
|
|
->from('ezcontentobject_tree') |
253
|
|
|
->where($query->expr->in('node_id', array(69, 71, 75, 77, 2))) |
254
|
|
|
->orderBy('contentobject_id') |
255
|
|
|
); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
public function testMoveHiddenSourceChildUpdate() |
259
|
|
|
{ |
260
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
261
|
|
|
$handler = $this->getLocationGateway(); |
262
|
|
|
$handler->hideSubtree('/1/2/69/70/'); |
263
|
|
|
|
264
|
|
|
$handler->moveSubtreeNodes( |
265
|
|
|
array( |
266
|
|
|
'path_string' => '/1/2/69/', |
267
|
|
|
'path_identification_string' => 'products', |
268
|
|
|
'is_hidden' => 0, |
269
|
|
|
'is_invisible' => 0, |
270
|
|
|
), |
271
|
|
|
array( |
272
|
|
|
'path_string' => '/1/2/77/', |
273
|
|
|
'path_identification_string' => 'solutions', |
274
|
|
|
'is_hidden' => 0, |
275
|
|
|
'is_invisible' => 0, |
276
|
|
|
) |
277
|
|
|
); |
278
|
|
|
|
279
|
|
|
/** @var $query \eZ\Publish\Core\Persistence\Database\SelectQuery */ |
280
|
|
|
$query = $this->handler->createSelectQuery(); |
281
|
|
|
$this->assertQueryResult( |
282
|
|
|
array( |
283
|
|
|
array(65, '/1/2/', '', 1, 1, 0, 0), |
284
|
|
|
array(67, '/1/2/77/69/', 'solutions/products', 77, 3, 0, 0), |
285
|
|
|
array(68, '/1/2/77/69/70/', 'solutions/products/software', 69, 4, 1, 1), |
286
|
|
|
array(69, '/1/2/77/69/70/71/', 'solutions/products/software/os_type_i', 70, 5, 0, 1), |
287
|
|
|
array(73, '/1/2/77/69/72/75/', 'solutions/products/boxes/cd_dvd_box_iii', 72, 5, 0, 0), |
288
|
|
|
array(75, '/1/2/77/', 'solutions', 2, 2, 0, 0), |
289
|
|
|
), |
290
|
|
|
$query |
291
|
|
|
->select('contentobject_id', 'path_string', 'path_identification_string', 'parent_node_id', 'depth', 'is_hidden', 'is_invisible') |
292
|
|
|
->from('ezcontentobject_tree') |
293
|
|
|
->where($query->expr->in('node_id', array(69, 70, 71, 75, 77, 2))) |
294
|
|
|
->orderBy('contentobject_id') |
295
|
|
|
); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
public function testMoveSubtreeAssignmentUpdate() |
299
|
|
|
{ |
300
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
301
|
|
|
$handler = $this->getLocationGateway(); |
302
|
|
|
$handler->updateNodeAssignment(67, 2, 77, 5); |
303
|
|
|
|
304
|
|
|
$query = $this->handler->createSelectQuery(); |
305
|
|
|
$this->assertQueryResult( |
306
|
|
|
array( |
307
|
|
|
array(67, 1, 0, 53, 1, 5, 77, '9cec85d730eec7578190ee95ce5a36f5', 0, 2, 1, 0, 0), |
308
|
|
|
), |
309
|
|
|
$query |
310
|
|
|
->select('*') |
311
|
|
|
->from('eznode_assignment') |
312
|
|
|
->where($query->expr->eq('contentobject_id', 67)) |
313
|
|
|
); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
public function testUpdateSubtreeModificationTime() |
317
|
|
|
{ |
318
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
319
|
|
|
$handler = $this->getLocationGateway(); |
320
|
|
|
$time = time(); |
321
|
|
|
$handler->updateSubtreeModificationTime('/1/2/69/'); |
322
|
|
|
|
323
|
|
|
$query = $this->handler->createSelectQuery(); |
324
|
|
|
$this->assertQueryResult( |
325
|
|
|
array( |
326
|
|
|
array('/1/'), |
327
|
|
|
array('/1/2/'), |
328
|
|
|
array('/1/2/69/'), |
329
|
|
|
), |
330
|
|
|
$query |
331
|
|
|
->select('path_string') |
332
|
|
|
->from('ezcontentobject_tree') |
333
|
|
|
->where($query->expr->gte('modified_subnode', $time)) |
334
|
|
|
->orderBy('path_string') |
335
|
|
|
); |
336
|
|
|
} |
337
|
|
|
|
338
|
|
View Code Duplication |
public function testHideUpdateHidden() |
339
|
|
|
{ |
340
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
341
|
|
|
$handler = $this->getLocationGateway(); |
342
|
|
|
$handler->hideSubtree('/1/2/69/'); |
343
|
|
|
|
344
|
|
|
$query = $this->handler->createSelectQuery(); |
345
|
|
|
$this->assertQueryResult( |
346
|
|
|
array( |
347
|
|
|
array(1, 0, 0), |
348
|
|
|
array(2, 0, 0), |
349
|
|
|
array(69, 1, 1), |
350
|
|
|
array(75, 0, 1), |
351
|
|
|
), |
352
|
|
|
$query |
353
|
|
|
->select('node_id', 'is_hidden', 'is_invisible') |
354
|
|
|
->from('ezcontentobject_tree') |
355
|
|
|
->where($query->expr->in('node_id', array(1, 2, 69, 75))) |
356
|
|
|
->orderBy('node_id') |
357
|
|
|
); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* @depends testHideUpdateHidden |
362
|
|
|
*/ |
363
|
|
View Code Duplication |
public function testHideUnhideUpdateHidden() |
364
|
|
|
{ |
365
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
366
|
|
|
$handler = $this->getLocationGateway(); |
367
|
|
|
$handler->hideSubtree('/1/2/69/'); |
368
|
|
|
$handler->unhideSubtree('/1/2/69/'); |
369
|
|
|
|
370
|
|
|
$query = $this->handler->createSelectQuery(); |
371
|
|
|
$this->assertQueryResult( |
372
|
|
|
array( |
373
|
|
|
array(1, 0, 0), |
374
|
|
|
array(2, 0, 0), |
375
|
|
|
array(69, 0, 0), |
376
|
|
|
array(75, 0, 0), |
377
|
|
|
), |
378
|
|
|
$query |
379
|
|
|
->select('node_id', 'is_hidden', 'is_invisible') |
380
|
|
|
->from('ezcontentobject_tree') |
381
|
|
|
->where($query->expr->in('node_id', array(1, 2, 69, 75))) |
382
|
|
|
->orderBy('node_id') |
383
|
|
|
); |
384
|
|
|
} |
385
|
|
|
|
386
|
|
|
/** |
387
|
|
|
* @depends testHideUpdateHidden |
388
|
|
|
*/ |
389
|
|
View Code Duplication |
public function testHideUnhideParentTree() |
390
|
|
|
{ |
391
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
392
|
|
|
$handler = $this->getLocationGateway(); |
393
|
|
|
$handler->hideSubtree('/1/2/69/'); |
394
|
|
|
$handler->hideSubtree('/1/2/69/70/'); |
395
|
|
|
$handler->unhideSubtree('/1/2/69/'); |
396
|
|
|
|
397
|
|
|
$query = $this->handler->createSelectQuery(); |
398
|
|
|
$this->assertQueryResult( |
399
|
|
|
array( |
400
|
|
|
array(1, 0, 0), |
401
|
|
|
array(2, 0, 0), |
402
|
|
|
array(69, 0, 0), |
403
|
|
|
array(70, 1, 1), |
404
|
|
|
array(71, 0, 1), |
405
|
|
|
array(75, 0, 0), |
406
|
|
|
), |
407
|
|
|
$query |
408
|
|
|
->select('node_id', 'is_hidden', 'is_invisible') |
409
|
|
|
->from('ezcontentobject_tree') |
410
|
|
|
->where($query->expr->in('node_id', array(1, 2, 69, 70, 71, 75))) |
411
|
|
|
->orderBy('node_id') |
412
|
|
|
); |
413
|
|
|
} |
414
|
|
|
|
415
|
|
|
/** |
416
|
|
|
* @depends testHideUpdateHidden |
417
|
|
|
*/ |
418
|
|
View Code Duplication |
public function testHideUnhidePartialSubtree() |
419
|
|
|
{ |
420
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
421
|
|
|
$handler = $this->getLocationGateway(); |
422
|
|
|
$handler->hideSubtree('/1/2/69/'); |
423
|
|
|
$handler->hideSubtree('/1/2/69/70/'); |
424
|
|
|
$handler->unhideSubtree('/1/2/69/70/'); |
425
|
|
|
|
426
|
|
|
$query = $this->handler->createSelectQuery(); |
427
|
|
|
$this->assertQueryResult( |
428
|
|
|
array( |
429
|
|
|
array(1, 0, 0), |
430
|
|
|
array(2, 0, 0), |
431
|
|
|
array(69, 1, 1), |
432
|
|
|
array(70, 0, 1), |
433
|
|
|
array(71, 0, 1), |
434
|
|
|
array(75, 0, 1), |
435
|
|
|
), |
436
|
|
|
$query |
437
|
|
|
->select('node_id', 'is_hidden', 'is_invisible') |
438
|
|
|
->from('ezcontentobject_tree') |
439
|
|
|
->where($query->expr->in('node_id', array(1, 2, 69, 70, 71, 75))) |
440
|
|
|
->orderBy('node_id') |
441
|
|
|
); |
442
|
|
|
} |
443
|
|
|
|
444
|
|
|
public function testSwapLocations() |
445
|
|
|
{ |
446
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
447
|
|
|
$handler = $this->getLocationGateway(); |
448
|
|
|
$handler->swap(70, 78); |
449
|
|
|
|
450
|
|
|
$query = $this->handler->createSelectQuery(); |
451
|
|
|
$this->assertQueryResult( |
452
|
|
|
array( |
453
|
|
|
array(70, 76), |
454
|
|
|
array(78, 68), |
455
|
|
|
), |
456
|
|
|
$query |
457
|
|
|
->select('node_id', 'contentobject_id') |
458
|
|
|
->from('ezcontentobject_tree') |
459
|
|
|
->where($query->expr->in('node_id', array(70, 78))) |
460
|
|
|
->orderBy('node_id') |
461
|
|
|
); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
public function testCreateLocation() |
465
|
|
|
{ |
466
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
467
|
|
|
$handler = $this->getLocationGateway(); |
468
|
|
|
$handler->create( |
469
|
|
|
new CreateStruct( |
470
|
|
|
array( |
471
|
|
|
'contentId' => 68, |
472
|
|
|
'remoteId' => 'some_id', |
473
|
|
|
) |
474
|
|
|
), |
475
|
|
|
array( |
476
|
|
|
'node_id' => '77', |
477
|
|
|
'depth' => '2', |
478
|
|
|
'path_string' => '/1/2/77/', |
479
|
|
|
) |
480
|
|
|
); |
481
|
|
|
|
482
|
|
|
$query = $this->handler->createSelectQuery(); |
483
|
|
|
$this->assertQueryResult( |
484
|
|
|
array( |
485
|
|
|
array(70, '/1/2/69/70/'), |
486
|
|
|
array(77, '/1/2/77/'), |
487
|
|
|
array(228, '/1/2/77/228/'), |
488
|
|
|
), |
489
|
|
|
$query |
490
|
|
|
->select('node_id', 'path_string') |
491
|
|
|
->from('ezcontentobject_tree') |
492
|
|
|
->where($query->expr->in('contentobject_id', array(68, 75))) |
493
|
|
|
->orderBy('node_id') |
494
|
|
|
); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::getMainNodeId |
499
|
|
|
* @depends testCreateLocation |
500
|
|
|
*/ |
501
|
|
|
public function testGetMainNodeId() |
502
|
|
|
{ |
503
|
|
|
// $this->insertDatabaseFixture( __DIR__ . '/_fixtures/full_example_tree.php' ); |
504
|
|
|
$handler = $this->getLocationGateway(); |
505
|
|
|
|
506
|
|
|
$parentLocationData = array( |
507
|
|
|
'node_id' => '77', |
508
|
|
|
'depth' => '2', |
509
|
|
|
'path_string' => '/1/2/77/', |
510
|
|
|
); |
511
|
|
|
|
512
|
|
|
// main location |
513
|
|
|
$mainLocation = $handler->create( |
514
|
|
|
new CreateStruct( |
515
|
|
|
array( |
516
|
|
|
'contentId' => 68, |
517
|
|
|
'contentVersion' => 1, |
518
|
|
|
'remoteId' => 'some_id', |
519
|
|
|
'mainLocationId' => true, |
520
|
|
|
) |
521
|
|
|
), |
522
|
|
|
$parentLocationData |
523
|
|
|
); |
524
|
|
|
|
525
|
|
|
// secondary location |
526
|
|
|
$handler->create( |
527
|
|
|
new CreateStruct( |
528
|
|
|
array( |
529
|
|
|
'contentId' => 68, |
530
|
|
|
'contentVersion' => 1, |
531
|
|
|
'remoteId' => 'some_id', |
532
|
|
|
'mainLocationId' => $mainLocation->id, |
533
|
|
|
) |
534
|
|
|
), |
535
|
|
|
$parentLocationData |
536
|
|
|
); |
537
|
|
|
|
538
|
|
|
$handlerReflection = new \ReflectionObject($handler); |
539
|
|
|
$methodReflection = $handlerReflection->getMethod('getMainNodeId'); |
540
|
|
|
$methodReflection->setAccessible(true); |
541
|
|
|
self::assertEquals($mainLocation->id, $res = $methodReflection->invoke($handler, 68)); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
View Code Duplication |
public static function getCreateLocationValues() |
545
|
|
|
{ |
546
|
|
|
return array( |
547
|
|
|
array('contentobject_id', 68), |
548
|
|
|
array('contentobject_is_published', 1), |
549
|
|
|
array('contentobject_version', 1), |
550
|
|
|
array('depth', 3), |
551
|
|
|
array('is_hidden', 0), |
552
|
|
|
array('is_invisible', 0), |
553
|
|
|
array('main_node_id', 42), |
554
|
|
|
array('parent_node_id', 77), |
555
|
|
|
array('path_identification_string', ''), |
556
|
|
|
array('priority', 1), |
557
|
|
|
array('remote_id', 'some_id'), |
558
|
|
|
array('sort_field', 1), |
559
|
|
|
array('sort_order', 1), |
560
|
|
|
); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* @depends testCreateLocation |
565
|
|
|
* @dataProvider getCreateLocationValues |
566
|
|
|
*/ |
567
|
|
|
public function testCreateLocationValues($field, $value) |
568
|
|
|
{ |
569
|
|
|
if ($value === null) { |
570
|
|
|
$this->markTestIncomplete('Proper value setting yet unknown.'); |
571
|
|
|
} |
572
|
|
|
|
573
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
574
|
|
|
$handler = $this->getLocationGateway(); |
575
|
|
|
$handler->create( |
576
|
|
|
new CreateStruct( |
577
|
|
|
array( |
578
|
|
|
'contentId' => 68, |
579
|
|
|
'contentVersion' => 1, |
580
|
|
|
'mainLocationId' => 42, |
581
|
|
|
'priority' => 1, |
582
|
|
|
'remoteId' => 'some_id', |
583
|
|
|
'sortField' => 1, |
584
|
|
|
'sortOrder' => 1, |
585
|
|
|
) |
586
|
|
|
), |
587
|
|
|
array( |
588
|
|
|
'node_id' => '77', |
589
|
|
|
'depth' => '2', |
590
|
|
|
'path_string' => '/1/2/77/', |
591
|
|
|
) |
592
|
|
|
); |
593
|
|
|
|
594
|
|
|
$query = $this->handler->createSelectQuery(); |
595
|
|
|
$this->assertQueryResult( |
596
|
|
|
array(array($value)), |
597
|
|
|
$query |
598
|
|
|
->select($field) |
599
|
|
|
->from('ezcontentobject_tree') |
600
|
|
|
->where($query->expr->eq('node_id', 228)) |
601
|
|
|
); |
602
|
|
|
} |
603
|
|
|
|
604
|
|
|
public static function getCreateLocationReturnValues() |
605
|
|
|
{ |
606
|
|
|
return array( |
607
|
|
|
array('id', 228), |
608
|
|
|
array('priority', 1), |
609
|
|
|
array('hidden', false), |
610
|
|
|
array('invisible', false), |
611
|
|
|
array('remoteId', 'some_id'), |
612
|
|
|
array('contentId', '68'), |
613
|
|
|
array('parentId', '77'), |
614
|
|
|
array('pathIdentificationString', ''), |
615
|
|
|
array('pathString', '/1/2/77/228/'), |
616
|
|
|
array('depth', 3), |
617
|
|
|
array('sortField', 1), |
618
|
|
|
array('sortOrder', 1), |
619
|
|
|
); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* @depends testCreateLocation |
624
|
|
|
* @dataProvider getCreateLocationReturnValues |
625
|
|
|
*/ |
626
|
|
|
public function testCreateLocationReturnValues($field, $value) |
627
|
|
|
{ |
628
|
|
|
if ($value === null) { |
629
|
|
|
$this->markTestIncomplete('Proper value setting yet unknown.'); |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
633
|
|
|
$handler = $this->getLocationGateway(); |
634
|
|
|
$location = $handler->create( |
635
|
|
|
new CreateStruct( |
636
|
|
|
array( |
637
|
|
|
'contentId' => 68, |
638
|
|
|
'contentVersion' => 1, |
639
|
|
|
'mainLocationId' => true, |
640
|
|
|
'priority' => 1, |
641
|
|
|
'remoteId' => 'some_id', |
642
|
|
|
'sortField' => 1, |
643
|
|
|
'sortOrder' => 1, |
644
|
|
|
) |
645
|
|
|
), |
646
|
|
|
array( |
647
|
|
|
'node_id' => '77', |
648
|
|
|
'depth' => '2', |
649
|
|
|
'path_string' => '/1/2/77/', |
650
|
|
|
) |
651
|
|
|
); |
652
|
|
|
|
653
|
|
|
$this->assertTrue($location instanceof Location); |
654
|
|
|
$this->assertEquals($value, $location->$field); |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
public static function getUpdateLocationData() |
658
|
|
|
{ |
659
|
|
|
return array( |
660
|
|
|
array('priority', 23), |
661
|
|
|
array('remote_id', 'someNewHash'), |
662
|
|
|
array('sort_field', 4), |
663
|
|
|
array('sort_order', 4), |
664
|
|
|
); |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
/** |
668
|
|
|
* @dataProvider getUpdateLocationData |
669
|
|
|
*/ |
670
|
|
View Code Duplication |
public function testUpdateLocation($field, $value) |
671
|
|
|
{ |
672
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
673
|
|
|
$handler = $this->getLocationGateway(); |
674
|
|
|
$handler->update( |
675
|
|
|
new Location\UpdateStruct( |
676
|
|
|
array( |
677
|
|
|
'priority' => 23, |
678
|
|
|
'remoteId' => 'someNewHash', |
679
|
|
|
'sortField' => 4, |
680
|
|
|
'sortOrder' => 4, |
681
|
|
|
) |
682
|
|
|
), |
683
|
|
|
70 |
684
|
|
|
); |
685
|
|
|
|
686
|
|
|
$query = $this->handler->createSelectQuery(); |
687
|
|
|
$this->assertQueryResult( |
688
|
|
|
array(array($value)), |
689
|
|
|
$query |
690
|
|
|
->select($field) |
691
|
|
|
->from('ezcontentobject_tree') |
692
|
|
|
->where($query->expr->in('node_id', array(70))) |
693
|
|
|
); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
View Code Duplication |
public static function getNodeAssignmentValues() |
697
|
|
|
{ |
698
|
|
|
return array( |
699
|
|
|
array('contentobject_version', 1), |
700
|
|
|
array('from_node_id', 0), |
701
|
|
|
array('id', 215), |
702
|
|
|
array('is_main', 0), |
703
|
|
|
array('op_code', 3), |
704
|
|
|
array('parent_node', 77), |
705
|
|
|
array('parent_remote_id', 'some_id'), |
706
|
|
|
array('remote_id', '0'), |
707
|
|
|
array('sort_field', 2), |
708
|
|
|
array('sort_order', 0), |
709
|
|
|
array('is_main', 0), |
710
|
|
|
array('priority', 1), |
711
|
|
|
array('is_hidden', 1), |
712
|
|
|
); |
713
|
|
|
} |
714
|
|
|
|
715
|
|
|
/** |
716
|
|
|
* @depends testCreateLocation |
717
|
|
|
* @dataProvider getNodeAssignmentValues |
718
|
|
|
*/ |
719
|
|
View Code Duplication |
public function testCreateLocationNodeAssignmentCreation($field, $value) |
720
|
|
|
{ |
721
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
722
|
|
|
$handler = $this->getLocationGateway(); |
723
|
|
|
$handler->createNodeAssignment( |
724
|
|
|
new CreateStruct( |
725
|
|
|
array( |
726
|
|
|
'contentId' => 68, |
727
|
|
|
'contentVersion' => 1, |
728
|
|
|
'mainLocationId' => 1, |
729
|
|
|
'priority' => 1, |
730
|
|
|
'remoteId' => 'some_id', |
731
|
|
|
'sortField' => 2, |
732
|
|
|
'sortOrder' => 0, |
733
|
|
|
'hidden' => 1, |
734
|
|
|
) |
735
|
|
|
), |
736
|
|
|
'77', |
737
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
738
|
|
|
); |
739
|
|
|
|
740
|
|
|
$query = $this->handler->createSelectQuery(); |
741
|
|
|
$this->assertQueryResult( |
742
|
|
|
array(array($value)), |
743
|
|
|
$query |
744
|
|
|
->select($field) |
745
|
|
|
->from('eznode_assignment') |
746
|
|
|
->where( |
747
|
|
|
$query->expr->lAnd( |
748
|
|
|
$query->expr->eq('contentobject_id', 68), |
749
|
|
|
$query->expr->eq('parent_node', 77) |
750
|
|
|
) |
751
|
|
|
) |
752
|
|
|
); |
753
|
|
|
} |
754
|
|
|
|
755
|
|
|
/** |
756
|
|
|
* @depends testCreateLocation |
757
|
|
|
*/ |
758
|
|
View Code Duplication |
public function testCreateLocationNodeAssignmentCreationMainLocation() |
759
|
|
|
{ |
760
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
761
|
|
|
$handler = $this->getLocationGateway(); |
762
|
|
|
$handler->createNodeAssignment( |
763
|
|
|
new CreateStruct( |
764
|
|
|
array( |
765
|
|
|
'contentId' => 68, |
766
|
|
|
'contentVersion' => 1, |
767
|
|
|
'mainLocationId' => true, |
768
|
|
|
'priority' => 1, |
769
|
|
|
'remoteId' => 'some_id', |
770
|
|
|
'sortField' => 1, |
771
|
|
|
'sortOrder' => 1, |
772
|
|
|
) |
773
|
|
|
), |
774
|
|
|
'77', |
775
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
776
|
|
|
); |
777
|
|
|
|
778
|
|
|
$query = $this->handler->createSelectQuery(); |
779
|
|
|
$this->assertQueryResult( |
780
|
|
|
array(array(1)), |
781
|
|
|
$query |
782
|
|
|
->select('is_main') |
783
|
|
|
->from('eznode_assignment') |
784
|
|
|
->where( |
785
|
|
|
$query->expr->lAnd( |
786
|
|
|
$query->expr->eq('contentobject_id', 68), |
787
|
|
|
$query->expr->eq('parent_node', 77) |
788
|
|
|
) |
789
|
|
|
) |
790
|
|
|
); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::updateLocationsContentVersionNo |
795
|
|
|
*/ |
796
|
|
|
public function testUpdateLocationsContentVersionNo() |
797
|
|
|
{ |
798
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
799
|
|
|
$gateway = $this->getLocationGateway(); |
800
|
|
|
|
801
|
|
|
$gateway->create( |
802
|
|
|
new CreateStruct( |
803
|
|
|
array( |
804
|
|
|
'contentId' => 4096, |
805
|
|
|
'remoteId' => 'some_id', |
806
|
|
|
'contentVersion' => 1, |
807
|
|
|
) |
808
|
|
|
), |
809
|
|
|
array( |
810
|
|
|
'node_id' => '77', |
811
|
|
|
'depth' => '2', |
812
|
|
|
'path_string' => '/1/2/77/', |
813
|
|
|
) |
814
|
|
|
); |
815
|
|
|
|
816
|
|
|
$gateway->updateLocationsContentVersionNo(4096, 2); |
817
|
|
|
|
818
|
|
|
$query = $this->handler->createSelectQuery(); |
819
|
|
|
$this->assertQueryResult( |
820
|
|
|
array( |
821
|
|
|
array(2), |
822
|
|
|
), |
823
|
|
|
$query->select( |
824
|
|
|
'contentobject_version' |
825
|
|
|
)->from( |
826
|
|
|
'ezcontentobject_tree' |
827
|
|
|
)->where( |
828
|
|
|
$query->expr->eq( |
829
|
|
|
'contentobject_id', |
830
|
|
|
4096 |
831
|
|
|
) |
832
|
|
|
) |
833
|
|
|
); |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::deleteNodeAssignment |
838
|
|
|
*/ |
839
|
|
|
public function testDeleteNodeAssignment() |
840
|
|
|
{ |
841
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
842
|
|
|
$handler = $this->getLocationGateway(); |
843
|
|
|
|
844
|
|
|
$handler->deleteNodeAssignment(11); |
845
|
|
|
|
846
|
|
|
$query = $this->handler->createSelectQuery(); |
847
|
|
|
$this->assertQueryResult( |
848
|
|
|
array(array(0)), |
849
|
|
|
$query |
850
|
|
|
->select('count(*)') |
851
|
|
|
->from('eznode_assignment') |
852
|
|
|
->where( |
853
|
|
|
$query->expr->lAnd( |
854
|
|
|
$query->expr->eq('contentobject_id', 11) |
855
|
|
|
) |
856
|
|
|
) |
857
|
|
|
); |
858
|
|
|
} |
859
|
|
|
|
860
|
|
|
/** |
861
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::deleteNodeAssignment |
862
|
|
|
*/ |
863
|
|
|
public function testDeleteNodeAssignmentWithSecondArgument() |
864
|
|
|
{ |
865
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
866
|
|
|
$handler = $this->getLocationGateway(); |
867
|
|
|
|
868
|
|
|
$query = $this->handler->createSelectQuery(); |
869
|
|
|
$query |
870
|
|
|
->select('count(*)') |
871
|
|
|
->from('eznode_assignment') |
872
|
|
|
->where( |
873
|
|
|
$query->expr->lAnd( |
874
|
|
|
$query->expr->eq('contentobject_id', 11) |
875
|
|
|
) |
876
|
|
|
); |
877
|
|
|
$statement = $query->prepare(); |
878
|
|
|
$statement->execute(); |
879
|
|
|
$nodeAssignmentsCount = (int)$statement->fetchColumn(); |
880
|
|
|
|
881
|
|
|
$handler->deleteNodeAssignment(11, 1); |
882
|
|
|
|
883
|
|
|
$query = $this->handler->createSelectQuery(); |
884
|
|
|
$this->assertQueryResult( |
885
|
|
|
array(array($nodeAssignmentsCount - 1)), |
886
|
|
|
$query |
887
|
|
|
->select('count(*)') |
888
|
|
|
->from('eznode_assignment') |
889
|
|
|
->where( |
890
|
|
|
$query->expr->lAnd( |
891
|
|
|
$query->expr->eq('contentobject_id', 11) |
892
|
|
|
) |
893
|
|
|
) |
894
|
|
|
); |
895
|
|
|
} |
896
|
|
|
|
897
|
|
|
public static function getConvertNodeAssignmentsLocationValues() |
898
|
|
|
{ |
899
|
|
|
return array( |
900
|
|
|
array('contentobject_id', '68'), |
901
|
|
|
array('contentobject_is_published', '1'), |
902
|
|
|
array('contentobject_version', '1'), |
903
|
|
|
array('depth', '3'), |
904
|
|
|
array('is_hidden', '1'), |
905
|
|
|
array('is_invisible', '1'), |
906
|
|
|
array('main_node_id', '70'), |
907
|
|
|
array('modified_subnode', time()), |
908
|
|
|
array('node_id', '228'), |
909
|
|
|
array('parent_node_id', '77'), |
910
|
|
|
array('path_identification_string', null), |
911
|
|
|
array('path_string', '/1/2/77/228/'), |
912
|
|
|
array('priority', '101'), |
913
|
|
|
array('remote_id', 'some_id'), |
914
|
|
|
array('sort_field', '1'), |
915
|
|
|
array('sort_order', '1'), |
916
|
|
|
); |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
/** |
920
|
|
|
* @depends testCreateLocationNodeAssignmentCreation |
921
|
|
|
* @dataProvider getConvertNodeAssignmentsLocationValues |
922
|
|
|
*/ |
923
|
|
|
public function testConvertNodeAssignments($field, $value) |
924
|
|
|
{ |
925
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
926
|
|
|
|
927
|
|
|
$handler = $this->getLocationGateway(); |
928
|
|
|
$handler->createNodeAssignment( |
929
|
|
|
new CreateStruct( |
930
|
|
|
array( |
931
|
|
|
'contentId' => 68, |
932
|
|
|
'contentVersion' => 1, |
933
|
|
|
'mainLocationId' => false, |
934
|
|
|
'priority' => 101, |
935
|
|
|
'remoteId' => 'some_id', |
936
|
|
|
'sortField' => 1, |
937
|
|
|
'sortOrder' => 1, |
938
|
|
|
'hidden' => true, |
939
|
|
|
// Note: not stored in node assignment, will be calculated from parent |
940
|
|
|
// visibility upon Location creation from node assignment |
941
|
|
|
'invisible' => false, |
942
|
|
|
) |
943
|
|
|
), |
944
|
|
|
'77', |
945
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
946
|
|
|
); |
947
|
|
|
|
948
|
|
|
$handler->createLocationsFromNodeAssignments(68, 1); |
949
|
|
|
|
950
|
|
|
$query = $this->handler->createSelectQuery(); |
951
|
|
|
$query |
952
|
|
|
->select($field) |
953
|
|
|
->from('ezcontentobject_tree') |
954
|
|
|
->where( |
955
|
|
|
$query->expr->lAnd( |
956
|
|
|
$query->expr->eq('contentobject_id', 68), |
957
|
|
|
$query->expr->eq('parent_node_id', 77) |
958
|
|
|
) |
959
|
|
|
); |
960
|
|
|
|
961
|
|
|
if ($field === 'modified_subnode') { |
962
|
|
|
$statement = $query->prepare(); |
963
|
|
|
$statement->execute(); |
964
|
|
|
$result = $statement->fetch(\PDO::FETCH_ASSOC); |
965
|
|
|
$this->assertGreaterThanOrEqual($value, $result); |
966
|
|
|
} else { |
967
|
|
|
$this->assertQueryResult( |
968
|
|
|
array(array($value)), |
969
|
|
|
$query |
970
|
|
|
); |
971
|
|
|
} |
972
|
|
|
} |
973
|
|
|
|
974
|
|
|
/** |
975
|
|
|
* @depends testCreateLocationNodeAssignmentCreation |
976
|
|
|
*/ |
977
|
|
View Code Duplication |
public function testConvertNodeAssignmentsMainLocation() |
978
|
|
|
{ |
979
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
980
|
|
|
|
981
|
|
|
$handler = $this->getLocationGateway(); |
982
|
|
|
$handler->createNodeAssignment( |
983
|
|
|
new CreateStruct( |
984
|
|
|
array( |
985
|
|
|
'contentId' => 68, |
986
|
|
|
'contentVersion' => 1, |
987
|
|
|
'mainLocationId' => true, |
988
|
|
|
'priority' => 101, |
989
|
|
|
'remoteId' => 'some_id', |
990
|
|
|
'sortField' => 1, |
991
|
|
|
'sortOrder' => 1, |
992
|
|
|
'hidden' => true, |
993
|
|
|
// Note: not stored in node assignment, will be calculated from parent |
994
|
|
|
// visibility upon Location creation from node assignment |
995
|
|
|
'invisible' => false, |
996
|
|
|
) |
997
|
|
|
), |
998
|
|
|
'77', |
999
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
1000
|
|
|
); |
1001
|
|
|
|
1002
|
|
|
$handler->createLocationsFromNodeAssignments(68, 1); |
1003
|
|
|
|
1004
|
|
|
$query = $this->handler->createSelectQuery(); |
1005
|
|
|
$this->assertQueryResult( |
1006
|
|
|
array(array(228)), |
1007
|
|
|
$query |
1008
|
|
|
->select('main_node_id') |
1009
|
|
|
->from('ezcontentobject_tree') |
1010
|
|
|
->where( |
1011
|
|
|
$query->expr->lAnd( |
1012
|
|
|
$query->expr->eq('contentobject_id', 68), |
1013
|
|
|
$query->expr->eq('parent_node_id', 77) |
1014
|
|
|
) |
1015
|
|
|
) |
1016
|
|
|
); |
1017
|
|
|
} |
1018
|
|
|
|
1019
|
|
|
/** |
1020
|
|
|
* @depends testCreateLocationNodeAssignmentCreation |
1021
|
|
|
*/ |
1022
|
|
View Code Duplication |
public function testConvertNodeAssignmentsParentHidden() |
1023
|
|
|
{ |
1024
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1025
|
|
|
|
1026
|
|
|
$handler = $this->getLocationGateway(); |
1027
|
|
|
$handler->createNodeAssignment( |
1028
|
|
|
new CreateStruct( |
1029
|
|
|
array( |
1030
|
|
|
'contentId' => 68, |
1031
|
|
|
'contentVersion' => 1, |
1032
|
|
|
'mainLocationId' => true, |
1033
|
|
|
'priority' => 101, |
1034
|
|
|
'remoteId' => 'some_id', |
1035
|
|
|
'sortField' => 1, |
1036
|
|
|
'sortOrder' => 1, |
1037
|
|
|
'hidden' => false, |
1038
|
|
|
// Note: not stored in node assignment, will be calculated from parent |
1039
|
|
|
// visibility upon Location creation from node assignment |
1040
|
|
|
'invisible' => false, |
1041
|
|
|
) |
1042
|
|
|
), |
1043
|
|
|
'224', |
1044
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
1045
|
|
|
); |
1046
|
|
|
|
1047
|
|
|
$handler->createLocationsFromNodeAssignments(68, 1); |
1048
|
|
|
|
1049
|
|
|
$query = $this->handler->createSelectQuery(); |
1050
|
|
|
$this->assertQueryResult( |
1051
|
|
|
array(array(0, 1)), |
1052
|
|
|
$query |
1053
|
|
|
->select('is_hidden, is_invisible') |
1054
|
|
|
->from('ezcontentobject_tree') |
1055
|
|
|
->where( |
1056
|
|
|
$query->expr->lAnd( |
1057
|
|
|
$query->expr->eq('contentobject_id', 68), |
1058
|
|
|
$query->expr->eq('parent_node_id', 224) |
1059
|
|
|
) |
1060
|
|
|
) |
1061
|
|
|
); |
1062
|
|
|
} |
1063
|
|
|
|
1064
|
|
|
/** |
1065
|
|
|
* @depends testCreateLocationNodeAssignmentCreation |
1066
|
|
|
*/ |
1067
|
|
View Code Duplication |
public function testConvertNodeAssignmentsParentInvisible() |
1068
|
|
|
{ |
1069
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1070
|
|
|
|
1071
|
|
|
$handler = $this->getLocationGateway(); |
1072
|
|
|
$handler->createNodeAssignment( |
1073
|
|
|
new CreateStruct( |
1074
|
|
|
array( |
1075
|
|
|
'contentId' => 68, |
1076
|
|
|
'contentVersion' => 1, |
1077
|
|
|
'mainLocationId' => true, |
1078
|
|
|
'priority' => 101, |
1079
|
|
|
'remoteId' => 'some_id', |
1080
|
|
|
'sortField' => 1, |
1081
|
|
|
'sortOrder' => 1, |
1082
|
|
|
'hidden' => false, |
1083
|
|
|
// Note: not stored in node assignment, will be calculated from parent |
1084
|
|
|
// visibility upon Location creation from node assignment |
1085
|
|
|
'invisible' => false, |
1086
|
|
|
) |
1087
|
|
|
), |
1088
|
|
|
'225', |
1089
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
1090
|
|
|
); |
1091
|
|
|
|
1092
|
|
|
$handler->createLocationsFromNodeAssignments(68, 1); |
1093
|
|
|
|
1094
|
|
|
$query = $this->handler->createSelectQuery(); |
1095
|
|
|
$this->assertQueryResult( |
1096
|
|
|
array(array(0, 1)), |
1097
|
|
|
$query |
1098
|
|
|
->select('is_hidden, is_invisible') |
1099
|
|
|
->from('ezcontentobject_tree') |
1100
|
|
|
->where( |
1101
|
|
|
$query->expr->lAnd( |
1102
|
|
|
$query->expr->eq('contentobject_id', 68), |
1103
|
|
|
$query->expr->eq('parent_node_id', 225) |
1104
|
|
|
) |
1105
|
|
|
) |
1106
|
|
|
); |
1107
|
|
|
} |
1108
|
|
|
|
1109
|
|
|
/** |
1110
|
|
|
* @depends testCreateLocationNodeAssignmentCreation |
1111
|
|
|
*/ |
1112
|
|
View Code Duplication |
public function testConvertNodeAssignmentsUpdateAssignment() |
1113
|
|
|
{ |
1114
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1115
|
|
|
|
1116
|
|
|
$handler = $this->getLocationGateway(); |
1117
|
|
|
$handler->createNodeAssignment( |
1118
|
|
|
new CreateStruct( |
1119
|
|
|
array( |
1120
|
|
|
'contentId' => 68, |
1121
|
|
|
'contentVersion' => 1, |
1122
|
|
|
'mainLocationId' => 1, |
1123
|
|
|
'priority' => 1, |
1124
|
|
|
'remoteId' => 'some_id', |
1125
|
|
|
'sortField' => 1, |
1126
|
|
|
'sortOrder' => 1, |
1127
|
|
|
) |
1128
|
|
|
), |
1129
|
|
|
'77', |
1130
|
|
|
DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE |
1131
|
|
|
); |
1132
|
|
|
|
1133
|
|
|
$handler->createLocationsFromNodeAssignments(68, 1); |
1134
|
|
|
|
1135
|
|
|
$query = $this->handler->createSelectQuery(); |
1136
|
|
|
$this->assertQueryResult( |
1137
|
|
|
array(array(DoctrineDatabase::NODE_ASSIGNMENT_OP_CODE_CREATE_NOP)), |
1138
|
|
|
$query |
1139
|
|
|
->select('op_code') |
1140
|
|
|
->from('eznode_assignment') |
1141
|
|
|
->where( |
1142
|
|
|
$query->expr->lAnd( |
1143
|
|
|
$query->expr->eq('contentobject_id', 68), |
1144
|
|
|
$query->expr->eq('parent_node', 77) |
1145
|
|
|
) |
1146
|
|
|
) |
1147
|
|
|
); |
1148
|
|
|
} |
1149
|
|
|
|
1150
|
|
|
/** |
1151
|
|
|
* Test for the setSectionForSubtree() method. |
1152
|
|
|
* |
1153
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::setSectionForSubtree |
1154
|
|
|
*/ |
1155
|
|
|
public function testSetSectionForSubtree() |
1156
|
|
|
{ |
1157
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/../../_fixtures/contentobjects.php'); |
1158
|
|
|
$handler = $this->getLocationGateway(); |
1159
|
|
|
$handler->setSectionForSubtree('/1/2/69/70/', 23); |
1160
|
|
|
|
1161
|
|
|
$query = $this->handler->createSelectQuery(); |
1162
|
|
|
$this->assertQueryResult( |
1163
|
|
|
array(array(68), array(69)), |
1164
|
|
|
$query |
1165
|
|
|
->select('id') |
1166
|
|
|
->from('ezcontentobject') |
1167
|
|
|
->where($query->expr->eq('section_id', 23)) |
1168
|
|
|
); |
1169
|
|
|
} |
1170
|
|
|
|
1171
|
|
|
/** |
1172
|
|
|
* Test for the changeMainLocation() method. |
1173
|
|
|
* |
1174
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::changeMainLocation |
1175
|
|
|
*/ |
1176
|
|
|
public function testChangeMainLocation() |
1177
|
|
|
{ |
1178
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1179
|
|
|
// Create additional location and assignment for test purpose |
1180
|
|
|
$query = $this->handler->createInsertQuery(); |
1181
|
|
|
$query->insertInto($this->handler->quoteTable('ezcontentobject_tree')) |
1182
|
|
|
->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue(10, null, \PDO::PARAM_INT)) |
1183
|
|
|
->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue(2, null, \PDO::PARAM_INT)) |
1184
|
|
|
->set($this->handler->quoteColumn('main_node_id'), $query->bindValue(15, null, \PDO::PARAM_INT)) |
1185
|
|
|
->set($this->handler->quoteColumn('node_id'), $query->bindValue(228, null, \PDO::PARAM_INT)) |
1186
|
|
|
->set($this->handler->quoteColumn('parent_node_id'), $query->bindValue(227, null, \PDO::PARAM_INT)) |
1187
|
|
|
->set($this->handler->quoteColumn('path_string'), $query->bindValue('/1/5/13/228/', null, \PDO::PARAM_STR)) |
1188
|
|
|
->set($this->handler->quoteColumn('remote_id'), $query->bindValue('asdfg123437', null, \PDO::PARAM_STR)); |
1189
|
|
|
$query->prepare()->execute(); |
1190
|
|
|
$query = $this->handler->createInsertQuery(); |
1191
|
|
|
$query->insertInto($this->handler->quoteTable('eznode_assignment')) |
1192
|
|
|
->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue(10, null, \PDO::PARAM_INT)) |
1193
|
|
|
->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue(2, null, \PDO::PARAM_INT)) |
1194
|
|
|
->set($this->handler->quoteColumn('id'), $query->bindValue(0, null, \PDO::PARAM_INT)) |
1195
|
|
|
->set($this->handler->quoteColumn('is_main'), $query->bindValue(0, null, \PDO::PARAM_INT)) |
1196
|
|
|
->set($this->handler->quoteColumn('parent_node'), $query->bindValue(227, null, \PDO::PARAM_INT)) |
1197
|
|
|
->set($this->handler->quoteColumn('parent_remote_id'), $query->bindValue('5238a276bf8231fbcf8a986cdc82a6a5', null, \PDO::PARAM_STR)); |
1198
|
|
|
$query->prepare()->execute(); |
1199
|
|
|
|
1200
|
|
|
$gateway = $this->getLocationGateway(); |
1201
|
|
|
|
1202
|
|
|
$gateway->changeMainLocation( |
1203
|
|
|
10, // content id |
1204
|
|
|
228, // new main location id |
1205
|
|
|
2, // content version number |
1206
|
|
|
227 // new main location parent id |
1207
|
|
|
); |
1208
|
|
|
|
1209
|
|
|
$query = $this->handler->createSelectQuery(); |
1210
|
|
|
$this->assertQueryResult( |
1211
|
|
|
array(array(228), array(228)), |
1212
|
|
|
$query->select( |
1213
|
|
|
'main_node_id' |
1214
|
|
|
)->from( |
1215
|
|
|
'ezcontentobject_tree' |
1216
|
|
|
)->where( |
1217
|
|
|
$query->expr->eq('contentobject_id', 10) |
1218
|
|
|
) |
1219
|
|
|
); |
1220
|
|
|
|
1221
|
|
|
$query = $this->handler->createSelectQuery(); |
1222
|
|
|
$this->assertQueryResult( |
1223
|
|
|
array(array(1)), |
1224
|
|
|
$query->select( |
1225
|
|
|
'is_main' |
1226
|
|
|
)->from( |
1227
|
|
|
'eznode_assignment' |
1228
|
|
|
)->where( |
1229
|
|
|
$query->expr->lAnd( |
1230
|
|
|
$query->expr->eq('contentobject_id', 10), |
1231
|
|
|
$query->expr->eq('contentobject_version', 2), |
1232
|
|
|
$query->expr->eq('parent_node', 227) |
1233
|
|
|
) |
1234
|
|
|
) |
1235
|
|
|
); |
1236
|
|
|
|
1237
|
|
|
$query = $this->handler->createSelectQuery(); |
1238
|
|
|
$this->assertQueryResult( |
1239
|
|
|
array(array(0)), |
1240
|
|
|
$query->select( |
1241
|
|
|
'is_main' |
1242
|
|
|
)->from( |
1243
|
|
|
'eznode_assignment' |
1244
|
|
|
)->where( |
1245
|
|
|
$query->expr->lAnd( |
1246
|
|
|
$query->expr->eq('contentobject_id', 10), |
1247
|
|
|
$query->expr->eq('contentobject_version', 2), |
1248
|
|
|
$query->expr->eq('parent_node', 44) |
1249
|
|
|
) |
1250
|
|
|
) |
1251
|
|
|
); |
1252
|
|
|
} |
1253
|
|
|
|
1254
|
|
|
/** |
1255
|
|
|
* Test for the getChildren() method. |
1256
|
|
|
* |
1257
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::getChildren |
1258
|
|
|
*/ |
1259
|
|
|
public function testGetChildren() |
1260
|
|
|
{ |
1261
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1262
|
|
|
|
1263
|
|
|
$gateway = $this->getLocationGateway(); |
1264
|
|
|
$childrenRows = $gateway->getChildren(213); |
1265
|
|
|
|
1266
|
|
|
$this->assertCount(2, $childrenRows); |
1267
|
|
|
$this->assertCount(16, $childrenRows[0]); |
1268
|
|
|
$this->assertEquals(214, $childrenRows[0]['node_id']); |
1269
|
|
|
$this->assertCount(16, $childrenRows[1]); |
1270
|
|
|
$this->assertEquals(215, $childrenRows[1]['node_id']); |
1271
|
|
|
} |
1272
|
|
|
|
1273
|
|
|
/** |
1274
|
|
|
* Test for the getFallbackMainNodeData() method. |
1275
|
|
|
* |
1276
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::getFallbackMainNodeData |
1277
|
|
|
*/ |
1278
|
|
|
public function testGetFallbackMainNodeData() |
1279
|
|
|
{ |
1280
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1281
|
|
|
// Create additional location for test purpose |
1282
|
|
|
$query = $this->handler->createInsertQuery(); |
1283
|
|
|
$query->insertInto($this->handler->quoteTable('ezcontentobject_tree')) |
1284
|
|
|
->set($this->handler->quoteColumn('contentobject_id'), $query->bindValue(12, null, \PDO::PARAM_INT)) |
1285
|
|
|
->set($this->handler->quoteColumn('contentobject_version'), $query->bindValue(1, null, \PDO::PARAM_INT)) |
1286
|
|
|
->set($this->handler->quoteColumn('main_node_id'), $query->bindValue(13, null, \PDO::PARAM_INT)) |
1287
|
|
|
->set($this->handler->quoteColumn('node_id'), $query->bindValue(228, null, \PDO::PARAM_INT)) |
1288
|
|
|
->set($this->handler->quoteColumn('parent_node_id'), $query->bindValue(227, null, \PDO::PARAM_INT)) |
1289
|
|
|
->set($this->handler->quoteColumn('path_string'), $query->bindValue('/1/5/13/228/', null, \PDO::PARAM_STR)) |
1290
|
|
|
->set($this->handler->quoteColumn('remote_id'), $query->bindValue('asdfg123437', null, \PDO::PARAM_STR)); |
1291
|
|
|
$query->prepare()->execute(); |
1292
|
|
|
|
1293
|
|
|
$gateway = $this->getLocationGateway(); |
1294
|
|
|
$data = $gateway->getFallbackMainNodeData(12, 13); |
1295
|
|
|
|
1296
|
|
|
$this->assertEquals(228, $data['node_id']); |
1297
|
|
|
$this->assertEquals(1, $data['contentobject_version']); |
1298
|
|
|
$this->assertEquals(227, $data['parent_node_id']); |
1299
|
|
|
} |
1300
|
|
|
|
1301
|
|
|
/** |
1302
|
|
|
* Test for the removeLocation() method. |
1303
|
|
|
* |
1304
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::removeLocation |
1305
|
|
|
*/ |
1306
|
|
|
public function testRemoveLocation() |
1307
|
|
|
{ |
1308
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1309
|
|
|
|
1310
|
|
|
$gateway = $this->getLocationGateway(); |
1311
|
|
|
$gateway->removeLocation(13); |
1312
|
|
|
|
1313
|
|
|
try { |
1314
|
|
|
$gateway->getBasicNodeData(13); |
1315
|
|
|
$this->fail('Location was not deleted!'); |
1316
|
|
|
} catch (NotFoundException $e) { |
1317
|
|
|
// Do nothing |
1318
|
|
|
} |
1319
|
|
|
} |
1320
|
|
|
|
1321
|
|
|
public function providerForTestUpdatePathIdentificationString() |
1322
|
|
|
{ |
1323
|
|
|
return array( |
1324
|
|
|
array(77, 2, 'new_solutions', 'new_solutions'), |
1325
|
|
|
array(75, 69, 'stylesheets', 'products/stylesheets'), |
1326
|
|
|
); |
1327
|
|
|
} |
1328
|
|
|
|
1329
|
|
|
/** |
1330
|
|
|
* Test for the updatePathIdentificationString() method. |
1331
|
|
|
* |
1332
|
|
|
* @covers \eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway\DoctrineDatabase::updatePathIdentificationString |
1333
|
|
|
* @dataProvider providerForTestUpdatePathIdentificationString |
1334
|
|
|
*/ |
1335
|
|
|
public function testUpdatePathIdentificationString($locationId, $parentLocationId, $text, $expected) |
1336
|
|
|
{ |
1337
|
|
|
$this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php'); |
1338
|
|
|
|
1339
|
|
|
$gateway = $this->getLocationGateway(); |
1340
|
|
|
$gateway->updatePathIdentificationString($locationId, $parentLocationId, $text); |
1341
|
|
|
|
1342
|
|
|
$query = $this->handler->createSelectQuery(); |
1343
|
|
|
$this->assertQueryResult( |
1344
|
|
|
array(array($expected)), |
1345
|
|
|
$query->select( |
1346
|
|
|
'path_identification_string' |
1347
|
|
|
)->from( |
1348
|
|
|
'ezcontentobject_tree' |
1349
|
|
|
)->where( |
1350
|
|
|
$query->expr->eq('node_id', $locationId) |
1351
|
|
|
) |
1352
|
|
|
); |
1353
|
|
|
} |
1354
|
|
|
} |
1355
|
|
|
|