NodeRepositoryTest   D
last analyzed

Coupling/Cohesion

Components 1
Dependencies 6

Complexity

Total Complexity 81

Size/Duplication

Total Lines 1025
Duplicated Lines 15.51 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 81
c 1
b 0
f 0
lcom 1
cbo 6
dl 159
loc 1025
rs 4.4353

71 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A testFindOnePublished() 0 6 1
A testFindVersionNotDeleted() 0 7 1
A provideLanguageLastVersionAndSiteIdNotPublished() 7 7 1
A testFindInLastVersion() 0 6 1
A provideNodeLanguageLastVersionAndSiteId() 7 7 1
A testFindNotDeletedSortByUpdatedAt() 0 14 4
A testCountNotDeletedVersions() 0 6 1
A testFindByNodeAndSite() 0 4 1
A provideNodeSiteAndCount() 0 7 1
A testFindByParent() 0 6 1
A provideParentIdSiteIdAndCount() 0 8 1
A testFindLastVersionByType() 0 7 1
A assertSameNode() 0 9 1
A testGetFooterTree() 10 10 2
A provideForGetFooter() 8 8 1
A provideForGetMenu() 7 7 1
A provideForGetSubMenu() 0 12 1
A testFindPublishedByLanguageAndSiteId() 0 9 2
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 testHasStatusedElement() 7 7 1
A provideNodeIdAndLanguageForPublishedFlag() 0 9 1
A testFindPublishedByType() 0 4 1
A provideFindPublishedByType() 0 7 1
A testFindPublishedByPathAndLanguage() 0 4 1
A provideLanguageLastVersionAndSiteId() 7 7 1
A provideLanguageAndVersionListAndSiteId() 7 7 1
A testGetMenuTree() 8 8 1
A testGetSubMenu() 0 10 2
A provideLanguageSiteIdAndCount() 7 7 1
A provideFindPublishedByPathAndLanguage() 7 7 1
A testFindAllRoutePattern() 0 10 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 19 1
A testFindByNodeIdAndSiteIdWithBlocksInArea() 0 5 1
A provideFindByNodeIdAndSiteIdWithBlocksInArea() 0 7 1
A testRemoveVersion() 13 13 1
A testFindAllPublishedSpecialPage() 0 5 1
A testFindAllSpecialPage() 0 5 1
A provideLanguageAndSiteIdSpecialPage() 0 11 1
A testCountOtherNodeWithSameSpecialPageName() 0 5 1
A provideCountOtherNodeWithSameSpecialPageName() 0 14 1
A testUpdateUseReference() 0 12 2
A testSoftDeleteAndRestoreNode() 0 21 3
A testHasNodeIdWithoutAutoUnpublishToState() 0 4 1
A provideNodeNotOffline() 0 7 1
A testCountByParentId() 0 4 1
A provideCountByParentId() 7 7 1
A testCountById() 0 4 1
A provideCountById() 7 7 1
A testUpdateEmbeddedStatus() 15 15 1
A testFindLastVersionByLanguage() 0 6 1
A provideSiteAndLanguage() 9 9 1
A testFindByIncludedPathSiteIdAndLanguage() 0 4 1
A provideFindByIncludedPathSiteIdAndLanguage() 0 6 1

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
11
/**
12
 * Class NodeRepositoryTest
13
 *
14
 * @group integrationTest
15
 */
