Completed
Push — ezp-31420-merge-up ( ec14fb...141a64 )
by
unknown
40:13 queued 27:42
created

DoctrineDatabaseTest::testRemoveLocation()   A

Complexity

Conditions 2
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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