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