Completed
Push — update_functional_test_node ( 9f12c4...9b7b1a )
by amaury
05:55
created

provideNodeLanguageLastVersionAndSiteId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\ModelInterface\Model\NodeInterface;
7
use OpenOrchestra\ModelBundle\Repository\NodeRepository;
8
use OpenOrchestra\ModelInterface\NodeEvents;
9
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
10
11
/**
12
 * Class NodeRepositoryTest
13
 *
14
 * @group integrationTest
15
 */
16
class NodeRepositoryTest extends AbstractKernelTestCase
17
{
18
    /**
19
     * @var NodeRepository
20
     */
21
    protected $repository;
22
    protected $userRepository;
23
24
    /**
25
     * Set up test
26
     */
27 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
    {
29
        parent::setUp();
30
31
        static::bootKernel();
32
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.node');
33
        $this->userRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user');
34
    }
35
36
    /**
37
     * @param string $language
38
     * @param int    $version
39
     * @param string $siteId
40
     *
41
     * @dataProvider provideLanguageLastVersionAndSiteId
42
     */
43
    public function testFindOnePublished($language, $version, $siteId)
44
    {
45
        $node = $this->repository->findOnePublished(NodeInterface::ROOT_NODE_ID, $language, $siteId);
46
47
        $this->assertSameNode($language, $version, $siteId, $node);
48
    }
49
50
    /**
51
     * @return array
52
     */
53 View Code Duplication
    public function provideLanguageLastVersionAndSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
54
    {
55
        return array(
56
            array('en', '1', '2'),
57
            array('fr', '1', '2'),
58
        );
59
    }
60
61
    /**
62
     * @param string $language
63
     * @param int    $version
64
     * @param string $siteId
65
     *
66
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
67
     */
68
    public function testFindVersionNotDeleted($language, $version, $siteId)
69
    {
70
        $node = $this->repository->findVersionNotDeleted(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
71
72
        $this->assertSame($node->getNodeId(), NodeInterface::ROOT_NODE_ID);
73
        $this->assertSame($node->getVersion(), $version);
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function provideLanguageLastVersionAndSiteIdNotPublished()
80
    {
81
        return array(
82
            array('fr', '2', '2', 3),
83
            array('fr', '1', '2', 3),
84
        );
85
    }
86
87
    /**
88
     * @param string $nodeId
89
     * @param string $language
90
     * @param string $siteId
91
     * @param int    $versionExpected
92
     *
93
     * @dataProvider provideNodeLanguageLastVersionAndSiteId
94
     */
95
    public function testFindInLastVersion($nodeId, $language, $siteId, $versionExpected)
96
    {
97
        $node = $this->repository->findInLastVersion($nodeId, $language, $siteId);
98
99
        $this->assertSameNode($language, $versionExpected, $siteId, $node, $nodeId);
100
    }
101
102
    /**
103
     * @return array
104
     */
105
    public function provideNodeLanguageLastVersionAndSiteId()
106
    {
107
        return array(
108
            array('fixture_page_community', 'fr', '2', '1'),
109
            array('fixture_page_news', 'fr', '2', '1'),
110
        );
111
    }
112
113
    /**
114
     * @param int    $countVersions
115
     * @param string $language
116
     * @param string $siteId
117
     *
118
     * @dataProvider provideLanguageAndVersionListAndSiteId
119
     */
120
    public function testFindNotDeletedSortByUpdatedAt($countVersions, $language, $siteId)
121
    {
122
        $nodes = $this->repository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $siteId);
123
124
        $this->assertCount($countVersions, $nodes);
125
        foreach ($nodes as $node) {
126
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
127
        }
128
        if (count($nodes) > 1) {
129
            for ($i = 1; $i < count($nodes); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
130
                $this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion());
131
            }
132
        }
133
    }
134
135
    /**
136
     * @param int    $countVersions
137
     * @param string $language
138
     * @param string $siteId
139
     *
140
     * @dataProvider provideLanguageAndVersionListAndSiteId
141
     */
142
    public function testCountNotDeletedVersions($countVersions, $language, $siteId)
143
    {
144
        $countNodes = $this->repository->countNotDeletedVersions(NodeInterface::ROOT_NODE_ID, $language, $siteId);
145
146
        $this->assertSame($countVersions, $countNodes);
147
    }
148
149
    /**
150
     * @return array
151
     */
152 View Code Duplication
    public function provideLanguageAndVersionListAndSiteId()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
153
    {
154
        return array(
155
            array(1, 'en', '2'),
156
            array(3, 'fr', '2'),
157
        );
158
    }
159
160
    /**
161
     * @param string $nodeId
162
     * @param string $siteId
163
     * @param int    $count
164
     *
165
     * @dataProvider provideNodeSiteAndCount
166
     */
167
    public function testFindByNodeAndSite($nodeId, $siteId, $count)
168
    {
169
        $this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId));
