Completed
Push — master ( 3ce81e...7f45d1 )
by amaury
07:58 queued 03:27
created

provideFindByNodeIdAndSiteIdWithBlocksInArea()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
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
use Phake;
11
12
/**
13
 * Class NodeRepositoryTest
14
 *
15
 * @group integrationTest
16
 */
17
class NodeRepositoryTest extends AbstractKernelTestCase
18
{
19
    /**
20
     * @var NodeRepository
21
     */
22
    protected $repository;
23
    protected $userRepository;
24
25
    /**
26
     * Set up test
27
     */
28 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...
29
    {
30
        parent::setUp();
31
32
        static::bootKernel();
33
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.node');
34
        $this->userRepository = static::$kernel->getContainer()->get('open_orchestra_user.repository.user');
35
    }
36
37
    /**
38
     * @param string $language
39
     * @param int    $version
40
     * @param string $siteId
41
     *
42
     * @dataProvider provideLanguageLastVersionAndSiteId
43
     */
44
    public function testFindOneCurrentlyPublished($language, $version, $siteId)
45
    {
46
        $node = $this->repository->findOneCurrentlyPublished(NodeInterface::ROOT_NODE_ID, $language, $siteId);
47
48
        $this->assertSameNode($language, $version, $siteId, $node);
49
    }
50
51
    /**
52
     * @return array
53
     */
54 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...
55
    {
56
        return array(
57
            array('en', 1, '2'),
58
            array('fr', 1, '2'),
59
        );
60
    }
61
62
    /**
63
     * @param $language
64
     * @param $version
65
     * @param $siteId
66
     *
67
     * @dataProvider provideLanguageLastVersionAndSiteId
68
     */
69
    public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithPublishedDataSet($language, $version, $siteId)
70
    {
71
        $node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
72
73
        $this->assertSameNode($language, $version, $siteId, $node);
74
    }
75
76
    /**
77
     * @param string $language
78
     * @param int    $version
79
     * @param string $siteId
80
     * @param int    $versionExpected
81
     *
82
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
83
     */
84
    public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithNotPublishedDataSet($language, $version = null, $siteId, $versionExpected)
85
    {
86
        $node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
87
88
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
89
        $this->assertSame('draft', $node->getStatus()->getName());
90
    }
91
92
    /**
93
     * @return array
94
     */
95 View Code Duplication
    public function provideLanguageLastVersionAndSiteIdNotPublished()
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...
96
    {
97
        return array(
98
            array('fr', 2, '2', 2),
99
            array('fr', null, '2', 2),
100
        );
101
    }
102
103
    /**
104
     * @param string $language
105
     * @param int    $version
106
     * @param string $siteId
107
     * @param int    $versionExpected
108
     *
109
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
110
     */
111
    public function testFindInLastVersion($language, $version = null, $siteId, $versionExpected)
0 ignored issues
show
Unused Code introduced by
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...
112
    {
113
        $node = $this->repository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId);
114
115
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
116
    }
117
118
    /**
119
     * @param int    $countVersions
120
     * @param string $language
121
     * @param string $siteId
122
     *
123
     * @dataProvider provideLanguageAndVersionListAndSiteId
124
     */
125
    public function testFindByNodeAndLanguageAndSite($countVersions, $language, $siteId)
126
    {
127
        $nodes = $this->repository->findByNodeAndLanguageAndSite(NodeInterface::ROOT_NODE_ID, $language, $siteId);
128
129
        $this->assertCount($countVersions, $nodes);
130
        foreach ($nodes as $node) {
131
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
132
        }
133
        if (count($nodes) > 1) {
134
            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...
135
                $this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion());
136
            }
137
        }
138
    }
139
140
    /**
141
     * @return array
142
     */
143 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...
144
    {
145
        return array(
146
            array(1, 'en', '2'),
147
            array(2, 'fr', '2'),
148
        );
149
    }
150
151
    /**
152
     * @param string $nodeId
153
     * @param string $siteId
154
     * @param int    $count
155
     *
156
     * @dataProvider provideNodeSiteAndCount
157
     */
