Completed
Push — update_vendor ( 4e04e9...325785 )
by amaury
03:22
created

NodeRepositoryTest::testFindByHistoryAndSiteId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 7
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 Phake;
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 testFindOneCurrentlyPublished($language, $version, $siteId)
44
    {
45
        $node = $this->repository->findOneCurrentlyPublished(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 $language
63
     * @param $version
64
     * @param $siteId
65
     *
66
     * @dataProvider provideLanguageLastVersionAndSiteId
67
     */
68
    public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithPublishedDataSet($language, $version, $siteId)
69
    {
70
        $node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
71
72
        $this->assertSameNode($language, $version, $siteId, $node);
73
    }
74
75
    /**
76
     * @param string $language
77
     * @param int    $version
78
     * @param string $siteId
79
     * @param int    $versionExpected
80
     *
81
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
82
     */
83
    public function testFindOneByNodeIdAndLanguageAndVersionAndSiteIdWithNotPublishedDataSet($language, $version = null, $siteId, $versionExpected)
84
    {
85
        $node = $this->repository->findVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
86
87
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
88
        $this->assertSame('draft', $node->getStatus()->getName());
89
    }
90
91
    /**
92
     * @return array
93
     */
94 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...
95
    {
96
        return array(
97
            array('fr', 2, '2', 2),
98
            array('fr', null, '2', 2),
99
        );
100
    }
101
102
    /**
103
     * @param string $language
104
     * @param int    $version
105
     * @param string $siteId
106
     * @param int    $versionExpected
107
     *
108
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
109
     */
110
    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...
111
    {
112
        $node = $this->repository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId);
113
114
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
115
    }
116
117
    /**
118
     * @param int    $countVersions
119
     * @param string $language
120
     * @param string $siteId
121
     *
122
     * @dataProvider provideLanguageAndVersionListAndSiteId
123
     */
124
    public function testFindByNodeAndLanguageAndSite($countVersions, $language, $siteId)
125
    {
126
        $nodes = $this->repository->findByNodeAndLanguageAndSite(NodeInterface::ROOT_NODE_ID, $language, $siteId);
127
128
        $this->assertCount($countVersions, $nodes);
129
        foreach ($nodes as $node) {
130
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
131
        }
132
        if (count($nodes) > 1) {
133
            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...
134
                $this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion());
135
            }
136
        }
137
    }
138
139
    /**
140
     * @return array
141
     */
142 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...
143
    {
144
        return array(
145
            array(1, 'en', '2'),
146
            array(2, 'fr', '2'),
147
        );
148
    }
149
150
    /**
151
     * @param string $nodeId
152
     * @param string $siteId
153
     * @param int    $count
154
     *
155
     * @dataProvider provideNodeSiteAndCount
156
     */
157
    public function testFindByNodeAndSite($nodeId, $siteId, $count)
158
    {
159
        $this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId));
160
    }
161
162
    /**
163
     * @return array
164
     */
165
    public function provideNodeSiteAndCount()
166
    {
167
        return array(
168
            array(NodeInterface::ROOT_NODE_ID, '2', 3),
169
            array(NodeInterface::TRANSVERSE_NODE_ID, '2', 3),
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(NodeInterface::TRANSVERSE_NODE_ID, '2', 0),
197
            array('fixture_page_what_is_orchestra', '2', 0),
198
        );
199
    }
200
201
    /**
202
     * @param string $path
203
     * @param string $siteId
204
     * @param int    $count
205
     *
206
     * @dataProvider providePathSiteIdAndCount
207
     */
208
    public function testFindByIncludedPathAndSiteId($path, $siteId, $count)
209
    {
210
        $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId);
211
212
        $this->assertGreaterThanOrEqual($count, count($nodes));
213
    }
214
215
    /**
216
     * @return array
217
     */
218
    public function providePathSiteIdAndCount()
