Completed
Push18cfff...7d8314
errored — Build
created

NodeRepositoryTest::provideCountOtherNodeWithSameSpecialPageName()   A

↳ Parent: NodeRepositoryTest

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 14
Code Lines 11

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
eloc 11
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 Noël GILAIN
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 itkg-ngilain
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 View Code Duplication
    public function provideLanguageLastVersionAndSiteIdNotPublished()
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
80
    {
81
        return array(
82
            array('fr', 2, '2', 3),
83
            array('fr', 1, '2', 3),
84
        );
85
    }
86
87
    /**
88
     * @param string $language
89
     * @param int    $version
90
     * @param string $siteId
91
     * @param int    $versionExpected
92
     *
93
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
94
     */
95
    public function testFindInLastVersion($language, $version = null, $siteId, $versionExpected)
0 ignored issues
show
Unused Code introduced by itkg-ngilain
The parameter $version is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
96
    {
97
        $node = $this->repository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId);
98
99
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
100
    }
101
102
    /**
103
     * @param int    $countVersions
104
     * @param string $language
105
     * @param string $siteId
106
     *
107
     * @dataProvider provideLanguageAndVersionListAndSiteId
108
     */
109
    public function testFindNotDeletedSortByUpdatedAt($countVersions, $language, $siteId)
110
    {
111
        $nodes = $this->repository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $siteId);
112
113
        $this->assertCount($countVersions, $nodes);
114
        foreach ($nodes as $node) {
115
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
116
        }
117
        if (count($nodes) > 1) {
118
            for ($i = 1; $i < count($nodes); $i++) {
0 ignored issues
show
Performance Best Practice introduced by itkg-ngilain
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...
119
                $this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion());
120
            }
121
        }
122
    }
123
124
    /**
125
     * @param int    $countVersions
126
     * @param string $language
127
     * @param string $siteId
128
     *
129
     * @dataProvider provideLanguageAndVersionListAndSiteId
130
     */
131
    public function testCountNotDeletedVersions($countVersions, $language, $siteId)
132
    {
133
        $countNodes = $this->repository->countNotDeletedVersions(NodeInterface::ROOT_NODE_ID, $language, $siteId);
134
135
        $this->assertSame($countVersions, $countNodes);
136
    }
137
138
    /**
139
     * @return array
140
     */
141 View Code Duplication
    public function provideLanguageAndVersionListAndSiteId()
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
142
    {
143
        return array(
144
            array(1, 'en', '2'),
145
            array(3, 'fr', '2'),
146
        );
147
    }
148
149
    /**
150
     * @param string $nodeId
151
     * @param string $siteId
152
     * @param int    $count
153
     *
154
     * @dataProvider provideNodeSiteAndCount
155
     */
156
    public function testFindByNodeAndSite($nodeId, $siteId, $count)
157
    {
158
        $this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId));
159
    }
160
161
    /**
162
     * @return array
163
     */
164
    public function provideNodeSiteAndCount()
165
    {
166
        return array(
167
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
168
            array('fixture_page_what_is_orchestra', '2', 0),
169
        );
170
    }
171
172
    /**
173
     * @param string $parentId
174
     * @param string $siteId
175
     * @param int    $count
176
     *
177
     * @dataProvider provideParentIdSiteIdAndCount
178
     */
179
    public function testFindByParent($parentId, $siteId, $count)
180
    {
181
        $nodes = $this->repository->findByParent($parentId, $siteId);
182
183
        $this->assertGreaterThanOrEqual($count, count($nodes));
184
    }
185
186
    /**
187
     * @return array
188
     */
189
    public function provideParentIdSiteIdAndCount()
190
    {
191
        return array(
192
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
193
            array('fixture_page_community', '2', 0),
194
            array('fixture_page_what_is_orchestra', '2', 0),
195
        );
196
    }
197
198
    /**
199
     * @param string $path
200
     * @param string $siteId
201
     * @param int    $count
202
     *
203
     * @dataProvider providePathSiteIdAndCount
204
     */
205
    public function testFindByIncludedPathAndSiteId($path, $siteId, $count)