16
class NodeRepositoryTest extends AbstractKernelTestCase
17
{
18
    /**
19
     * @var NodeRepository
20
     */
21
    protected $repository;
22
    protected $userRepository;
23
24
    /**
25
     * Set up test
26
     */
27 View Code Duplication
    protected function setUp()
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

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

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

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

Loading history...
54
    {
55
        return array(
56
            array('en', '1', '2'),
57
            array('fr', '1', '2'),
58
        );
59
    }
60
61
    /**
62
     * @param string $language
63
     * @param int    $version
64
     * @param string $siteId
65
     *
66
     * @dataProvider provideLanguageLastVersionAndSiteIdNotPublished
67
     */
68
    public function testFindVersionNotDeleted($language, $version, $siteId)
69
    {
70
        $node = $this->repository->findVersionNotDeleted(NodeInterface::ROOT_NODE_ID, $language, $siteId, $version);
71
72
        $this->assertSame($node->getNodeId(), NodeInterface::ROOT_NODE_ID);
73
        $this->assertSame($node->getVersion(), $version);
74
    }
75
76
    /**
77
     * @return array
78
     */
79 View Code Duplication
    public function provideLanguageLastVersionAndSiteIdNotPublished()
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
80
    {
81
        return array(
82
            array('fr', '2', '2', 3),
83
            array('fr', '1', '2', 3),
84
        );
85
    }
86
87
    /**
88
     * @param string $nodeId
89
     * @param string $language
90
     * @param string $siteId
91
     * @param int    $versionExpected
92
     *
93
     * @dataProvider provideNodeLanguageLastVersionAndSiteId
94
     */
95
    public function testFindInLastVersion($nodeId, $language, $siteId, $versionExpected)
96
    {
97
        $node = $this->repository->findInLastVersion($nodeId, $language, $siteId);
98
99
        $this->assertSameNode($language, $versionExpected, $siteId, $node, $nodeId);
100
    }
101
102
    /**
103
     * @return array
104
     */
105 View Code Duplication
    public function provideNodeLanguageLastVersionAndSiteId()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
This method seems to be duplicated in your project.

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

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

Loading history...
106
    {
107
        return array(
108
            array('fixture_auto_unpublish', 'fr', '2', '1'),
109
            array('fixture_page_news', 'fr', '2', '1'),
110
        );
111
    }
112
113
    /**
114
     * @param int    $countVersions
115
     * @param string $language
116
     * @param string $siteId
117
     *
118
     * @dataProvider provideLanguageAndVersionListAndSiteId
119
     */
120
    public function testFindNotDeletedSortByUpdatedAt($countVersions, $language, $siteId)
121
    {
122
        $nodes = $this->repository->findNotDeletedSortByUpdatedAt(NodeInterface::ROOT_NODE_ID, $language, $siteId);
123
124
        $this->assertCount($countVersions, $nodes);
125
        foreach ($nodes as $node) {
126
            $this->assertSameNode($language, $node->getVersion(), $siteId, $node);
127
        }
128
        if (count($nodes) > 1) {
129
            for ($i = 1; $i < count($nodes); $i++) {
0 ignored issues
show
Performance Best Practice introduced by Noël GILAIN
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

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

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

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

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

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

Loading history...
153
    {
154
        return array(
155
            array(1, 'en', '2'),
156
            array(3, 'fr', '2'),
157
        );
158
    }
159
160
    /**
161
     * @param string $nodeId
162
     * @param string $siteId
163
     * @param int    $count
164
     *
165
     * @dataProvider provideNodeSiteAndCount
166
     */
167
    public function testFindByNodeAndSite($nodeId, $siteId, $count)
168
    {
169
        $this->assertCount($count, $this->repository->findByNodeAndSite($nodeId, $siteId));
170
    }
171
172
    /**
173
     * @return array
174
     */
175
    public function provideNodeSiteAndCount()
176
    {
177
        return array(
178
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
179
            array('fixture_page_what_is_orchestra', '2', 0),
180
        );
181
    }
182
183
    /**
184
     * @param string $parentId
185
     * @param string $siteId
186
     * @param int    $count
187
     *
188
     * @dataProvider provideParentIdSiteIdAndCount
189
     */
190
    public function testFindByParent($parentId, $siteId, $count)
191
    {
192
        $nodes = $this->repository->findByParent($parentId, $siteId);
193
194
        $this->assertGreaterThanOrEqual($count, count($nodes));
195
    }
196
197
    /**
198
     * @return array
199
     */
200
    public function provideParentIdSiteIdAndCount()
201
    {
202
        return array(
203
            array(NodeInterface::ROOT_NODE_ID, '2', 5),
204
            array('fixture_page_community', '2', 0),
205
            array('fixture_page_what_is_orchestra', '2', 0),
206
        );
207
    }
208
209
    /**
210
     * Tets find last version by type
211
     */
212
    public function testFindLastVersionByType()
213
    {
214
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
215
        $nodes = $this->repository->findLastVersionByType('2');
216
217
        $this->assertSameNode('fr', $node->getVersion(), '2', $nodes[NodeInterface::ROOT_NODE_ID]);
218
    }
219
220
    /**
221
     * @param string        $language
222
     * @param int           $version
223
     * @param string        $siteId
224
     * @param NodeInterface $node
225
     * @param string        $nodeId
226
     */
227
    protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID)
228
    {
229
        $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node);
230
        $this->assertSame($nodeId, $node->getNodeId());
231
        $this->assertSame($language, $node->getLanguage());
232
        $this->assertSame($version, $node->getVersion());
233
        $this->assertSame($siteId, $node->getSiteId());
234
        $this->assertSame(false, $node->isDeleted());
235
    }
236
237
    /**
238
     * @param string      $siteId
239
     * @param int         $nodeNumber
240
     * @param int         $version
241
     * @param string      $language
242
     * @param string|null $nodeId
243
     *
244
     * @dataProvider provideForGetFooter()
245
     */
246 View Code Duplication
    public function testGetFooterTree($siteId, $nodeNumber, $version, $language = 'fr', $nodeId = null)
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
247
    {
248
        $nodes = $this->repository->getFooterTree($language, $siteId);
249
250
        $this->assertCount($nodeNumber, $nodes);
251
        if ($nodeId) {
0 ignored issues
show
Bug Best Practice introduced by Noël GILAIN
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...
252
            $this->assertSameNode($language, $version, $siteId, $nodes[0], $nodeId);
253
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
254
        }
255
    }
256
257
    /**
258
     * @return array
259
     */
260 View Code Duplication
    public function provideForGetFooter()
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
261
    {
262
        return array(
263
            array('2', 1, '1', 'fr', 'fixture_page_legal_mentions'),
264
            array('2', 1, '1', 'en'),
265
            array('2', 1, '1'),
266
        );
267
    }
268
269
    /**
270
     * @param string      $siteId
271
     * @param int         $nodeNumber
272
     * @param int         $version
273
     * @param string      $language
274
     *
275
     * @dataProvider provideForGetMenu()
276
     */
277 View Code Duplication
    public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr')
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
278
    {
279
        $nodes = $this->repository->getMenuTree($language, $siteId);
280
281
        $this->assertCount($nodeNumber, $nodes);
282
        $this->assertSameNode($language, $version, $siteId, $nodes[0]);
283
        $this->assertSame('published', $nodes[0]->getStatus()->getName());
284
    }
285
286
    /**
287
     * @return array
288
     */
289 View Code Duplication
    public function provideForGetMenu()
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
290
    {
291
        return array(
292
            array('2', 4, '1', 'fr'),
293
            array('2', 4, '1', 'en'),
294
        );
295
    }
296
297
    /**
298
     * @param string $nodeId
299
     * @param int    $nbLevel
300
     * @param int    $nodeNumber
301
     * @param int    $version
302
     * @param string $siteId
303
     * @param string $local
304
     *
305
     * @dataProvider provideForGetSubMenu
306
     */
307
    public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local)
308
    {
309
        $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId);
310
311
        $this->assertCount($nodeNumber, $nodes);
312
        if ($nodeNumber > 0) {
313
            $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId);
314
            $this->assertSame('published', $nodes[0]->getStatus()->getName());
315
        }