219
    {
220
        return array(
221
            array('root', '2', 5),
222
            array('root/fixture_page_community', '2', 0),
223
            array('transverse', '2', 0),
224
        );
225
    }
226
227
    /**
228
     * @param string $siteId
229
     * @param int    $version
230
     *
231
     * @dataProvider provideSiteIdAndLastVersion
232
     */
233
    public function testFindLastVersionByType($siteId, $version)
234
    {
235
        $nodes = $this->repository->findLastVersionByType($siteId);
236
237
        $this->assertSameNode('fr', $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
238
    }
239
240
    /**
241
     * @return array
242
     */
243
    public function provideSiteIdAndLastVersion()
244
    {
245
        return array(
246
            array('2', 2),
247
        );
248
    }
249
250
    /**
251
     * @param string        $language
252
     * @param int           $version
253
     * @param string        $siteId
254
     * @param NodeInterface $node
255
     * @param string        $nodeId
256
     */
257
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
258
    {
259
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
260
        $this->assertSame($nodeId, $node->getNodeId());
261
        $this->assertSame($language, $node->getLanguage());
262
        $this->assertSame($version, $node->getVersion());
263
        $this->assertSame($siteId, $node->getSiteId());
264
        $this->assertSame(false, $node->isDeleted());
265
    }
266
267
    /**
268
     * @param string      $siteId
269
     * @param int         $nodeNumber
270
     * @param int         $version
271
     * @param string      $language
272
     * @param string|null $nodeId
273
     *
274
     * @dataProvider provideForGetFooter()
275
     */
276 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...
277
    {
278
        $nodes = $this->repository->getFooterTree($language, $siteId);
279
        $this->assertCount($nodeNumber, $nodes);
280
        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...
281
            $this->assertSameNode($language, $version, $siteId, $nodes[$nodeId], $nodeId);
282
            $this->assertSame('published', $nodes[$nodeId]->getStatus()->getName());
283
        }
284
    }
285
286
    /**
287
     * @return array
288
     */
289
    public function provideForGetFooter()
290
    {
291
        return array(
292
            array('2', 1, 1, 'fr', 'fixture_page_legal_mentions'),
293
            array('2', 1, 1, 'en'),
294
            array('2', 1, 1),
295
        );
296
    }
297
298
    /**
299
     * @param string      $siteId
300
     * @param int         $nodeNumber
301
     * @param int         $version
302
     * @param string      $language
303
     *
304
     * @dataProvider provideForGetMenu()
305
     */
306
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
307
    {
308
        $nodes = $this->repository->getMenuTree($language, $siteId);
309
310
        $this->assertCount($nodeNumber, $nodes);
311
        $this->assertSameNode($language, $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
312
        $this->assertSame('published', $nodes[NodeInterface::ROOT_NODE_ID]->getStatus()->getName());
313
    }
314
315
    /**
316
     * @return array
317
     */
318 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...
319
    {
320
        return array(
321
            array('2', 4, 1, 'fr'),
322
            array('2', 4, 1, 'en'),
323
        );
324
    }
325
326
    /**
327
     * @param string $nodeId
328
     * @param int    $nbLevel
329
     * @param int    $nodeNumber
330
     * @param int    $version
331
     * @param string $siteId
332
     * @param string $local
333
     *
334
     * @dataProvider provideForGetSubMenu
335
     */
336 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...
337
    {
338
        $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId);
339
340
        $this->assertCount($nodeNumber, $nodes);
341
        if ($nodeNumber > 0) {
342
            $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId);
343
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
344
        }
345
    }
346
347
    /**
348
     * @return array
349
     */
350
    public function provideForGetSubMenu()
