Completed
Push — master ( a94b1d...e43892 )
by amaury
10:11 queued 05:56
created

NodeRepositoryTest   C

Complexity

Total Complexity 66

Size/Duplication

Total Lines 837
Duplicated Lines 13.62 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 66
c 4
b 0
f 1
lcom 1
cbo 6
dl 114
loc 837
rs 5

59 Methods

Rating   Name   Duplication   Size   Complexity  
A testFindByParent() 0 6 1
A provideForGetMenu() 7 7 1
A provideForGetSubMenu() 0 12 1
A provideLanguageSiteIdAndCount() 7 7 1
A provideLanguageAndVersionListAndSiteId() 7 7 1
A testFindByNodeAndSite() 0 4 1
A provideNodeSiteAndCount() 0 7 1
A provideParentIdSiteIdAndCount() 0 8 1
A testFindByIncludedPathAndSiteId() 0 6 1
A testFindLastVersionByType() 0 6 1
A provideSiteIdAndLastVersion() 0 6 1
A assertSameNode() 0 9 1
A providePathSiteIdAndCount() 0 8 1
A setUp() 8 8 1
A provideLanguageLastVersionAndSiteId() 7 7 1
A provideForGetFooter() 8 8 1
A testFindByHistoryAndSiteId() 9 9 1
A provideFindByHistoryAndSiteId() 0 9 1
A testFindPublishedSortedByVersion() 0 4 1
A provideFindPublishedSortedVersionData() 0 8 1
A testFindSubTreeByPath() 0 6 1
A provideLanguage() 0 7 1
A testFindByParentAndRoutePattern() 0 4 1
A provideParentRouteAndNodeId() 0 7 1
A testHasOtherNodeWithSameParentAndOrder() 0 4 1
A provideParentAndOrder() 0 9 1
A testFindOnePublished() 0 6 1
A testFindVersionNotDeleted() 0 7 1
A provideLanguageLastVersionAndSiteIdNotPublished() 7 7 1
A testFindInLastVersion() 0 6 1
A testFindNotDeletedSortByUpdatedAt() 0 14 4
A testCountNotDeletedVersions() 0 6 1
A testGetFooterTree() 10 10 2
A testFindPublishedByLanguageAndSiteId() 0 9 2
A testHasStatusedElement() 7 7 1
A testFindBySiteIdAndDefaultTheme() 0 5 1
A provideNodeIdAndLanguageForPublishedFlag() 0 9 1
A testFindPublishedByType() 0 4 1
A provideFindPublishedByType() 0 7 1
A testFindPublishedByPathAndLanguage() 0 4 1
A provideFindPublishedByPathAndLanguage() 7 7 1
A testFindByIncludedPathSiteIdAndLanguage() 0 4 1
A provideFindByIncludedPathSiteIdAndLanguage() 0 6 1
A testFindByTheme() 0 4 1
A provideTheme() 0 6 1
B testFindTreeNode() 0 27 2
A testCount() 0 4 1
A provideSiteIdAndLanguage() 9 9 1
A testCountWithFilter() 0 4 1
A provideCountWithFilterPaginateConfiguration() 0 12 1
A testFindForPaginate() 0 4 1
A provideFindWithFilterPaginateConfiguration() 0 16 1
A testUpdateOrderOfBrothers() 0 21 1
A testRemoveBlockInArea() 0 18 1
A testFindByNodeIdAndSiteIdWithBlocksInArea() 0 5 1
A provideFindByNodeIdAndSiteIdWithBlocksInArea() 0 9 1
A testRemoveVersion() 13 13 1
A testGetMenuTree() 8 8 1
A testGetSubMenu() 0 10 2

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like NodeRepositoryTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use NodeRepositoryTest, and based on these observations, apply Extract Interface, too.

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 testFindOnePublished($language, $version, $siteId)
45
    {
46
        $node = $this->repository->findOnePublished(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 string $language
64
     * @param int    $version
65
     * @param string $siteId
66
     *
67
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
68
     */
69
    public function testFindVersionNotDeleted($language, $version, $siteId)
70
    {
71
        $node = $this->repository->findVersionNotDeleted(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
72
73
        $this->assertSame($node->getNodeId(), NodeInterface::ROOT_NODE_ID);
74
        $this->assertSame($node->getVersion(), $version);
75
    }
76
77
    /**
78
     * @return array
79
     */
80 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...
81
    {
82
        return array(
83
            array('fr', 2, '2', 3),
84
            array('fr', 1, '2', 3),
85
        );
86
    }
87
88
    /**
89
     * @param string $language
90
     * @param int    $version
91
     * @param string $siteId
92
     * @param int    $versionExpected
93
     *
94
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
95
     */
96
    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...
97
    {
98
        $node = $this->repository->findInLastVersion(NodeInterface::ROOT_NODE_ID, $language, $siteId);
99
100
        $this->assertSameNode($language, $versionExpected, $siteId, $node);
101
    }
102
103
    /**
104
     * @param int    $countVersions
105
     * @param string $language
106
     * @param string $siteId
107
     *
108
     * @dataProvider provideLanguageAndVersionListAndSiteId
109
     */
110
    public function testFindNotDeletedSortByUpdatedAt($countVersions, $language, $siteId)
111
    {
112
        $nodes = $this->repository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $siteId);
113
114
        $this->assertCount($countVersions, $nodes);
115
        foreach ($nodes as $node) {
116
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
117
        }
118
        if (count($nodes) > 1) {
119
            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...
120
                $this->assertGreaterThan($nodes[$i]->getVersion(), $nodes[$i-1]->getVersion());
121
            }
122
        }
123
    }
124
125
    /**
126
     * @param int    $countVersions
127
     * @param string $language
128
     * @param string $siteId
129
     *
130
     * @dataProvider provideLanguageAndVersionListAndSiteId
131
     */
132
    public function testCountNotDeletedVersions($countVersions, $language, $siteId)
133
    {
134
        $countNodes = $this->repository->countNotDeletedVersions(NodeInterface::ROOT_NODE_ID, $language, $siteId);
135
136
        $this->assertSame($countVersions, $countNodes);
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(3, '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', 5),
169
            array('fixture_page_what_is_orchestra', '2', 0),
170
        );
171
    }