206
    {
207
        $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId);
208
209
        $this->assertGreaterThanOrEqual($count, count($nodes));
210
    }
211
212
    /**
213
     * @return array
214
     */
215
    public function providePathSiteIdAndCount()
216
    {
217
        return array(
218
            array('root', '2', 5),
219
            array('root/fixture_page_community', '2', 0),
220
            array('transverse', '2', 0),
221
        );
222
    }
223
224
    /**
225
     * @param string $siteId
226
     * @param int    $version
227
     *
228
     * @dataProvider provideSiteIdAndLastVersion
229
     */
230
    public function testFindLastVersionByType($siteId, $version)
231
    {
232
        $nodes = $this->repository->findLastVersionByType($siteId);
233
234
        $this->assertSameNode('fr', $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
235
    }
236
237
    /**
238
     * @return array
239
     */
240
    public function provideSiteIdAndLastVersion()
241
    {
242
        return array(
243
            array('2', 3),
244
        );
245
    }
246
247
    /**
248
     * @param string        $language
249
     * @param int           $version
250
     * @param string        $siteId
251
     * @param NodeInterface $node
252
     * @param string        $nodeId
253
     */
254
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
255
    {
256
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
257
        $this->assertSame($nodeId, $node->getNodeId());
258
        $this->assertSame($language, $node->getLanguage());
259
        $this->assertSame($version, $node->getVersion());
260
        $this->assertSame($siteId, $node->getSiteId());
261
        $this->assertSame(false, $node->isDeleted());
262
    }
263
264
    /**
265
     * @param string      $siteId
266
     * @param int         $nodeNumber
267
     * @param int         $version
268
     * @param string      $language
269
     * @param string|null $nodeId
270
     *
271
     * @dataProvider provideForGetFooter()
272
     */
273 View Code Duplication
    public function testGetFooterTree($siteId, $nodeNumber, $version, $language = 'fr', $nodeId = null)
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
274
    {
275
        $nodes = $this->repository->getFooterTree($language, $siteId);
276
277
        $this->assertCount($nodeNumber, $nodes);
278
        if ($nodeId) {
0 ignored issues
show
Bug Best Practice introduced by itkg-ngilain
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...
279
            $this->assertSameNode($language, $version, $siteId, $nodes[0], $nodeId);
280
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
281
        }
282
    }
283
284
    /**
285
     * @return array
286
     */
287 View Code Duplication
    public function provideForGetFooter()
0 ignored issues
show
Duplication introduced by Noël GILAIN
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...
288
    {
289
        return array(
290
            array('2', 1, 1, 'fr', 'fixture_page_legal_mentions'),
291
            array('2', 1, 1, 'en'),
292
            array('2', 1, 1),
293
        );
294
    }
295
296
    /**
297
     * @param string      $siteId
298
     * @param int         $nodeNumber
299
     * @param int         $version
300
     * @param string      $language
301
     *
302
     * @dataProvider provideForGetMenu()
303
     */
304 View Code Duplication
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
0 ignored issues
show
Duplication introduced by Noël GILAIN
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...
305
    {
306
        $nodes = $this->repository->getMenuTree($language, $siteId);
307
308
        $this->assertCount($nodeNumber, $nodes);
309
        $this->assertSameNode($language, $version, $siteId, $nodes[0]);
310
        $this->assertSame('published', $nodes[0]->getStatus()->getName());
311
    }
312
313
    /**
314
     * @return array
315
     */
316 View Code Duplication
    public function provideForGetMenu()
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
317
    {
318
        return array(
319
            array('2', 4, 1, 'fr'),
320
            array('2', 4, 1, 'en'),
321
        );
322
    }
323
324
    /**
325
     * @param string $nodeId
326
     * @param int    $nbLevel
327
     * @param int    $nodeNumber
328
     * @param int    $version
329
     * @param string $siteId
330
     * @param string $local
331
     *
332
     * @dataProvider provideForGetSubMenu
333
     */
334
    public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local)
335
    {
336
        $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId);
337
338
        $this->assertCount($nodeNumber, $nodes);
339
        if ($nodeNumber > 0) {
340
            $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId);