316
    }
317
318
    /**
319
     * @return array
320
     */
321
    public function provideForGetSubMenu()
322
    {
323
        return array(
324
            array(NodeInterface::ROOT_NODE_ID, 1, 5, '1', '2', 'fr'),
325
            array(NodeInterface::ROOT_NODE_ID, 2, 5, '1', '2', 'fr'),
326
            array(NodeInterface::ROOT_NODE_ID, 0, 5, '1', '2', 'fr'),
327
            array(NodeInterface::ROOT_NODE_ID, 0, 6, '1', '2', 'en'),
328
            array('fixture_page_community', 1, 1, '1', '2', 'fr'),
329
            array('fixture_page_community', 1, 1, '1', '2', 'en'),
330
            array('page_unexistant', 1, 0, 1, '2', 'fr'),
331
        );
332
    }
333
334
    /**
335
     * @param string $language
336
     * @param string $siteId
337
     * @param int    $count
338
     *
339
     * @dataProvider provideLanguageSiteIdAndCount
340
     */
341
    public function testFindPublishedByLanguageAndSiteId($language, $siteId, $count)
342
    {
343
        $nodes = $this->repository->findPublishedByLanguageAndSiteId($language, $siteId);
344
345
        $this->assertCount($count, $nodes);
346
        foreach ($nodes as $node) {
347
            $this->assertSame($language, $node->getLanguage());
348
        }
349
    }