170
    }
171
172
    /**
173
     * @return array
174
     */
175
    public function provideNodeSiteAndCount()
176
    {
177
        return array(
178
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
179
            array('fixture_page_what_is_orchestra', '2', 0),
180
        );
181
    }
182
183
    /**
184
     * @param string $parentId
185
     * @param string $siteId
186
     * @param int    $count
187
     *
188
     * @dataProvider provideParentIdSiteIdAndCount
189
     */
190
    public function testFindByParent($parentId, $siteId, $count)
191
    {
192
        $nodes = $this->repository->findByParent($parentId, $siteId);
193
194
        $this->assertGreaterThanOrEqual($count, count($nodes));
195
    }
196
197
    /**
198
     * @return array
199
     */
200
    public function provideParentIdSiteIdAndCount()
201
    {
202
        return array(
203
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
204
            array('fixture_page_community', '2', 0),
205
            array('fixture_page_what_is_orchestra', '2', 0),
206
        );
207
    }
208
209
    /**
210
     * @param string $path
211
     * @param string $siteId
212
     * @param int    $count
213
     *
214
     * @dataProvider providePathSiteIdAndCount
215
     */
216
    public function testFindByIncludedPathAndSiteId($path, $siteId, $count)
217
    {
218
        $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId);
219
220
        $this->assertGreaterThanOrEqual($count, count($nodes));
221
    }
222
223
    /**
224
     * @return array
225
     */
226 View Code Duplication
    public function providePathSiteIdAndCount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
227
    {
228
        return array(
229
            array('root', '2', 5),
230
            array('root/fixture_page_community', '2', 0),
231
            array('transverse', '2', 0),
232
        );
233
    }
234
235
    /**
236
     * Tets find last version by type
237
     */
238
    public function testFindLastVersionByType()
239
    {
240
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
241
        $nodes = $this->repository->findLastVersionByType('2');
242
243
        $this->assertSameNode('fr', $node->getVersion(), '2', $nodes[NodeInterface::ROOT_NODE_ID]);
244
    }
245
246
    /**
247
     * @param string        $language
248
     * @param int           $version
249
     * @param string        $siteId
250
     * @param NodeInterface $node
251
     * @param string        $nodeId
252
     */
253
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
254
    {
255
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
256
        $this->assertSame($nodeId, $node->getNodeId());
257
        $this->assertSame($language, $node->getLanguage());
258
        $this->assertSame($version, $node->getVersion());
259
        $this->assertSame($siteId, $node->getSiteId());
260
        $this->assertSame(false, $node->isDeleted());
261
    }
262
263
    /**
264
     * @param string      $siteId
265
     * @param int         $nodeNumber
266
     * @param int         $version
267
     * @param string      $language
268
     * @param string|null $nodeId
269
     *
270
     * @dataProvider provideForGetFooter()
271
     */