341
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
342
        }
343
    }
344
345
    /**
346
     * @return array
347
     */
348
    public function provideForGetSubMenu()
349
    {
350
        return array(
351
            array(NodeInterface::ROOT_NODE_ID, 1, 6, 1, '2', 'fr'),
352
            array(NodeInterface::ROOT_NODE_ID, 2, 6, 1, '2', 'fr'),
353
            array(NodeInterface::ROOT_NODE_ID, 0, 6, 1, '2', 'fr'),
354
            array(NodeInterface::ROOT_NODE_ID, 0, 5, 1, '2', 'en'),
355
            array('fixture_page_community', 1, 1, 1, '2', 'fr'),
356
            array('fixture_page_community', 1, 1, 1, '2', 'en'),
357
            array('page_unexistant', 1, 0, 1, '2', 'fr'),
358
        );
359
    }
360
361
    /**
362
     * @param string $language
363
     * @param string $siteId
364
     * @param int    $count
365
     *
366
     * @dataProvider provideLanguageSiteIdAndCount
367
     */
368
    public function testFindPublishedByLanguageAndSiteId($language, $siteId, $count)
369
    {
370
        $nodes = $this->repository->findPublishedByLanguageAndSiteId($language, $siteId);
371
372
        $this->assertCount($count, $nodes);
373
        foreach ($nodes as $node) {
374
            $this->assertSame($language, $node->getLanguage());
375
        }
376
    }
377
378
    /**
379
     * @return array
380
     */
381 View Code Duplication
    public function provideLanguageSiteIdAndCount()
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
382
    {
383
        return array(
384
            array('en', '2', 5),
385
            array('fr', '2', 6),
386
        );
387
    }
388
389
    /**
390
     * @param string       $user
391
     * @param string       $siteId
392
     * @param array        $eventTypes
393
     * @param boolean|null $published
394
     * @param int          $limit
395
     * @param array|null   $sort
396
     * @param int          $count
397
     *
398
     * @dataProvider provideFindByHistoryAndSiteId
399
     */
400 View Code Duplication
    public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count)
0 ignored issues
show
Duplication introduced by Nicolas ANNE
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...
401
    {
402
        $user = $this->userRepository->findOneByUsername($user);
403
404
        $this->assertCount(
405
            $count,
406
            $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort)
407
        );
408
    }
409
410
    /**
411
     * @return array
412
     */
413
    public function provideFindByHistoryAndSiteId()
414
    {
415
        return array(
416
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 0),
417
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0),
418
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 0),
419
            array('developer', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), false, 10, null, 1),
420
        );
421
    }
422
423
    /**
424
     * @param string $nodeId
425
     * @param string $language
426
     * @param int    $count
427
     *
428
     * @dataProvider provideFindPublishedSortedVersionData
429
     */
430
    public function testFindPublishedSortedByVersion($nodeId, $language, $count)
431
    {
432
        $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2'));
433
    }
434
435
    /**
436
     * @return array
437
     */
438
    public function provideFindPublishedSortedVersionData()
439
    {
440
        return array(
441
            array(NodeInterface::ROOT_NODE_ID, 'fr', 1),
442
            array(NodeInterface::ROOT_NODE_ID, 'en', 1),
443
            array('fixture_page_contact', 'en', 1),
444
        );
445
    }
446
447
    /**
448
     * @param string $language
449
     * @apram int    $expectedCount
450
     *
451
     * @dataProvider provideLanguage
452
     */
453
    public function testFindSubTreeByPath($language, $expectedCount)
454
    {
455
        $nodes = $this->repository->findSubTreeByPath('root', '2', $language);
456
457
        $this->assertCount($expectedCount, $nodes);
458
    }
459
460
    /**
461
     * @return array
462
     */
463
    public function provideLanguage()
464
    {
465
        return array(
466
            array('en', 4),
467
            array('fr', 5),
468
        );
469
    }
470
471
    /**
472
     * @param string $parentId
473
     * @param string $routePattern
474
     * @param string $nodeId
475
     *
476
     * @dataProvider provideParentRouteAndNodeId
477
     */