158
    public function testFindByNodeAndSite($nodeId, $siteId, $count)
159
    {
160
        $this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId));
161
    }
162
163
    /**
164
     * @return array
165
     */
166
    public function provideNodeSiteAndCount()
167
    {
168
        return array(
169
            array(NodeInterface::ROOT_NODE_ID, '2', 4),
170
            array('fixture_page_what_is_orchestra', '2', 0),
171
        );
172
    }
173
174
    /**
175
     * @param string $parentId
176
     * @param string $siteId
177
     * @param int    $count
178
     *
179
     * @dataProvider provideParentIdSiteIdAndCount
180
     */
181
    public function testFindByParent($parentId, $siteId, $count)
182
    {
183
        $nodes = $this->repository->findByParent($parentId, $siteId);
184
185
        $this->assertGreaterThanOrEqual($count, count($nodes));
186
    }
187
188
    /**
189
     * @return array
190
     */
191
    public function provideParentIdSiteIdAndCount()
192
    {
193
        return array(
194
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
195
            array('fixture_page_community', '2', 0),
196
            array('fixture_page_what_is_orchestra', '2', 0),
197
        );
198
    }
199
200
    /**
201
     * @param string $path
202
     * @param string $siteId
203
     * @param int    $count
204
     *
205
     * @dataProvider providePathSiteIdAndCount
206
     */
207
    public function testFindByIncludedPathAndSiteId($path, $siteId, $count)
208
    {
209
        $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId);
210
211
        $this->assertGreaterThanOrEqual($count, count($nodes));
212
    }
213
214
    /**
215
     * @return array
216
     */
217
    public function providePathSiteIdAndCount()
218
    {
219
        return array(
220
            array('root', '2', 5),
221
            array('root/fixture_page_community', '2', 0),
222
            array('transverse', '2', 0),
223
        );
224
    }
225
226
    /**
227
     * @param string $siteId
228
     * @param int    $version
229
     *
230
     * @dataProvider provideSiteIdAndLastVersion
231
     */
232
    public function testFindLastVersionByType($siteId, $version)
233
    {
234
        $nodes = $this->repository->findLastVersionByType($siteId);
235
236
        $this->assertSameNode('fr', $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
237
    }
238
239
    /**
240
     * @return array
241
     */
242
    public function provideSiteIdAndLastVersion()
243
    {
244
        return array(
245
            array('2', 2),
246
        );
247
    }
248
249
    /**
250
     * @param string        $language
251
     * @param int           $version
252
     * @param string        $siteId
253
     * @param NodeInterface $node
254
     * @param string        $nodeId
255
     */
256
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
257
    {
258
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
259
        $this->assertSame($nodeId, $node->getNodeId());
260
        $this->assertSame($language, $node->getLanguage());
261
        $this->assertSame($version, $node->getVersion());
262
        $this->assertSame($siteId, $node->getSiteId());
263
        $this->assertSame(false, $node->isDeleted());
264
    }
265
266
    /**
267
     * @param string      $siteId
268
     * @param int         $nodeNumber
269
     * @param int         $version
270
     * @param string      $language
271
     * @param string|null $nodeId
272
     *
273
     * @dataProvider provideForGetFooter()
274
     */
275 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...
276
    {
277
        $nodes = $this->repository->getFooterTree($language, $siteId);
278
        $this->assertCount($nodeNumber, $nodes);
279
        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...
280
            $this->assertSameNode($language, $version, $siteId, $nodes[$nodeId], $nodeId);
281
            $this->assertSame('published', $nodes[$nodeId]->getStatus()->getName());
282
        }
283
    }
284
285
    /**
286
     * @return array
287
     */
288 View Code Duplication
    public function provideForGetFooter()
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...
289
    {
290
        return array(
291
            array('2', 1, 1, 'fr', 'fixture_page_legal_mentions'),
292
            array('2', 1, 1, 'en'),
293
            array('2', 1, 1),
294
        );
295
    }