272 View Code Duplication
    public function testGetFooterTree($siteId, $nodeNumber, $version, $language = 'fr', $nodeId = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
273
    {
274
        $nodes = $this->repository->getFooterTree($language, $siteId);
275
276
        $this->assertCount($nodeNumber, $nodes);
277
        if ($nodeId) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $nodeId of type string|null is loosely compared to true; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
278
            $this->assertSameNode($language, $version, $siteId, $nodes[0], $nodeId);
279
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
280
        }
281
    }
282
283
    /**
284
     * @return array
285
     */
286
    public function provideForGetFooter()
287
    {
288
        return array(
289
            array('2', 1, '1', 'fr', 'fixture_page_legal_mentions'),
290
            array('2', 1, '1', 'en'),
291
            array('2', 1, '1'),
292
        );
293
    }
294
295
    /**
296
     * @param string      $siteId
297
     * @param int         $nodeNumber
298
     * @param int         $version
299
     * @param string      $language
300
     *
301
     * @dataProvider provideForGetMenu()
302
     */
303
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
304
    {
305
        $nodes = $this->repository->getMenuTree($language, $siteId);
306
307
        $this->assertCount($nodeNumber, $nodes);
308
        $this->assertSameNode($language, $version, $siteId, $nodes[0]);
309
        $this->assertSame('published', $nodes[0]->getStatus()->getName());
310
    }
311
312
    /**
313
     * @return array
314
     */
315
    public function provideForGetMenu()
316
    {
317
        return array(
318
            array('2', 4, '1', 'fr'),
319
            array('2', 4, '1', 'en'),
320
        );
321
    }
322
323
    /**
324
     * @param string $nodeId
325
     * @param int    $nbLevel
326
     * @param int    $nodeNumber
327
     * @param int    $version
328
     * @param string $siteId
329
     * @param string $local
330
     *
331
     * @dataProvider provideForGetSubMenu
332
     */
333 View Code Duplication
    public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
334
    {
335
        $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId);
336
337
        $this->assertCount($nodeNumber, $nodes);
338
        if ($nodeNumber > 0) {
339
            $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId);
340
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
341
        }
342
    }
343
344
    /**
345
     * @return array
346
     */
347
    public function provideForGetSubMenu()
348
    {
349
        return array(
350
            array(NodeInterface::ROOT_NODE_ID, 1, 6, '1', '2', 'fr'),
351
            array(NodeInterface::ROOT_NODE_ID, 2, 6, '1', '2', 'fr'),
352
            array(NodeInterface::ROOT_NODE_ID, 0, 6, '1', '2', 'fr'),
353
            array(NodeInterface::ROOT_NODE_ID, 0, 5, '1', '2', 'en'),
354
            array('fixture_page_community', 1, 1, '1', '2', 'fr'),
355
            array('fixture_page_community', 1, 1, '1', '2', 'en'),
356
            array('page_unexistant', 1, 0, 1, '2', 'fr'),
357
        );
358
    }
359
360
    /**
361
     * @param string $language
362
     * @param string $siteId
363
     * @param int    $count
364
     *
365
     * @dataProvider provideLanguageSiteIdAndCount
366
     */
367
    public function testFindPublishedByLanguageAndSiteId($language, $siteId, $count)
368
    {
369
        $nodes = $this->repository->findPublishedByLanguageAndSiteId($language, $siteId);
370
371
        $this->assertCount($count, $nodes);
372
        foreach ($nodes as $node) {
373
            $this->assertSame($language, $node->getLanguage());
374
        }
375
    }
376
377
    /**
378
     * @return array
379
     */
380 View Code Duplication
    public function provideLanguageSiteIdAndCount()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
381
    {
382
        return array(
383
            array('en', '2', 5),
384
            array('fr', '2', 6),
385
        );
386
    }
387
388
    /**
389
     * @param string       $user
390
     * @param string       $siteId
391
     * @param array        $eventTypes
392
     * @param boolean|null $published
393
     * @param int          $limit
394
     * @param array|null   $sort
395
     * @param int          $count
396
     *
397
     * @dataProvider provideFindByHistoryAndSiteId
398
     */