478
    public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId)
479
    {
480
        $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2'));
481
    }
482
483
    /**
484
     * @return array
485
     */
486
    public function provideParentRouteAndNodeId()
487
    {
488
        return array(
489
            array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'),
490
            array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'),
491
        );
492
    }
493
494
    /**
495
     * @param string $parentId
496
     * @param int    $order
497
     * @param string $nodeId
498
     * @param bool   $expectedValue
499
     * @param string $siteId
500
     *
501
     * @dataProvider provideParentAndOrder
502
     */
503
    public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2')
504
    {
505
        $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId));
506
    }
507
508
    /**
509
     * @return array
510
     */
511
    public function provideParentAndOrder()
512
    {
513
        return array(
514
            array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true),
515
            array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false),
516
            array('fixture_page_legal_mentions', 0, 'fakeID', false),
517
            array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'),
518
        );
519
    }
520
521
    /**
522
     * Test has statused element
523
     */
524 View Code Duplication
    public function testHasStatusedElement()
0 ignored issues
show
Duplication introduced by itkg-ngilain
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...
525
    {
526
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
527
        $status = $statusRepository->findOneByInitial();
528
529
        $this->assertTrue($this->repository->hasStatusedElement($status));
530
    }
531
532
    /**
533
     * Test find by site and defaultTheme
534
     */
535
    public function testFindBySiteIdAndDefaultTheme()
536
    {
537
        $this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false));
538
        $this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true));
539
    }
540
541
    /**
542
     * @return array
543
     */
544
    public function provideNodeIdAndLanguageForPublishedFlag()
545
    {
546
        return array(
547
            'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'),
548
            'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'),
549
            'community in fr' => array('fixture_page_community', 'fr'),
550
            'community in en' => array('fixture_page_community', 'en'),
551
        );
552
    }
553
554
    /**
555
     * @param string  $siteId
556
     * @param integer $expectedCount
557
     *
558
     * @dataProvider provideFindPublishedByType
559
     */
560
    public function testFindPublishedByType($siteId, $expectedCount)
561
    {
562
        $this->assertCount($expectedCount, $this->repository->findPublishedByType($siteId));
563
    }
564
565
    /**
566
     * @return array
567
     */
568
    public function provideFindPublishedByType()
569
    {
570
        return array(
571
            array("1", 0),
572
            array("2", 16),
573
        );
574
    }
575
576
    /**
577
     * @param string  $path
578
     * @param string  $siteId
579
     * @param string  $language
580
     * @param integer $expectedCount
581
     *
582
     * @dataProvider provideFindPublishedByPathAndLanguage
583
     */
584
    public function testFindPublishedByPathAndLanguage($path, $siteId, $language, $expectedCount)
585
    {
586
        $this->assertCount($expectedCount, $this->repository->findPublishedByPathAndLanguage($path, $siteId, $language));
587
    }
588
589
    /**
590
     * @return array
591
     */
592 View Code Duplication
    public function provideFindPublishedByPathAndLanguage()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
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...
593
    {
594
        return array(
595
            array("root", "2", "en", 5),
596
            array("transverse", "2", "en", 0),
597
        );
598
    }
599
600
    /**
601
     * @param string  $path
602
     * @param string  $siteId
603
     * @param string  $language
604
     * @param integer $expectedCount
605
     *
606
     * @dataProvider provideFindByIncludedPathSiteIdAndLanguage
607
     */
608
    public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount)
609
    {
610
        $this->assertCount($expectedCount, $this->repository->findByIncludedPathSiteIdAndLanguage($path, $siteId, $language));
611
    }
612
613
    /**
614
     * @return array
615
     */
616
    public function provideFindByIncludedPathSiteIdAndLanguage()
617
    {
618
        return array(
619
            array("root", "2", "en", 6),
620
        );
621
    }
622
623
    /**
624
     * @param string  $theme
625
     * @param integer $expectedCount
626
     *
627
     * @dataProvider provideTheme
628
     */
629
    public function testFindByTheme($theme, $expectedCount)
630
    {
631
        $this->assertCount($expectedCount, $this->repository->FindByTheme($theme));
632
    }