350
351
    /**
352
     * @return array
353
     */
354 View Code Duplication
    public function provideLanguageSiteIdAndCount()
0 ignored issues
show
Duplication introduced by itkg-ngilain
This method seems to be duplicated in your project.

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

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

Loading history...
355
    {
356
        return array(
357
            array('en', '2', 6),
358
            array('fr', '2', 5),
359
        );
360
    }
361
362
    /**
363
     * @param string       $user
364
     * @param string       $siteId
365
     * @param array        $eventTypes
366
     * @param boolean|null $published
367
     * @param int          $limit
368
     * @param array|null   $sort
369
     * @param int          $count
370
     *
371
     * @dataProvider provideFindByHistoryAndSiteId
372
     */
373 View Code Duplication
    public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count)
0 ignored issues
show
Duplication introduced by itkg-nanne
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...
374
    {
375
        $user = $this->userRepository->findOneByUsername($user);
376
377
        $this->assertCount(
378
            $count,
379
            $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort)
380
        );
381
    }
382
383
    /**
384
     * @return array
385
     */
386
    public function provideFindByHistoryAndSiteId()
387
    {
388
        return array(
389
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 0),
390
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0),
391
            array('p-admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 0),
392
            array('developer', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), false, 10, null, 1),
393
        );
394
    }
395
396
    /**
397
     * @param string $nodeId
398
     * @param string $language
399
     * @param int    $count
400
     *
401
     * @dataProvider provideFindPublishedSortedVersionData
402
     */
403
    public function testFindPublishedSortedByVersion($nodeId, $language, $count)
404
    {
405
        $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2'));
406
    }
407
408
    /**
409
     * @return array
410
     */
411
    public function provideFindPublishedSortedVersionData()
412
    {
413
        return array(
414
            array(NodeInterface::ROOT_NODE_ID, 'fr', 1),
415
            array(NodeInterface::ROOT_NODE_ID, 'en', 1),
416
            array('fixture_page_contact', 'en', 1),
417
        );
418
    }
419
420
    /**
421
     * @param string $language
422
     * @apram int    $expectedCount
423
     *
424
     * @dataProvider provideLanguage
425
     */
426
    public function testFindSubTreeByPath($language, $expectedCount)
427
    {
428
        $nodes = $this->repository->findSubTreeByPath('root', '2', $language);
429
430
        $this->assertCount($expectedCount, $nodes);
431
    }
432
433
    /**
434
     * @return array
435
     */
436
    public function provideLanguage()
437
    {
438
        return array(
439
            array('en', 5),
440
            array('fr', 4),
441
        );
442
    }
443
444
    /**
445
     * @param string $parentId
446
     * @param string $routePattern
447
     * @param string $nodeId
448
     *
449
     * @dataProvider provideParentRouteAndNodeId
450
     */
451
    public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId)
452
    {
453
        $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2'));
454
    }
455
456
    /**
457
     * @return array
458
     */
459
    public function provideParentRouteAndNodeId()
460
    {
461
        return array(
462
            array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'),
463
            array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'),
464
        );
465
    }
466
467
    /**
468
     * @param string $parentId
469
     * @param int    $order
470
     * @param string $nodeId
471
     * @param bool   $expectedValue
472
     * @param string $siteId
473
     *
474
     * @dataProvider provideParentAndOrder
475
     */
476
    public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2')
477
    {
478
        $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId));