399 View Code Duplication
    public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
400
    {
401
        $user = $this->userRepository->findOneByUsername($user);
402
403
        $this->assertCount(
404
            $count,
405
            $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort)
406
        );
407
    }
408
409
    /**
410
     * @return array
411
     */
412
    public function provideFindByHistoryAndSiteId()
413
    {
414
        return array(
415
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 0),
416
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0),
417
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 0),
418
            array('developer', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), false, 10, null, 1),
419
        );
420
    }
421
422
    /**
423
     * @param string $nodeId
424
     * @param string $language
425
     * @param int    $count
426
     *
427
     * @dataProvider provideFindPublishedSortedVersionData
428
     */
429
    public function testFindPublishedSortedByVersion($nodeId, $language, $count)
430
    {
431
        $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2'));
432
    }
433
434
    /**
435
     * @return array
436
     */
437
    public function provideFindPublishedSortedVersionData()
438
    {
439
        return array(
440
            array(NodeInterface::ROOT_NODE_ID, 'fr', 1),
441
            array(NodeInterface::ROOT_NODE_ID, 'en', 1),
442
            array('fixture_page_contact', 'en', 1),
443
        );
444
    }
445
446
    /**
447
     * @param string $language
448
     * @apram int    $expectedCount
449
     *
450
     * @dataProvider provideLanguage
451
     */
452
    public function testFindSubTreeByPath($language, $expectedCount)
453
    {
454
        $nodes = $this->repository->findSubTreeByPath('root', '2', $language);
455
456
        $this->assertCount($expectedCount, $nodes);
457
    }
458
459
    /**
460
     * @return array
461
     */
462
    public function provideLanguage()
463
    {
464
        return array(
465
            array('en', 4),
466
            array('fr', 5),
467
        );
468
    }
469
470
    /**
471
     * @param string $parentId
472
     * @param string $routePattern
473
     * @param string $nodeId
474
     *
475
     * @dataProvider provideParentRouteAndNodeId
476
     */
477
    public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId)
478
    {
479
        $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2'));
480
    }
481
482
    /**
483
     * @return array
484
     */
485
    public function provideParentRouteAndNodeId()
486
    {
487
        return array(
488
            array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'),
489
            array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'),
490
        );
491
    }
492
493
    /**
494
     * @param string $parentId
495
     * @param int    $order
496
     * @param string $nodeId
497
     * @param bool   $expectedValue
498
     * @param string $siteId
499
     *
500
     * @dataProvider provideParentAndOrder
501
     */
502
    public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2')
503
    {
504
        $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId));
505
    }
506
507
    /**
508
     * @return array
509
     */
510
    public function provideParentAndOrder()
511
    {
512
        return array(
513
            array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true),
514
            array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false),
515
            array('fixture_page_legal_mentions', 0, 'fakeID', false),
516
            array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'),
517
        );
518
    }
519
520
    /**
521
     * Test has statused element
522
     */
523 View Code Duplication
    public function testHasStatusedElement()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
524
    {
525
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
526
        $status = $statusRepository->findOneByInitial();
527
528
        $this->assertTrue($this->repository->hasStatusedElement($status));
529
    }
530
531
    /**
532
     * Test find by site and defaultTheme
533
     */
534
    public function testFindBySiteIdAndDefaultTheme()
535
    {
536
        $this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false));
537
        $this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true));
538
    }
539
540
    /**
541
     * @return array
542
     */
543
    public function provideNodeIdAndLanguageForPublishedFlag()
544
    {
545
        return array(
546
            'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'),
547
            'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'),
548
            'community in fr' => array('fixture_page_community', 'fr'),
549
            'community in en' => array('fixture_page_community', 'en'),
550
        );
551
    }
552
553
    /**
554
     * @param string  $siteId
555
     * @param integer $expectedCount
556
     *
557
     * @dataProvider provideFindPublishedByType
558
     */
559
    public function testFindPublishedByType($siteId, $expectedCount)