633
634
    /**
635
     * @return array
636
     */
637
    public function provideTheme()
638
    {
639
        return array(
640
            array("fakeTheme", 0),
641
        );
642
    }
643
644
    /**
645
     * test find tree node
646
     */
647
    public function testFindTreeNode()
648
    {
649
        $tree = $this->repository->findTreeNode('2', 'fr', '-');
650
651
        $this->assertCount(3, $tree);
652
653
        $nodeRootTree = $tree[0];
654
        $nodeRoot = $nodeRootTree['node'];
655
        $this->assertCount(5, $nodeRootTree['child']);
656
        $this->assertSame('root', $nodeRoot['nodeId']);
657
        $childrenRoot = $nodeRootTree['child'];
658
        $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish');
659
        foreach ($childrenRoot as $index => $child) {
660
            $this->assertCount(0, $child['child']);
661
            $this->assertSame($orderNodeId[$index], $child['node']['nodeId']);
662
        }
663
664
        $node404Tree = $tree[1];
665
        $node404 = $node404Tree['node'];
666
        $this->assertCount(0, $node404Tree['child']);
667
        $this->assertSame('errorPage404', $node404['nodeId']);
668
669
        $node503Tree = $tree[2];
670
        $node503 = $node503Tree['node'];
671
        $this->assertCount(0, $node503Tree['child']);
672
        $this->assertSame('errorPage503', $node503['nodeId']);
673
    }
674
675
    /**
676
     * @param string $siteId
677
     * @param string $language
678
     * @param int    $count
679
     *
680
     * @dataProvider provideSiteIdAndLanguage
681
     */
682
    public function testCount($siteId, $language, $count)
683
    {
684
        $this->assertEquals($count, $this->repository->count($siteId, $language));
685
    }
686
687
    /**
688
     * @return array
689
     */
690 View Code Duplication
    public function provideSiteIdAndLanguage()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
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...
691
    {
692
        return array(
693
            array('2', 'fr', 8),
694
            array('2', 'en', 8),
695
            array('2', 'de', 7),
696
            array('3', 'fr', 1),
697
        );
698
    }
699
700
    /**
701
     * @param PaginateFinderConfiguration $configuration
702
     * @param string                      $siteId
703
     * @param string                      $language
704
     * @param int                         $count
705
     *
706
     * @dataProvider provideCountWithFilterPaginateConfiguration
707
     */
708
    public function testCountWithFilter($configuration, $siteId, $language, $count)
709
    {
710
        $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language));
711
    }
712
713
    /**
714
     * @return array
715
     */
716
    public function provideCountWithFilterPaginateConfiguration()
717
    {
718
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
719
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
720
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
721
722
        return array(
723
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
724
            'order' => array($configurationOrder, '2', 'fr', 8),
725
            'filter' => array($configurationFilter, '2', 'fr', 1),
726
        );
727
    }
728
729
    /**
730
     * @param PaginateFinderConfiguration $configuration
731
     * @param string                      $siteId
732
     * @param string                      $language
733
     * @param int                         $count
734
     *
735
     * @dataProvider provideFindWithFilterPaginateConfiguration
736
     */
737
    public function testFindForPaginate($configuration, $siteId, $language, $count)
738
    {
739
        $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language));
740
    }
741
742
    /**
743
     * @return array
744
     */
745
    public function provideFindWithFilterPaginateConfiguration()
746
    {
747
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
748
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array());
749
        $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array());
750
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
751
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
752
753
        return array(
754
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
755
            'limit' => array($configurationLimit, '2', 'fr', 2),
756
            'skip' => array($configurationSkip, '2', 'fr', 6),
757
            'order' => array($configurationOrder, '2', 'fr', 8),
758
            'filter' => array($configurationFilter, '2', 'fr', 1),
759
        );
760
    }
761
762
    /**
763
     * Test update order of brothers
764
     */
765
    public function testUpdateOrderOfBrothers()