479
    }
480
481
    /**
482
     * @return array
483
     */
484
    public function provideParentAndOrder()
485
    {
486
        return array(
487
            array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true),
488
            array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false),
489
            array('fixture_page_legal_mentions', 0, 'fakeID', false),
490
            array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'),
491
        );
492
    }
493
494
    /**
495
     * Test has statused element
496
     */
497 View Code Duplication
    public function testHasStatusedElement()
0 ignored issues
show
Duplication introduced by Noël GILAIN
This method seems to be duplicated in your project.

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

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

Loading history...
498
    {
499
        $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
500
        $status = $statusRepository->findOneByInitial();
501
502
        $this->assertTrue($this->repository->hasStatusedElement($status));
503
    }
504
505
    /**
506
     * @return array
507
     */
508
    public function provideNodeIdAndLanguageForPublishedFlag()
509
    {
510
        return array(
511
            'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'),
512
            'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'),
513
            'community in fr' => array('fixture_page_community', 'fr'),
514
            'community in en' => array('fixture_page_community', 'en'),
515
        );
516
    }
517
518
    /**
519
     * @param string  $siteId
520
     * @param integer $expectedCount
521
     *
522
     * @dataProvider provideFindPublishedByType
523
     */
524
    public function testFindPublishedByType($siteId, $expectedCount)
525
    {
526
        $this->assertCount($expectedCount, $this->repository->findPublishedByType($siteId));
527
    }
528
529
    /**
530
     * @return array
531
     */
532
    public function provideFindPublishedByType()
533
    {
534
        return array(
535
            array("1", 0),
536
            array("2", 16),
537
        );
538
    }
539
540
    /**
541
     * @param string  $path
542
     * @param string  $siteId
543
     * @param string  $language
544
     * @param integer $expectedCount
545
     *
546
     * @dataProvider provideFindPublishedByPathAndLanguage
547
     */
548
    public function testFindPublishedByPathAndLanguage($path, $siteId, $language, $expectedCount)
549
    {
550
        $this->assertCount($expectedCount, $this->repository->findPublishedByPathAndLanguage($path, $siteId, $language));
551
    }
552
553
    /**
554
     * @return array
555
     */
556 View Code Duplication
    public function provideFindPublishedByPathAndLanguage()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
This method seems to be duplicated in your project.

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

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

Loading history...
557
    {
558
        return array(
559
            array("root", "2", "en", 6),
560
            array("transverse", "2", "en", 0),
561
        );
562
    }
563
564
    /**
565
     * @param string  $path
566
     * @param string  $siteId
567
     * @param string  $language
568
     * @param integer $expectedCount
569
     *
570
     * @dataProvider provideFindByIncludedPathSiteIdAndLanguage
571
     */
572
    public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount)
573
    {
574
        $this->assertCount($expectedCount, $this->repository->findNodeIdByIncludedPathSiteIdAndLanguage($path, $siteId, $language));
575
    }
576
577
    /**
578
     * @return array
579
     */
580
    public function provideFindByIncludedPathSiteIdAndLanguage()
581
    {
582
        return array(
583
            array("root", "2", "en", 6),
584
        );
585
    }
586
587
    /**
588
     * Test find all router pattern
589
     */
590
    public function testFindAllRoutePattern()
591
    {
592
        $routePatterns = $this->repository->findAllRoutePattern( 'fr', '2');
593
        $this->assertCount(12, $routePatterns);
594
595
        $routePattern = $routePatterns[0];
596
        $this->assertArrayHasKey('routePattern', $routePattern);
597
        $this->assertArrayHasKey('nodeId', $routePattern);
598
        $this->assertArrayHasKey('parentId', $routePattern);
599
    }
600
601
    /**
602
     * test find tree node
603
     */
604
    public function testFindTreeNode()