560
    {
561
        $this->assertCount($expectedCount, $this->repository->findPublishedByType($siteId));
562
    }
563
564
    /**
565
     * @return array
566
     */
567
    public function provideFindPublishedByType()
568
    {
569
        return array(
570
            array("1", 0),
571
            array("2", 16),
572
        );
573
    }
574
575
    /**
576
     * @param string  $path
577
     * @param string  $siteId
578
     * @param string  $language
579
     * @param integer $expectedCount
580
     *
581
     * @dataProvider provideFindPublishedByPathAndLanguage
582
     */
583
    public function testFindPublishedByPathAndLanguage($path, $siteId, $language, $expectedCount)
584
    {
585
        $this->assertCount($expectedCount, $this->repository->findPublishedByPathAndLanguage($path, $siteId, $language));
586
    }
587
588
    /**
589
     * @return array
590
     */
591 View Code Duplication
    public function provideFindPublishedByPathAndLanguage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
592
    {
593
        return array(
594
            array("root", "2", "en", 5),
595
            array("transverse", "2", "en", 0),
596
        );
597
    }
598
599
    /**
600
     * @param string  $path
601
     * @param string  $siteId
602
     * @param string  $language
603
     * @param integer $expectedCount
604
     *
605
     * @dataProvider provideFindByIncludedPathSiteIdAndLanguage
606
     */
607
    public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount)
608
    {
609
        $this->assertCount($expectedCount, $this->repository->findByIncludedPathSiteIdAndLanguage($path, $siteId, $language));
610
    }
611
612
    /**
613
     * @return array
614
     */
615
    public function provideFindByIncludedPathSiteIdAndLanguage()
616
    {
617
        return array(
618
            array("root", "2", "en", 6),
619
        );
620
    }
621
622
    /**
623
     * @param string  $theme
624
     * @param integer $expectedCount
625
     *
626
     * @dataProvider provideTheme
627
     */
628
    public function testFindByTheme($theme, $expectedCount)
629
    {
630
        $this->assertCount($expectedCount, $this->repository->FindByTheme($theme));
631
    }
632
633
    /**
634
     * @return array
635
     */
636
    public function provideTheme()
637
    {
638
        return array(
639
            array("fakeTheme", 0),
640
        );
641
    }
642
643
    /**
644
     * test find tree node
645
     */
646
    public function testFindTreeNode()
647
    {
648
        $tree = $this->repository->findTreeNode('2', 'fr', '-');
649
650
        $this->assertCount(3, $tree);
651
652
        $nodeRootTree = $tree[0];
653
        $nodeRoot = $nodeRootTree['node'];
654
        $this->assertCount(5, $nodeRootTree['child']);
655
        $this->assertSame('root', $nodeRoot['nodeId']);
656
        $childrenRoot = $nodeRootTree['child'];
657
        $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish');
658
        foreach ($childrenRoot as $index => $child) {
659
            $this->assertCount(0, $child['child']);
660
            $this->assertSame($orderNodeId[$index], $child['node']['nodeId']);
661
        }
662
663
        $node404Tree = $tree[1];
664
        $node404 = $node404Tree['node'];
665
        $this->assertCount(0, $node404Tree['child']);
666
        $this->assertSame('errorPage404', $node404['nodeId']);
667
668
        $node503Tree = $tree[2];
669
        $node503 = $node503Tree['node'];
670
        $this->assertCount(0, $node503Tree['child']);
671
        $this->assertSame('errorPage503', $node503['nodeId']);
672
    }
673
674
    /**
675
     * @param string $siteId
676
     * @param string $language
677
     * @param int    $count
678
     *
679
     * @dataProvider provideSiteIdAndLanguage
680
     */
681
    public function testCount($siteId, $language, $count)
682
    {
683
        $this->assertEquals($count, $this->repository->count($siteId, $language));
684
    }
685
686
    /**
687
     * @return array
688
     */
689
    public function provideSiteIdAndLanguage()