766
    {
767
        $dm = static::$kernel->getContainer()->get('object_manager');
768
        $nodeNews = $this->repository->findOneByNodeId('fixture_page_news');
769
        $nodeCommunity = $this->repository->findOneByNodeId('fixture_page_community');
770
        $nodeContact= $this->repository->findOneByNodeId('fixture_page_contact');
771
        $dm->detach($nodeContact);
772
        $dm->detach($nodeCommunity);
773
        $dm->detach($nodeNews);
774
775
        $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId());
776
777
        $nodeNewsAfterUpdate = $this->repository->findOneByNodeId('fixture_page_news');
778
        $nodeCommunityAfterUpdate = $this->repository->findOneByNodeId('fixture_page_community');
779
        $nodeContactAfterUpdate = $this->repository->findOneByNodeId('fixture_page_contact');
780
781
        $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder());
782
        $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder());
783
        $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder());
784
785
    }
786
787
    /**
788
     * Test remove block in area
789
     */
790
    public function testRemoveBlockInArea()
791
    {
792
        $dm = static::$kernel->getContainer()->get('object_manager');
793
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
794
        $block = $node->getArea('main')->getBlocks()[0];
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(0, $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', 'header', 3),
830
            array('root', '2', 'footer', 3),
831
            array('root', 'fake', 'footer', 0),
832
            array('fake', '2', 'footer', 0),
833
        );
834
    }
835
836
    /**
837
     * Test remove node version
838
     */
839 View Code Duplication
    public function testRemoveVersion()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
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...
840
    {
841
        $dm = static::$kernel->getContainer()->get('object_manager');
842
        $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', 1);
843
        $storageIds = array($node->geTId());
844
        $dm->detach($node);
845
846
        $this->repository->removeNodeVersions($storageIds);
847
        $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', 1));
848
849
        $dm->persist($node);
850
        $dm->flush();
851
    }
852
853
    /**
854
     * @param string $language
855
     * @param string $siteId
856
     * @param int    $count
857
     *
858
     * @dataProvider provideLanguageAndSiteIdSpecialPage
859
     */
860
    public function testFindAllPublishedSpecialPage($language, $siteId, $count)
861
    {
862
        $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId);
863
        $this->assertCount($count, $nodes);
864
    }
865
866
    /**
867
     * @param string $language
868
     * @param string $siteId
869
     * @param int    $count
870
     *
871
     * @dataProvider provideLanguageAndSiteIdSpecialPage
872
     */
873
    public function testFindAllSpecialPage($language, $siteId, $count)
874
    {
875
        $nodes = $this->repository->findAllSpecialPage($language, $siteId);
876
        $this->assertCount($count, $nodes);
877
    }
878
879
    /**
880
     * @return array
881
     */
882
    public function provideLanguageAndSiteIdSpecialPage()
883
    {
884
        return array(
885
            array('fr', '2', 1),
886
            array('en', '2', 1),
887
            array('de', '2', 1),
888
            array('fr', '3', 0),
889
            array('en', '3', 0),
890
            array('de', '3', 0),
891
        );
892
    }
893
894
    /**
895
     * @param string $nodeId
896
     * @param string $language
897
     * @param string $siteId
898
     * @param string $name
899
     * @param int    $count
900
     *
901
     * @dataProvider provideCountOtherNodeWithSameSpecialPageName
902
     */
903
    public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count)
904
    {
905
        $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name);
906
        $this->assertSame($count, $nodesCount);
907
    }
908
909
    /**
910
     * @return array
911
     */
912
    public function provideCountOtherNodeWithSameSpecialPageName()
913
    {
914
        return array(
915
            array('root', 'fr', '2', 'DEFAULT', 1),
916
            array('root', 'en', '2', 'DEFAULT', 1),
917
            array('root', 'de', '2', 'DEFAULT', 1),
918
            array('root', 'fr', '2', 'FAKE', 0),
919
            array('root', 'en', '2', 'FAKE', 0),
920
            array('root', 'de', '2', 'FAKE', 0),
921
            array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0),
922
            array('fixture_page_contact', 'en', '2', 'DEFAULT', 0),
923
            array('fixture_page_contact', 'de', '2', 'DEFAULT', 0),
924
        );
925
    }
926
927
}
928