296
297
    /**
298
     * @param string      $siteId
299
     * @param int         $nodeNumber
300
     * @param int         $version
301
     * @param string      $language
302
     *
303
     * @dataProvider provideForGetMenu()
304
     */
305
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
306
    {
307
        $nodes = $this->repository->getMenuTree($language, $siteId);
308
309
        $this->assertCount($nodeNumber, $nodes);
310
        $this->assertSameNode($language, $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
311
        $this->assertSame('published', $nodes[NodeInterface::ROOT_NODE_ID]->getStatus()->getName());
312
    }
313
314
    /**
315
     * @return array
316
     */
317 View Code Duplication
    public function provideForGetMenu()
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...
318
    {
319
        return array(
320
            array('2', 4, 1, 'fr'),
321
            array('2', 4, 1, 'en'),
322
        );
323
    }
324
325
    /**
326
     * @param string $nodeId
327
     * @param int    $nbLevel
328
     * @param int    $nodeNumber
329
     * @param int    $version
330
     * @param string $siteId
331
     * @param string $local
332
     *
333
     * @dataProvider provideForGetSubMenu
334
     */
335 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...
336
    {
337
        $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId);
338
339
        $this->assertCount($nodeNumber, $nodes);
340
        if ($nodeNumber > 0) {
341
            $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId);
342
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
343
        }
344
    }
345
346
    /**
347
     * @return array
348
     */
349
    public function provideForGetSubMenu()
350
    {
351
        return array(
352
            array(NodeInterface::ROOT_NODE_ID, 1, 6, 1, '2', 'fr'),
353
            array(NodeInterface::ROOT_NODE_ID, 2, 6, 1, '2', 'fr'),
354
            array(NodeInterface::ROOT_NODE_ID, 0, 6, 1, '2', 'fr'),
355
            array(NodeInterface::ROOT_NODE_ID, 0, 5, 1, '2', 'en'),
356
            array('fixture_page_community', 1, 1, 1, '2', 'fr'),
357
            array('fixture_page_community', 1, 1, 1, '2', 'en'),
358
            array('page_unexistant', 1, 0, 1, '2', 'fr'),
359
        );
360
    }
361
362
    /**
363
     * @param string $language
364
     * @param string $siteId
365
     * @param int    $count
366
     *
367
     * @dataProvider provideLanguageSiteIdAndCount
368
     */
369
    public function testFindCurrentlyPublishedVersion($language, $siteId, $count)
370
    {
371
        $nodes = $this->repository->findCurrentlyPublishedVersion($language, $siteId);
372
373
        $this->assertCount($count, $nodes);
374
        foreach ($nodes as $node) {
375
            $this->assertSame($language, $node->getLanguage());
376
        }
377
    }
378
379
    /**
380
     * @return array
381
     */
382 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...
383
    {
384
        return array(
385
            array('en', '2', 6),
386
            array('fr', '2', 6),
387
        );
388
    }
389
390
    /**
391
     * @param string       $user
392
     * @param string       $siteId
393
     * @param array        $eventTypes
394
     * @param boolean|null $published
395
     * @param int          $limit
396
     * @param array|null   $sort
397
     * @param int          $count
398
     *
399
     * @dataProvider provideFindByHistoryAndSiteId
400
     */
401 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...
402
    {
403
        $user = $this->userRepository->findOneByUsername($user);
404
405
        $this->assertCount(
406
            $count,
407
            $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort)
408
        );
409
    }
410
411
    /**
412
     * @return array
413
     */
414
    public function provideFindByHistoryAndSiteId()
415
    {
416
        return array(
417
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 0),
418
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0),
419
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 0),
420
            array('developer', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), false, 10, null, 1),
421
        );
422
    }
423
424
    /**
425
     * @param string $nodeId
426
     * @param string $language
427
     * @param int    $count
428
     *
429
     * @dataProvider provideFindPublishedSortedVersionData
430
     */
431
    public function testFindPublishedSortedByVersion($nodeId, $language, $count)
432
    {
433
        $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2'));
434
    }
435
436
    /**
437
     * @return array
438
     */