351
    {
352
        return array(
353
            array(NodeInterface::ROOT_NODE_ID, 1, 8, 1, '2', 'fr'),
354
            array(NodeInterface::ROOT_NODE_ID, 2, 8, 1, '2', 'fr'),
355
            array(NodeInterface::ROOT_NODE_ID, 0, 8, 1, '2', 'fr'),
356
            array(NodeInterface::ROOT_NODE_ID, 0, 7, 1, '2', 'en'),
357
            array('fixture_page_community', 1, 1, 1, '2', 'fr'),
358
            array('fixture_page_community', 1, 1, 1, '2', 'en'),
359
            array('page_unexistant', 1, 0, 1, '2', 'fr'),
360
        );
361
    }
362
363
    /**
364
     * @param string $language
365
     * @param string $siteId
366
     * @param int    $count
367
     *
368
     * @dataProvider provideLanguageSiteIdAndCount
369
     */
370
    public function testFindCurrentlyPublishedVersion($language, $siteId, $count)
371
    {
372
        $nodes = $this->repository->findCurrentlyPublishedVersion($language, $siteId);
373
374
        $this->assertCount($count, $nodes);
375
        foreach ($nodes as $node) {
376
            $this->assertSame($language, $node->getLanguage());
377
        }
378
    }
379
380
    /**
381
     * @return array
382
     */
383 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...
384
    {
385
        return array(
386
            array('en', '2', 6),
387
            array('fr', '2', 6),
388
        );
389
    }
390
391
    /**
392
     * @param string       $author
393
     * @param string       $siteId
394
     * @param boolean|null $published
395
     * @param int          $limit
396
     * @param array|null   $sort
397
     * @param int          $count
398
     *
399
     * @dataProvider provideFindByAuthorAndSiteId
400
     */
401
    public function testFindByAuthorAndSiteId($author, $siteId, $published, $limit, $sort, $count)
402
    {
403
        $this->assertCount(
404
            $count,
405
            $this->repository->findByAuthorAndSiteId($author, $siteId, $published, $limit, $sort)
0 ignored issues
show
Deprecated Code introduced by
The method OpenOrchestra\ModelBundl...findByAuthorAndSiteId() has been deprecated with message: will be removed in 2.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
406
        );
407
    }
408
409
    /**
410
     * @return array
411
     */
412
    public function provideFindByAuthorAndSiteId()
413
    {
414
        return array(
415
            array('fake_admin', '2', null, 10, array('updatedAt' => -1), 3),
416
            array('fake_admin', '2', false, 10, null, 1),
417
            array('fake_admin', '2', true, 10, null, 2),
418
            array('fake_admin', '2', true, 2, null, 2),
419
            array('fake_contributor', '2', false, 10, null, 0),
420
            array('fake_contributor', '2', null, 10, null, 0),
421
            array('fake_admin', '3', true, 10, null, 1),
422
        );
423
    }
424
425
    /**
426
     * @param string       $user
427
     * @param string       $siteId
428
     * @param array        $eventTypes
429
     * @param boolean|null $published
430
     * @param int          $limit
431
     * @param array|null   $sort
432
     * @param int          $count
433
     *
434
     * @dataProvider provideFindByHistoryAndSiteId
435
     */
436 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...
437
    {
438
        $user = $this->userRepository->findOneByUsername($user);
439
440
        $this->assertCount(
441
            $count,
442
            $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort)
443
        );
444
    }
445
446
    /**
447
     * @return array
448
     */
449
    public function provideFindByHistoryAndSiteId()