605
    {
606
        $tree = $this->repository->findTreeNode('2', 'fr', '-');
607
608
        $this->assertCount(3, $tree);
609
610
        $nodeRootTree = $tree[0];
611
        $nodeRoot = $nodeRootTree['node'];
612
        $this->assertCount(5, $nodeRootTree['child']);
613
        $this->assertSame('root', $nodeRoot['nodeId']);
614
        $childrenRoot = $nodeRootTree['child'];
615
        $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish');
616
        foreach ($childrenRoot as $index => $child) {
617
            $this->assertCount(0, $child['child']);
618
            $this->assertSame($orderNodeId[$index], $child['node']['nodeId']);
619
        }
620
621
        $node404Tree = $tree[1];
622
        $node404 = $node404Tree['node'];
623
        $this->assertCount(0, $node404Tree['child']);
624
        $this->assertSame('errorPage404', $node404['nodeId']);
625
626
        $node503Tree = $tree[2];
627
        $node503 = $node503Tree['node'];
628
        $this->assertCount(0, $node503Tree['child']);
629
        $this->assertSame('errorPage503', $node503['nodeId']);
630
    }
631
632
    /**
633
     * @param string $siteId
634
     * @param string $language
635
     * @param int    $count
636
     *
637
     * @dataProvider provideSiteIdAndLanguage
638
     */
639
    public function testCount($siteId, $language, $count)
640
    {
641
        $this->assertEquals($count, $this->repository->count($siteId, $language));
642
    }
643
644
    /**
645
     * @return array
646
     */
647 View Code Duplication
    public function provideSiteIdAndLanguage()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
This method seems to be duplicated in your project.

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

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

Loading history...
648
    {
649
        return array(
650
            array('2', 'fr', 8),
651
            array('2', 'en', 8),
652
            array('2', 'de', 7),
653
            array('3', 'fr', 1),
654
        );
655
    }
656
657
    /**
658
     * @param PaginateFinderConfiguration $configuration
659
     * @param string                      $siteId
660
     * @param string                      $language
661
     * @param int                         $count
662
     *
663
     * @dataProvider provideCountWithFilterPaginateConfiguration
664
     */
665
    public function testCountWithFilter($configuration, $siteId, $language, $count)
666
    {
667
        $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language));
668
    }
669
670
    /**
671
     * @return array
672
     */
673
    public function provideCountWithFilterPaginateConfiguration()
674
    {
675
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
676
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
677
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
678
679
        return array(
680
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
681
            'order' => array($configurationOrder, '2', 'fr', 8),
682
            'filter' => array($configurationFilter, '2', 'fr', 1),
683
        );
684
    }
685
686
    /**
687
     * @param PaginateFinderConfiguration $configuration
688
     * @param string                      $siteId
689
     * @param string                      $language
690
     * @param int                         $count
691
     *
692
     * @dataProvider provideFindWithFilterPaginateConfiguration
693
     */
694
    public function testFindForPaginate($configuration, $siteId, $language, $count)
695
    {
696
        $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language));
697
    }
698
699
    /**
700
     * @return array
701
     */
702
    public function provideFindWithFilterPaginateConfiguration()
703
    {
704
        $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
705
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array());
706
        $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array());
707
        $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt'));
708
        $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra'));
709
710
        return array(
711
            'all' => array($configurationAllPaginate, '2', 'fr', 8),
712
            'limit' => array($configurationLimit, '2', 'fr', 2),
713
            'skip' => array($configurationSkip, '2', 'fr', 6),
714
            'order' => array($configurationOrder, '2', 'fr', 8),
715
            'filter' => array($configurationFilter, '2', 'fr', 1),
716
        );
717
    }
718
719
    /**
720
     * Test update order of brothers
721
     */
722
    public function testUpdateOrderOfBrothers()
723
    {
724
        $dm = static::$kernel->getContainer()->get('object_manager');
725
        $nodeNews = $this->repository->findOneByNodeAndSite('fixture_page_news', '2');
726
        $nodeCommunity = $this->repository->findOneByNodeAndSite('fixture_page_community', '2');
727
        $nodeContact= $this->repository->findOneByNodeAndSite('fixture_page_contact', '2');
728
        $dm->detach($nodeContact);
729
        $dm->detach($nodeCommunity);
730
        $dm->detach($nodeNews);
731
732
        $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId());
733
734
        $nodeNewsAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_news', '2');