439
    public function provideFindPublishedSortedVersionData()
440
    {
441
        return array(
442
            array(NodeInterface::ROOT_NODE_ID, 'fr', 1),
443
            array(NodeInterface::ROOT_NODE_ID, 'en', 1),
444
            array('fixture_page_contact', 'en', 1),
445
        );
446
    }
447
448
    /**
449
     * @param string $language
450
     * @apram int    $expectedCount
451
     *
452
     * @dataProvider provideLanguage
453
     */
454
    public function testFindSubTreeByPath($language, $expectedCount)
455
    {
456
        $nodes = $this->repository->findSubTreeByPath('root', '2', $language);
457
458
        $this->assertCount($expectedCount, $nodes);
459
    }
460
461
    /**
462
     * @return array
463
     */
464
    public function provideLanguage()
465
    {
466
        return array(
467
            array('en', 4),
468
            array('fr', 5),
469
        );
470
    }
471
472
    /**
473
     * @param string $parentId
474
     * @param string $routePattern
475
     * @param string $nodeId
476
     *
477
     * @dataProvider provideParentRouteAndNodeId
478
     */
479
    public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId)
480
    {
481
        $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2'));
482
    }
483
484
    /**
485
     * @return array
486
     */
487
    public function provideParentRouteAndNodeId()
488
    {
489
        return array(
490
            array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'),
491
            array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'),
492
        );
493
    }
494
495
    /**
496
     * @param string $parentId
497
     * @param int    $order
498
     * @param string $nodeId
499
     * @param bool   $expectedValue
500
     * @param string $siteId
501
     *
502
     * @dataProvider provideParentAndOrder
503
     */
504
    public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2')
505
    {
506
        $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId));
507
    }
508
509
    /**
510
     * @return array
511
     */
512
    public function provideParentAndOrder()
513
    {
514
        return array(
515
            array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true),
516
            array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false),
517
            array('fixture_page_legal_mentions', 0, 'fakeID', false),
518
            array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'),
519
        );
520
    }
521
522
    /**
523
     * @param string $type
524
     * @param int    $count
525
     *
526
     * @dataProvider provideNodeTypeAndCount
527
     */
528
    public function testFindAllNodesOfTypeInLastPublishedVersionForSite($type, $count)
529
    {
530
        $this->assertCount($count, $this->repository->findAllNodesOfTypeInLastPublishedVersionForSite($type, '2'));
531
    }
532
533
    /**
534
     * @return array
535
     */
536
    public function provideNodeTypeAndCount()
537
    {
538
        return array(
539
            array(NodeInterface::TYPE_DEFAULT, 16),
540
            array(NodeInterface::TYPE_ERROR, 6),
541
        );
542
    }
543
544
    /**
545
     * Test has statused element
546
     */
547
    public function testHasStatusedElement()
548
    {
549
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
550
        $status = $statusRepository->findOneByInitial();
551
552
        $this->assertTrue($this->repository->hasStatusedElement($status));
553
    }
554
555
    /**
556
     * Test find by site and defaultTheme
557
     */
558
    public function testFindBySiteIdAndDefaultTheme()
559
    {
560
        $this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false));
561
        $this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true));
562
    }
563
564
    /**
565
     * @param string $nodeId
566
     * @param string $language
567
     *
568
     * @dataProvider provideNodeIdAndLanguageForPublishedFlag
569
     */
570
    public function testfindAllCurrentlyPublishedByElementId($nodeId, $language)
571
    {
572
        $node = Phake::mock(NodeInterface::CLASS);
573
        Phake::when($node)->getNodeId()->thenReturn($nodeId);
574
        Phake::when($node)->getLanguage()->thenReturn($language);
575
        Phake::when($node)->getSiteId()->thenReturn('2');
576
577
        $this->assertCount(1, $this->repository->findAllCurrentlyPublishedByElementId($node));
0 ignored issues
show
Documentation introduced by
$node is of type object<Phake_IMock>, but the function expects a object<OpenOrchestra\Mod...el\StatusableInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

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