450
    {
451
        return array(
452
            array('admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 1),
453
            array('admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0),
454
            array('admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 1),
455
            array('admin', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), true, 10, null, 2),
456
        );
457
    }
458
459
    /**
460
     * @param string $nodeId
461
     * @param string $language
462
     * @param int    $count
463
     *
464
     * @dataProvider provideFindPublishedSortedVersionData
465
     */
466
    public function testFindPublishedSortedByVersion($nodeId, $language, $count)
467
    {
468
        $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2'));
469
    }
470
471
    /**
472
     * @return array
473
     */
474
    public function provideFindPublishedSortedVersionData()
475
    {
476
        return array(
477
            array(NodeInterface::ROOT_NODE_ID, 'fr', 1),
478
            array(NodeInterface::ROOT_NODE_ID, 'en', 1),
479
            array('fixture_page_contact', 'en', 1),
480
        );
481
    }
482
483
    /**
484
     * @param string $language
485
     * @apram int    $expectedCount
486
     *
487
     * @dataProvider provideLanguage
488
     */
489
    public function testFindSubTreeByPath($language, $expectedCount)
490
    {
491
        $nodes = $this->repository->findSubTreeByPath('root', '2', $language);
492
493
        $this->assertCount($expectedCount, $nodes);
494
    }
495
496
    /**
497
     * @return array
498
     */
499
    public function provideLanguage()
500
    {
501
        return array(
502
            array('en', 6),
503
            array('fr', 7),
504
        );
505
    }
506
507
    /**
508
     * @param string $parentId
509
     * @param string $routePattern
510
     * @param string $nodeId
511
     *
512
     * @dataProvider provideParentRouteAndNodeId
513
     */
514
    public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId)
515
    {
516
        $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2'));
517
    }
518
519
    /**
520
     * @return array
521
     */
522
    public function provideParentRouteAndNodeId()
523
    {
524
        return array(
525
            array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'),
526
            array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'),
527
        );
528
    }
529
530
    /**
531
     * @param string $parentId
532
     * @param int    $order
533
     * @param string $nodeId
534
     * @param bool   $expectedValue
535
     * @param string $siteId
536
     *
537
     * @dataProvider provideParentAndOrder
538
     */
539
    public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2')
540
    {
541
        $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId));
542
    }
543
544
    /**
545
     * @return array
546
     */
547
    public function provideParentAndOrder()
548
    {
549
        return array(
550
            array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true),
551
            array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false),
552
            array('fixture_page_legal_mentions', 0, 'fakeID', false),
553
            array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'),
554
            array(NodeInterface::TRANSVERSE_NODE_ID, 1, '-', false,),
555
        );
556
    }
557
558
    /**
559
     * @param string $type
560
     * @param int    $count
561
     *
562
     * @dataProvider provideNodeTypeAndCount
563
     */
564
    public function testFindAllNodesOfTypeInLastPublishedVersionForSite($type, $count)
565
    {
566
        $this->assertCount($count, $this->repository->findAllNodesOfTypeInLastPublishedVersionForSite($type, '2'));
567
    }
568
569
    /**
570
     * @return array
571
     */
572
    public function provideNodeTypeAndCount()
573
    {
574
        return array(
575
            array(NodeInterface::TYPE_DEFAULT, 15),
576
            array(NodeInterface::TYPE_ERROR, 6),
577
            array(NodeInterface::TYPE_TRANSVERSE, 0),
578
        );
579
    }
580
581
    /**
582
     * Test has statused element
583
     */
584 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...
585
    {
586
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
587
        $status = $statusRepository->findOneByInitial();
588
589
        $this->assertTrue($this->repository->hasStatusedElement($status));
590
    }
591
592
    /**
593
     * Test find by site and defaultTheme
594
     */
595
    public function testFindBySiteIdAndDefaultTheme()
596
    {
597
        $this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false));
598
        $this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true));
599
    }
600
601
    /**
602
     * @param string $nodeId
603
     * @param string $language
604
     *
605
     * @dataProvider provideNodeIdAndLanguageForPublishedFlag
606
     */
607
    public function testfindAllCurrentlyPublishedByElementId($nodeId, $language)
608
    {
609
        $node = Phake::mock(NodeInterface::CLASS);
610
        Phake::when($node)->getNodeId()->thenReturn($nodeId);
611
        Phake::when($node)->getLanguage()->thenReturn($language);
612
        Phake::when($node)->getSiteId()->thenReturn('2');
613
614
        $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...
615
    }
616
617
    /**
618
     * @return array
619
     */
620
    public function provideNodeIdAndLanguageForPublishedFlag()