735
        $nodeCommunityAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_community', '2');
736
        $nodeContactAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_contact', '2');
737
738
        $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder());
739
        $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder());
740
        $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder());
741
742
    }
743
744
    /**
745
     * Test remove block in area
746
     */
747
    public function testRemoveBlockInArea()
748
    {
749
        $dm = static::$kernel->getContainer()->get('object_manager');
750
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
751
        $block = $node->getArea('main')->getBlocks()[0];
752
        $this->assertCount(2, $node->getArea('main')->getBlocks());
753
754
        $this->repository->removeBlockInArea($block->getId(), 'main', $node->getNodeId(), $node->getSiteId(), $node->getLanguage(), $node->getVersion());
755
756
        $dm->detach($node);
757
        $dm->detach($block);
758
        $node = $this->repository->findInLastVersion('root', 'fr', '2');
759
        $blocks = $node->getArea('main')->getBlocks();
760
        $this->assertCount(1, $blocks);
761
762
        $node->getArea('main')->addBlock($block);
763
        $dm->persist($block);
764
        $dm->flush();
765
    }
766
767
    /**
768
     * @param string $nodeId
769
     * @param string $siteId
770
     * @param string $areaId
771
     * @param int    $count
772
     *
773
     * @dataProvider provideFindByNodeIdAndSiteIdWithBlocksInArea
774
     */
775
    public function testFindByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId, $count)
776
    {
777
        $nodes = $this->repository->findByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId);
778
        $this->assertCount($count, $nodes);
779
    }
780
781
    /**
782
     * @return array
783
     */
784
    public function provideFindByNodeIdAndSiteIdWithBlocksInArea()
785
    {
786
        return array(
787
            array('root', '2', 'main', 3),
788
            array('root', 'fake', 'footer', 0),
789
        );
790
    }
791
792
    /**
793
     * Test remove node version
794
     */
795 View Code Duplication
    public function testRemoveVersion()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
This method seems to be duplicated in your project.

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

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

Loading history...
796
    {
797
        $dm = static::$kernel->getContainer()->get('object_manager');
798
        $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', '1');
799
        $storageIds = array($node->geTId());
800
        $dm->detach($node);
801
802
        $this->repository->removeNodeVersions($storageIds);
803
        $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', '1'));
804
805
        $dm->persist($node);
806
        $dm->flush();
807
    }
808
809
    /**
810
     * @param string $language
811
     * @param string $siteId
812
     * @param int    $count
813
     *
814
     * @dataProvider provideLanguageAndSiteIdSpecialPage
815
     */
816
    public function testFindAllPublishedSpecialPage($language, $siteId, $count)
817
    {
818
        $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId);
819
        $this->assertCount($count, $nodes);
820
    }
821
822
    /**
823
     * @param string $language
824
     * @param string $siteId
825
     * @param int    $count
826
     *
827
     * @dataProvider provideLanguageAndSiteIdSpecialPage
828
     */
829
    public function testFindAllSpecialPage($language, $siteId, $count)
830
    {
831
        $nodes = $this->repository->findAllSpecialPage($language, $siteId);
832
        $this->assertCount($count, $nodes);
833
    }
834
835
    /**
836
     * @return array
837
     */
838
    public function provideLanguageAndSiteIdSpecialPage()
839
    {
840
        return array(
841
            array('fr', '2', 1),
842
            array('en', '2', 1),
843
            array('de', '2', 1),
844
            array('fr', '3', 0),
845
            array('en', '3', 0),
846
            array('de', '3', 0),
847
        );
848
    }
849
850
    /**
851
     * @param string $nodeId
852
     * @param string $language
853
     * @param string $siteId
854
     * @param string $name
855
     * @param int    $count
856
     *
857
     * @dataProvider provideCountOtherNodeWithSameSpecialPageName
858
     */
859
    public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count)
860
    {
861
        $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name);
862
        $this->assertSame($count, $nodesCount);
863
    }
864
865
    /**
866
     * @return array
867
     */
868
    public function provideCountOtherNodeWithSameSpecialPageName()
