Completed
Push — ezp-30147 ( 4b6c34 )
by
unknown
20:39
created

DoctrineDatabaseTest::getUpdateLocationData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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