172
173
    /**
174
     * @param string $parentId
175
     * @param string $siteId
176
     * @param int    $count
177
     *
178
     * @dataProvider provideParentIdSiteIdAndCount
179
     */
180
    public function testFindByParent($parentId, $siteId, $count)
181
    {
182
        $nodes = $this->repository->findByParent($parentId, $siteId);
183
184
        $this->assertGreaterThanOrEqual($count, count($nodes));
185
    }
186
187
    /**
188
     * @return array
189
     */
190
    public function provideParentIdSiteIdAndCount()
191
    {
192
        return array(
193
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
194
            array('fixture_page_community', '2', 0),
195
            array('fixture_page_what_is_orchestra', '2', 0),
196
        );
197
    }
198
199
    /**
200
     * @param string $path
201
     * @param string $siteId
202
     * @param int    $count
203
     *
204
     * @dataProvider providePathSiteIdAndCount
205
     */
206
    public function testFindByIncludedPathAndSiteId($path, $siteId, $count)
207
    {
208
        $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId);
209
210
        $this->assertGreaterThanOrEqual($count, count($nodes));
211
    }
212
213
    /**
214
     * @return array
215
     */
216
    public function providePathSiteIdAndCount()
217
    {
218
        return array(
219
            array('root', '2', 5),
220
            array('root/fixture_page_community', '2', 0),
221
            array('transverse', '2', 0),
222
        );
223
    }
224
225
    /**
226
     * @param string $siteId
227
     * @param int    $version
228
     *
229
     * @dataProvider provideSiteIdAndLastVersion
230
     */
231
    public function testFindLastVersionByType($siteId, $version)
232
    {
233
        $nodes = $this->repository->findLastVersionByType($siteId);
234
235
        $this->assertSameNode('fr', $version, $siteId, $nodes[NodeInterface::ROOT_NODE_ID]);
236
    }
237
238
    /**
239
     * @return array
240
     */
241
    public function provideSiteIdAndLastVersion()