869
    {
870
        return array(
871
            array('root', 'fr', '2', 'DEFAULT', 1),
872
            array('root', 'en', '2', 'DEFAULT', 1),
873
            array('root', 'de', '2', 'DEFAULT', 1),
874
            array('root', 'fr', '2', 'FAKE', 0),
875
            array('root', 'en', '2', 'FAKE', 0),
876
            array('root', 'de', '2', 'FAKE', 0),
877
            array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0),
878
            array('fixture_page_contact', 'en', '2', 'DEFAULT', 0),
879
            array('fixture_page_contact', 'de', '2', 'DEFAULT', 0),
880
        );
881
    }
882
883
    /**
884
     * Test update use Reference
885
     */
886
    public function testUpdateUseReference()
887
    {
888
        $nodeId = 'root';
889
        $siteId = '3';
890
        $entityType = NodeInterface::ENTITY_TYPE;
891
        $referenceNodeId = 'fakeReferenceId';
892
        $this->repository->updateUseReference($referenceNodeId, $nodeId, $siteId, $entityType);
893
        $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId);
894
        foreach ($nodes as $node) {
895
            $this->assertTrue(array_key_exists($referenceNodeId, $node->getUseReferences($entityType)));
896
        }
897
    }
898
899
    /**
900
     * Test soft delete node
901
     */
902
    public function testSoftDeleteAndRestoreNode()
903
    {
904
        $nodeId = 'root';
905
        $siteId = '2';
906
907
        $this->repository->softDeleteNode($nodeId, $siteId);
908
        $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId);
909
        foreach ($nodes as $node) {
910
            $this->assertTrue($node->isDeleted());
911
        }
912
        $this->repository->restoreDeletedNode($nodeId, $siteId);
913
914
        $documentManager = static::$kernel->getContainer()->get('object_manager');
915
        $documentManager->clear();
916
        $documentManager->close();
917
918
        $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId);
919
        foreach ($nodes as $node) {
920
            $this->assertFalse($node->isDeleted());
921
        }
922
    }
923
924
    /**
925
     * @param string   $nodeId
926
     * @param string   $siteId
927
     * @param bool     $has
928
     *
929
     * @dataProvider provideNodeNotOffline
930
     */
931
    public function testHasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId, $has)
932
    {
933
        $this->assertSame($has, $this->repository->hasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId));
934
    }
935
936
    /**
937
     * @return array
938
     */
939
    public function provideNodeNotOffline()
940
    {
941
        return array(
942
            array('root', '2', true),
943
            array('fixture_page_contact', '2', true)
944
        );
945
    }
946
947
    /**
948
     * @param string $parentId
949
     * @param string $siteId
950
     * @param int    $count
951
     *
952
     * @dataProvider provideCountByParentId
953
     */
954
    public function testCountByParentId($parentId, $siteId, $count)
955
    {
956
        $this->assertEquals($count, $this->repository->countByParentId($parentId, $siteId));
957
    }
958
959
    /**
960
     * @return array
961
     */
962 View Code Duplication
    public function provideCountByParentId()
0 ignored issues
show
Duplication introduced by Amaury Lavieille
This method seems to be duplicated in your project.

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

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

Loading history...
963
    {
964
        return array(
965
            array('fixture_page_contact', '2', 0),
966
            array('root', '2', 15)
967
        );
968
    }
969
970
    /**
971
     * @param string $nodeId
972
     * @param string $siteId
973
     * @param int    $count
974
     *
975
     * @dataProvider provideCountById
976
     */
977
    public function testCountById($nodeId, $siteId, $count)
978
    {
979
        $this->assertEquals($count, $this->repository->countById($nodeId, $siteId));
980
    }
981
982
    /**
983
     * @return array
984
     */
985 View Code Duplication
    public function provideCountById()
0 ignored issues
show
Duplication introduced by itkg-nanne
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...
986
    {
987
        return array(
988
            array('fixture_page_contact', '2', 3),
989
            array('root', '2', 5)
990
        );
991
    }
992
993
    /**
994
     * Test update embedded status
995
     */
996 View Code Duplication
    public function testUpdateEmbeddedStatus()
0 ignored issues