621
    {
622
        return array(
623
            'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'),
624
            'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'),
625
            'community in fr' => array('fixture_page_community', 'fr'),
626
            'community in en' => array('fixture_page_community', 'en'),
627
        );
628
    }
629
630
    /**
631
     * @param string  $siteId
632
     * @param integer $expectedCount
633
     *
634
     * @dataProvider provideFindLastVersionByTypeCurrentlyPublished
635
     */
636
    public function testFindLastVersionByTypeCurrentlyPublished($siteId, $expectedCount)
637
    {
638
        $this->assertCount($expectedCount, $this->repository->findLastVersionByTypeCurrentlyPublished($siteId));
639
    }
640
641
    /**
642
     * @return array
643
     */
644
    public function provideFindLastVersionByTypeCurrentlyPublished()
645
    {
646
        return array(
647
            array("1", 0),
648
            array("2", 16),
649
        );
650
    }
651
652
    /**
653
     * @param string  $path
654
     * @param string  $siteId
655
     * @param integer $expectedCount
656
     *
657
     * @dataProvider provideFindByPathCurrentlyPublished
658
     */
659
    public function testFindByPathCurrentlyPublished($path, $siteId, $expectedCount)
660
    {
661
        $this->assertCount($expectedCount, $this->repository->findByPathCurrentlyPublished($path, $siteId));
0 ignored issues
show
Deprecated Code introduced by
The method OpenOrchestra\ModelBundl...athCurrentlyPublished() has been deprecated with message: will be removed in 2.0, use findByPathCurrentlyPublishedAndLanguage

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
662
    }
663
664
    /**
665
     * @return array
666
     */
667 View Code Duplication
    public function provideFindByPathCurrentlyPublished()
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...
668
    {
669
        return array(
670
            array("root", "2", 8),
671
            array("transverse", "2", 0),
672
        );
673
    }
674
675
    /**
676
     * @param string  $path
677
     * @param string  $siteId
678
     * @param string  $language
679
     * @param integer $expectedCount
680
     *
681
     * @dataProvider provideFindByPathCurrentlyPublishedAndLanguage
682
     */
683
    public function testFindByPathCurrentlyPublishedAndLanguage($path, $siteId, $language, $expectedCount)
684
    {
685
        $this->assertCount($expectedCount, $this->repository->findByPathCurrentlyPublishedAndLanguage($path, $siteId, $language));
686
    }
687
688
    /**
689
     * @return array
690
     */
691 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...
692
    {
693
        return array(
694
            array("root", "2", "en", 8),
695
            array("transverse", "2", "en", 0),
696
        );
697
    }
698
699
    /**
700
     * @param string  $path
701
     * @param string  $siteId
702
     * @param string  $language
703
     * @param integer $expectedCount
704
     *
705
     * @dataProvider provideFindByIncludedPathSiteIdAndLanguage
706
     */
707
    public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount)
708
    {
709
        $this->assertCount($expectedCount, $this->repository->findByIncludedPathSiteIdAndLanguage($path, $siteId, $language));
710
    }
711
712
    /**
713
     * @return array
714
     */
715 View Code Duplication
    public function provideFindByIncludedPathSiteIdAndLanguage()
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...
716
    {
717
        return array(
718
            array("root", "2", "en", 8),
719
            array("transverse", "2", "en", 1),
720
        );
721
    }
722
723
    /**
724
     * @param string  $theme
725
     * @param integer $expectedCount
726
     *
727
     * @dataProvider provideTheme
728
     */
729
    public function testFindByTheme($theme, $expectedCount)
730
    {
731
        $this->assertCount($expectedCount, $this->repository->FindByTheme($theme));
732
    }
733
734
    /**
735
     * @return array
736
     */
737
    public function provideTheme()
738
    {
739
        return array(
740
            array("fakeTheme", 0),
741
            array("themePresentation", 29),
742
        );
743
    }
744
}
745