242
    {
243
        return array(
244
            array('2', 3),
245
        );
246
    }
247
248
    /**
249
     * @param string        $language
250
     * @param int           $version
251
     * @param string        $siteId
252
     * @param NodeInterface $node
253
     * @param string        $nodeId
254
     */
255
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
256
    {
257
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
258
        $this->assertSame($nodeId, $node->getNodeId());
259
        $this->assertSame($language, $node->getLanguage());
260
        $this->assertSame($version, $node->getVersion());
261
        $this->assertSame($siteId, $node->getSiteId());
262
        $this->assertSame(false, $node->isDeleted());
263
    }
264
265
    /**
266
     * @param string      $siteId
267
     * @param int         $nodeNumber
268
     * @param int         $version
269
     * @param string      $language
270
     * @param string|null $nodeId
271
     *
272
     * @dataProvider provideForGetFooter()
273
     */
274 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...
275
    {
276
        $nodes = $this->repository->getFooterTree($language, $siteId);
277
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[0], $nodeId);
281
            $this->assertSame('published', $nodes[0]->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 View Code Duplication
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
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...
306
    {
307
        $nodes = $this->repository->getMenuTree($language, $siteId);
308
309
        $this->assertCount($nodeNumber, $nodes);
310
        $this->assertSameNode($language, $version, $siteId, $nodes[0]);
311
        $this->assertSame('published', $nodes[0]->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
    public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local)
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 testFindPublishedByLanguageAndSiteId($language, $siteId, $count)
370
    {
371
        $nodes = $this->repository->findPublishedByLanguageAndSiteId($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', 5),
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
     * Test has statused element
524
     */
525 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...
526
    {
527
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
528
        $status = $statusRepository->findOneByInitial();
529
530
        $this->assertTrue($this->repository->hasStatusedElement($status));
531
    }
532
533
    /**
534
     * Test find by site and defaultTheme
535
     */
536
    public function testFindBySiteIdAndDefaultTheme()
537
    {
538
        $this->assertCount(0, $this->repository->findBySiteIdAndDefaultTheme('2', false));
539
        $this->assertGreaterThanOrEqual(16, $this->repository->findBySiteIdAndDefaultTheme('2', true));
540
    }
541
542
    /**
543
     * @return array
544
     */
545
    public function provideNodeIdAndLanguageForPublishedFlag()
546
    {
547
        return array(
548
            'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'),
549
            'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'),
550
            'community in fr' => array('fixture_page_community', 'fr'),
551
            'community in en' => array('fixture_page_community', 'en'),
552
        );
553
    }
554
555
    /**
556
     * @param string  $siteId
557
     * @param integer $expectedCount
558
     *
559
     * @dataProvider provideFindPublishedByType
560
     */
561
    public function testFindPublishedByType($siteId, $expectedCount)
562
    {
563
        $this->assertCount($expectedCount, $this->repository->findPublishedByType($siteId));
564
    }
565
566
    /**
567
     * @return array
568
     */
569
    public function provideFindPublishedByType()
570
    {
571
        return array(
572
            array("1", 0),
573
            array("2", 16),
574
        );
575
    }
576
577
    /**
578
     * @param string  $path
579
     * @param string  $siteId
580
     * @param string  $language
581
     * @param integer $expectedCount
582
     *
583
     * @dataProvider provideFindPublishedByPathAndLanguage
584
     */
585
    public function testFindPublishedByPathAndLanguage($path, $siteId, $language, $expectedCount)
586
    {
587
        $this->assertCount($expectedCount, $this->repository->findPublishedByPathAndLanguage($path, $siteId, $language));
588
    }
589
590
    /**
591
     * @return array
592
     */
593 View Code Duplication
    public function provideFindPublishedByPathAndLanguage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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

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

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

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

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

Loading history...
841
    {
842
        $dm = static::$kernel->getContainer()->get('object_manager');
843
        $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', 1);
844
        $storageIds = array($node->geTId());
845
        $dm->detach($node);
846
847
        $this->repository->removeNodeVersions($storageIds);
848
        $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', 1));
849
850
        $dm->persist($node);
851
        $dm->flush();
852
    }
853
}
854