Completed
Push — ezp-29724 ( 1025e5...495423 )
by
unknown
30:13 queued 07:05
created

DoctrineDatabaseTest   B

Complexity

Total Complexity 50

Size/Duplication

Total Lines 1331
Duplicated Lines 41.62 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 0
Metric Value
dl 554
loc 1331
rs 7.2
c 0
b 0
f 0
wmc 50
lcom 1
cbo 8

46 Methods

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