690
    {
691
        return array(
692
            array('2', 'fr', 8),
693
            array('2', 'en', 8),
694
            array('2', 'de', 7),
695
            array('3', 'fr', 1),
696
        );
697
    }
698
699
    /**
700
     * @param PaginateFinderConfiguration $configuration
701
     * @param string                      $siteId
702
     * @param string                      $language
703
     * @param int                         $count
704
     *
705
     * @dataProvider provideCountWithFilterPaginateConfiguration
706
     */
707
    public function testCountWithFilter($configuration, $siteId, $language, $count)
708
    {
709
        $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language));
710
    }
711
712
    /**
713
     * @return array
714
     */
715
    public function provideCountWithFilterPaginateConfiguration()
716
    {
717
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
718
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
719
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
720
721
        return array(
722
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
723
            'order' => array($configurationOrder, '2', 'fr', 8),
724
            'filter' => array($configurationFilter, '2', 'fr', 1),
725
        );
726
    }
727
728
    /**
729
     * @param PaginateFinderConfiguration $configuration
730
     * @param string                      $siteId
731
     * @param string                      $language
732
     * @param int                         $count
733
     *
734
     * @dataProvider provideFindWithFilterPaginateConfiguration
735
     */
736
    public function testFindForPaginate($configuration, $siteId, $language, $count)
737
    {
738
        $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language));
739
    }
740
741
    /**
742
     * @return array
743
     */
744
    public function provideFindWithFilterPaginateConfiguration()
745
    {
746
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
747
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array());
748
        $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array());
749
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
750
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
751
752
        return array(
753
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
754
            'limit' => array($configurationLimit, '2', 'fr', 2),
755
            'skip' => array($configurationSkip, '2', 'fr', 6),
756
            'order' => array($configurationOrder, '2', 'fr', 8),
757
            'filter' => array($configurationFilter, '2', 'fr', 1),
758
        );
759
    }
760
761
    /**
762
     * Test update order of brothers
763
     */
764
    public function testUpdateOrderOfBrothers()
765
    {
766
        $dm = static::$kernel->getContainer()->get('object_manager');
767
        $nodeNews = $this->repository->findOneByNodeId('fixture_page_news');
768
        $nodeCommunity = $this->repository->findOneByNodeId('fixture_page_community');
769
        $nodeContact= $this->repository->findOneByNodeId('fixture_page_contact');
770
        $dm->detach($nodeContact);
771
        $dm->detach($nodeCommunity);
772
        $dm->detach($nodeNews);
773
774
        $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId());
775
776
        $nodeNewsAfterUpdate = $this->repository->findOneByNodeId('fixture_page_news');
777
        $nodeCommunityAfterUpdate = $this->repository->findOneByNodeId('fixture_page_community');
778
        $nodeContactAfterUpdate = $this->repository->findOneByNodeId('fixture_page_contact');
779
780
        $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder());
781
        $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder());
782
        $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder());
783
784
    }
785
786
    /**
787
     * Test remove block in area
788
     */
789
    public function testRemoveBlockInArea()
790
    {
791
        $dm = static::$kernel->getContainer()->get('object_manager');
792
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
793
        $block = $node->getArea('main')->getBlocks()[0];
794
        $this->assertCount(2, $node->getArea('main')->getBlocks());
795
796
        $this->repository->removeBlockInArea($block->getId(), 'main', $node->getNodeId(), $node->getSiteId(), $node->getLanguage(), $node->getVersion());
797
798
        $dm->detach($node);
799
        $dm->detach($block);
800
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
801
        $blocks = $node->getArea('main')->getBlocks();
802
        $this->assertCount(1, $blocks);
803
804
        $node->getArea('main')->addBlock($block);
805
        $dm->persist($block);
806
        $dm->flush();
807
    }
808
809
    /**
810
     * @param string $nodeId
811
     * @param string $siteId
812
     * @param string $areaId
813
     * @param int    $count
814
     *
815
     * @dataProvider provideFindByNodeIdAndSiteIdWithBlocksInArea
816
     */
