Completed
Push — ezp-30147 ( 4b6c34...8feb09 )
by
unknown
21:46
created

DoctrineDatabaseTest   B

Complexity

Total Complexity 50

Size/Duplication

Total Lines 1338
Duplicated Lines 42.6 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 0
Metric Value
dl 570
loc 1338
rs 7.2
c 0
b 0
f 0
wmc 50
lcom 1
cbo 9

46 Methods

Rating   Name   Duplication   Size   Complexity  
A getLocationGateway() 16 16 1
A getLoadLocationValues() 19 19 1
A testLoadLocationByRemoteId() 12 12 1
A testLoadLocation() 0 12 1
A testLoadInvalidLocation() 0 6 1
A testLoadLocationDataByContent() 14 14 1
A testLoadParentLocationDataForDraftContentAll() 14 14 1
A testLoadLocationDataByContentLimitSubtree() 0 10 1
A testMoveSubtreePathUpdate() 36 36 1
A testMoveHiddenDestinationUpdate() 37 37 1
A testMoveHiddenSourceUpdate() 37 37 1
A testMoveHiddenSourceChildUpdate() 0 39 1
A testMoveSubtreeAssignmentUpdate() 0 17 1
A testUpdateSubtreeModificationTime() 0 21 1
A testHideUpdateHidden() 21 21 1
A testHideUnhideUpdateHidden() 22 22 1
A testHideUnhideParentTree() 25 25 1
A testHideUnhidePartialSubtree() 25 25 1
A testSwapLocations() 0 19 1
A testCreateLocation() 0 32 1
A testGetMainNodeId() 0 42 1
A getCreateLocationValues() 18 18 1
A testCreateLocationValues() 0 36 2
A getCreateLocationReturnValues() 0 17 1
A testCreateLocationReturnValues() 0 30 2
A getUpdateLocationData() 0 9 1
A testUpdateLocation() 25 25 1
A getNodeAssignmentValues() 18 18 1
A testCreateLocationNodeAssignmentCreation() 35 35 1
A testCreateLocationNodeAssignmentCreationMainLocation() 34 34 1
A testUpdateLocationsContentVersionNo() 0 39 1
A testDeleteNodeAssignment() 0 20 1
A testDeleteNodeAssignmentWithSecondArgument() 0 33 1
A getConvertNodeAssignmentsLocationValues() 0 21 1
A testConvertNodeAssignments() 0 50 2
A testConvertNodeAssignmentsMainLocation() 41 41 1
A testConvertNodeAssignmentsParentHidden() 41 41 1
A testConvertNodeAssignmentsParentInvisible() 41 41 1
A testConvertNodeAssignmentsUpdateAssignment() 37 37 1
A testSetSectionForSubtree() 0 15 1
B testChangeMainLocation() 0 77 1
A testGetChildren() 0 13 1
A testGetFallbackMainNodeData() 0 22 1
A testRemoveLocation() 0 14 2
A providerForTestUpdatePathIdentificationString() 0 7 1
A testUpdatePathIdentificationString() 0 19 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like DoctrineDatabaseTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use DoctrineDatabaseTest, and based on these observations, apply Extract Interface, too.

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\TestCase;
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 TestCase
21
{
22 View Code Duplication
    protected function getLocationGateway()
23
    {
24
        $dbHandler = $this->getDatabaseHandler();
25
26
        return new DoctrineDatabase(
27
            $dbHandler,
28
            $this
29
                ->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway\\CriteriaConverter')
30
                ->disableOriginalConstructor()
31
                ->getMock(),
32
            $this
33
                ->getMockBuilder('eZ\\Publish\\Core\\Persistence\\Legacy\\Content\\Location\\Gateway\\SortClauseConverter')
34
                ->disableOriginalConstructor()
35
                ->getMock()
36
        );
37
    }
38
39 View Code Duplication
    public static function getLoadLocationValues()
40
    {
41
        return array(
42
            array('node_id', 77),
43
            array('priority', 0),
44
            array('is_hidden', 0),
45
            array('is_invisible', 0),
46
            array('remote_id', 'dbc2f3c8716c12f32c379dbf0b1cb133'),
47
            array('contentobject_id', 75),
48
            array('parent_node_id', 2),
49
            array('path_identification_string', 'solutions'),
50
            array('path_string', '/1/2/77/'),
51
            array('modified_subnode', 1311065017),
52
            array('main_node_id', 77),
53
            array('depth', 2),
54
            array('sort_field', 2),
55
            array('sort_order', 1),
56
        );
57
    }
58
59
    /**
60
     * @dataProvider getLoadLocationValues
61
     */
62 View Code Duplication
    public function testLoadLocationByRemoteId($field, $value)
63
    {
64
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php');
65
        $handler = $this->getLocationGateway();
66
        $data = $handler->getBasicNodeDataByRemoteId('dbc2f3c8716c12f32c379dbf0b1cb133');
67
68
        $this->assertEquals(
69
            $value,
70
            $data[$field],
71
            "Value in property $field not as expected."
72
        );
73
    }
74
75
    /**
76
     * @dataProvider getLoadLocationValues
77
     */
78
    public function testLoadLocation($field, $value)
79
    {
80
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php');
81
        $handler = $this->getLocationGateway();
82
        $data = $handler->getBasicNodeData(77);
83
84
        $this->assertEquals(
85
            $value,
86
            $data[$field],
87
            "Value in property $field not as expected."
88
        );
89
    }
90
91
    /**
92
     * @expectedException \eZ\Publish\API\Repository\Exceptions\NotFoundException
93
     */
94
    public function testLoadInvalidLocation()
95
    {
96
        $this->insertDatabaseFixture(__DIR__ . '/_fixtures/full_example_tree.php');
97
        $handler = $this->getLocationGateway();
98
        $data = $handler->getBasicNodeData(1337);
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

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.

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