817
    public function testFindByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId, $count)
818
    {
819
        $nodes = $this->repository->findByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId);
820
        $this->assertCount($count, $nodes);
821
    }
822
823
    /**
824
     * @return array
825
     */
826
    public function provideFindByNodeIdAndSiteIdWithBlocksInArea()
827
    {
828
        return array(
829
            array('root', '2', 'main', 3),
830
            array('root', 'fake', 'footer', 0),
831
        );
832
    }
833
834
    /**
835
     * Test remove node version
836
     */
837 View Code Duplication
    public function testRemoveVersion()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
838
    {
839
        $dm = static::$kernel->getContainer()->get('object_manager');
840
        $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', '1');
841
        $storageIds = array($node->geTId());
842
        $dm->detach($node);
843
844
        $this->repository->removeNodeVersions($storageIds);
845
        $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', '1'));
846
847
        $dm->persist($node);
848
        $dm->flush();
849
    }
850
851
    /**
852
     * @param string $language
853
     * @param string $siteId
854
     * @param int    $count
855
     *
856
     * @dataProvider provideLanguageAndSiteIdSpecialPage
857
     */
858
    public function testFindAllPublishedSpecialPage($language, $siteId, $count)
859
    {
860
        $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId);
861
        $this->assertCount($count, $nodes);
862
    }
863
864
    /**
865
     * @param string $language
866
     * @param string $siteId
867
     * @param int    $count
868
     *
869
     * @dataProvider provideLanguageAndSiteIdSpecialPage
870
     */
871
    public function testFindAllSpecialPage($language, $siteId, $count)
872
    {
873
        $nodes = $this->repository->findAllSpecialPage($language, $siteId);
874
        $this->assertCount($count, $nodes);
875
    }
876
877
    /**
878
     * @return array
879
     */
880
    public function provideLanguageAndSiteIdSpecialPage()
881
    {
882
        return array(
883
            array('fr', '2', 1),
884
            array('en', '2', 1),
885
            array('de', '2', 1),
886
            array('fr', '3', 0),
887
            array('en', '3', 0),
888
            array('de', '3', 0),
889
        );
890
    }
891
892
    /**
893
     * @param string $nodeId
894
     * @param string $language
895
     * @param string $siteId
896
     * @param string $name
897
     * @param int    $count
898
     *
899
     * @dataProvider provideCountOtherNodeWithSameSpecialPageName
900
     */
901
    public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count)
902
    {
903
        $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name);
904
        $this->assertSame($count, $nodesCount);
905
    }
906
907
    /**
908
     * @return array
909
     */
910
    public function provideCountOtherNodeWithSameSpecialPageName()
911
    {
912
        return array(
913
            array('root', 'fr', '2', 'DEFAULT', 1),
914
            array('root', 'en', '2', 'DEFAULT', 1),
915
            array('root', 'de', '2', 'DEFAULT', 1),
916
            array('root', 'fr', '2', 'FAKE', 0),
917
            array('root', 'en', '2', 'FAKE', 0),
918
            array('root', 'de', '2', 'FAKE', 0),
919
            array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0),
920
            array('fixture_page_contact', 'en', '2', 'DEFAULT', 0),
921
            array('fixture_page_contact', 'de', '2', 'DEFAULT', 0),
922
        );
923
    }
924
925
    /**
926
     * Test update use Reference
927
     */
928
    public function testUpdateUseReference()
929
    {
930
        $nodeId = 'root';
931
        $siteId = '3';
932
        $entityType = NodeInterface::ENTITY_TYPE;
933
        $referenceNodeId = 'fakeReferenceId';
934
        $this->repository->updateUseReference($referenceNodeId, $nodeId, $siteId, $entityType);
935
        $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId);
936
        foreach ($nodes as $node) {
937
            $this->assertTrue(array_key_exists($referenceNodeId, $node->getUseReferences($entityType)));
938
        }
939
    }
940
}
941