These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | protected function setUp() |
||
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
|
|||
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
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
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
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() |
|
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
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
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 For '' == 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 | public function provideForGetFooter() |
||
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') |
|
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
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, 6, '1', '2', 'fr'), |
||
325 | array(NodeInterface::ROOT_NODE_ID, 2, 6, '1', '2', 'fr'), |
||
326 | array(NodeInterface::ROOT_NODE_ID, 0, 6, '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() |
|
355 | { |
||
356 | return array( |
||
357 | array('en', '2', 6), |
||
358 | array('fr', '2', 6), |
||
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) |
|
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', 5), |
||
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
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", 17), |
||
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() |
|
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->findByIncludedPathSiteIdAndLanguage($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 tree node |
||
589 | */ |
||
590 | public function testFindTreeNode() |
||
591 | { |
||
592 | $tree = $this->repository->findTreeNode('2', 'fr', '-'); |
||
593 | |||
594 | $this->assertCount(3, $tree); |
||
595 | |||
596 | $nodeRootTree = $tree[0]; |
||
597 | $nodeRoot = $nodeRootTree['node']; |
||
598 | $this->assertCount(5, $nodeRootTree['child']); |
||
599 | $this->assertSame('root', $nodeRoot['nodeId']); |
||
600 | $childrenRoot = $nodeRootTree['child']; |
||
601 | $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish'); |
||
602 | foreach ($childrenRoot as $index => $child) { |
||
603 | $this->assertCount(0, $child['child']); |
||
604 | $this->assertSame($orderNodeId[$index], $child['node']['nodeId']); |
||
605 | } |
||
606 | |||
607 | $node404Tree = $tree[1]; |
||
608 | $node404 = $node404Tree['node']; |
||
609 | $this->assertCount(0, $node404Tree['child']); |
||
610 | $this->assertSame('errorPage404', $node404['nodeId']); |
||
611 | |||
612 | $node503Tree = $tree[2]; |
||
613 | $node503 = $node503Tree['node']; |
||
614 | $this->assertCount(0, $node503Tree['child']); |
||
615 | $this->assertSame('errorPage503', $node503['nodeId']); |
||
616 | } |
||
617 | |||
618 | /** |
||
619 | * @param string $siteId |
||
620 | * @param string $language |
||
621 | * @param int $count |
||
622 | * |
||
623 | * @dataProvider provideSiteIdAndLanguage |
||
624 | */ |
||
625 | public function testCount($siteId, $language, $count) |
||
626 | { |
||
627 | $this->assertEquals($count, $this->repository->count($siteId, $language)); |
||
628 | } |
||
629 | |||
630 | /** |
||
631 | * @return array |
||
632 | */ |
||
633 | public function provideSiteIdAndLanguage() |
||
634 | { |
||
635 | return array( |
||
636 | array('2', 'fr', 8), |
||
637 | array('2', 'en', 8), |
||
638 | array('2', 'de', 7), |
||
639 | array('3', 'fr', 1), |
||
640 | ); |
||
641 | } |
||
642 | |||
643 | /** |
||
644 | * @param PaginateFinderConfiguration $configuration |
||
645 | * @param string $siteId |
||
646 | * @param string $language |
||
647 | * @param int $count |
||
648 | * |
||
649 | * @dataProvider provideCountWithFilterPaginateConfiguration |
||
650 | */ |
||
651 | public function testCountWithFilter($configuration, $siteId, $language, $count) |
||
652 | { |
||
653 | $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language)); |
||
654 | } |
||
655 | |||
656 | /** |
||
657 | * @return array |
||
658 | */ |
||
659 | public function provideCountWithFilterPaginateConfiguration() |
||
660 | { |
||
661 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
662 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
663 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
664 | |||
665 | return array( |
||
666 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
667 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
668 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
669 | ); |
||
670 | } |
||
671 | |||
672 | /** |
||
673 | * @param PaginateFinderConfiguration $configuration |
||
674 | * @param string $siteId |
||
675 | * @param string $language |
||
676 | * @param int $count |
||
677 | * |
||
678 | * @dataProvider provideFindWithFilterPaginateConfiguration |
||
679 | */ |
||
680 | public function testFindForPaginate($configuration, $siteId, $language, $count) |
||
681 | { |
||
682 | $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language)); |
||
683 | } |
||
684 | |||
685 | /** |
||
686 | * @return array |
||
687 | */ |
||
688 | public function provideFindWithFilterPaginateConfiguration() |
||
689 | { |
||
690 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
691 | $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array()); |
||
692 | $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array()); |
||
693 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
694 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
695 | |||
696 | return array( |
||
697 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
698 | 'limit' => array($configurationLimit, '2', 'fr', 2), |
||
699 | 'skip' => array($configurationSkip, '2', 'fr', 6), |
||
700 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
701 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
702 | ); |
||
703 | } |
||
704 | |||
705 | /** |
||
706 | * Test update order of brothers |
||
707 | */ |
||
708 | public function testUpdateOrderOfBrothers() |
||
709 | { |
||
710 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
711 | $nodeNews = $this->repository->findOneByNodeAndSite('fixture_page_news', '2'); |
||
712 | $nodeCommunity = $this->repository->findOneByNodeAndSite('fixture_page_community', '2'); |
||
713 | $nodeContact= $this->repository->findOneByNodeAndSite('fixture_page_contact', '2'); |
||
714 | $dm->detach($nodeContact); |
||
715 | $dm->detach($nodeCommunity); |
||
716 | $dm->detach($nodeNews); |
||
717 | |||
718 | $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId()); |
||
719 | |||
720 | $nodeNewsAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_news', '2'); |
||
721 | $nodeCommunityAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_community', '2'); |
||
722 | $nodeContactAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_contact', '2'); |
||
723 | |||
724 | $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder()); |
||
725 | $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder()); |
||
726 | $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder()); |
||
727 | |||
728 | } |
||
729 | |||
730 | /** |
||
731 | * Test remove block in area |
||
732 | */ |
||
733 | public function testRemoveBlockInArea() |
||
734 | { |
||
735 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
736 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
737 | $block = $node->getArea('main')->getBlocks()[0]; |
||
738 | $this->assertCount(2, $node->getArea('main')->getBlocks()); |
||
739 | |||
740 | $this->repository->removeBlockInArea($block->getId(), 'main', $node->getNodeId(), $node->getSiteId(), $node->getLanguage(), $node->getVersion()); |
||
741 | |||
742 | $dm->detach($node); |
||
743 | $dm->detach($block); |
||
744 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
745 | $blocks = $node->getArea('main')->getBlocks(); |
||
746 | $this->assertCount(1, $blocks); |
||
747 | |||
748 | $node->getArea('main')->addBlock($block); |
||
749 | $dm->persist($block); |
||
750 | $dm->flush(); |
||
751 | } |
||
752 | |||
753 | /** |
||
754 | * @param string $nodeId |
||
755 | * @param string $siteId |
||
756 | * @param string $areaId |
||
757 | * @param int $count |
||
758 | * |
||
759 | * @dataProvider provideFindByNodeIdAndSiteIdWithBlocksInArea |
||
760 | */ |
||
761 | public function testFindByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId, $count) |
||
762 | { |
||
763 | $nodes = $this->repository->findByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId); |
||
764 | $this->assertCount($count, $nodes); |
||
765 | } |
||
766 | |||
767 | /** |
||
768 | * @return array |
||
769 | */ |
||
770 | public function provideFindByNodeIdAndSiteIdWithBlocksInArea() |
||
771 | { |
||
772 | return array( |
||
773 | array('root', '2', 'main', 3), |
||
774 | array('root', 'fake', 'footer', 0), |
||
775 | ); |
||
776 | } |
||
777 | |||
778 | /** |
||
779 | * Test remove node version |
||
780 | */ |
||
781 | View Code Duplication | public function testRemoveVersion() |
|
0 ignored issues
–
show
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...
|
|||
782 | { |
||
783 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
784 | $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', '1'); |
||
785 | $storageIds = array($node->geTId()); |
||
786 | $dm->detach($node); |
||
787 | |||
788 | $this->repository->removeNodeVersions($storageIds); |
||
789 | $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', '1')); |
||
790 | |||
791 | $dm->persist($node); |
||
792 | $dm->flush(); |
||
793 | } |
||
794 | |||
795 | /** |
||
796 | * @param string $language |
||
797 | * @param string $siteId |
||
798 | * @param int $count |
||
799 | * |
||
800 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
801 | */ |
||
802 | public function testFindAllPublishedSpecialPage($language, $siteId, $count) |
||
803 | { |
||
804 | $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId); |
||
805 | $this->assertCount($count, $nodes); |
||
806 | } |
||
807 | |||
808 | /** |
||
809 | * @param string $language |
||
810 | * @param string $siteId |
||
811 | * @param int $count |
||
812 | * |
||
813 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
814 | */ |
||
815 | public function testFindAllSpecialPage($language, $siteId, $count) |
||
816 | { |
||
817 | $nodes = $this->repository->findAllSpecialPage($language, $siteId); |
||
818 | $this->assertCount($count, $nodes); |
||
819 | } |
||
820 | |||
821 | /** |
||
822 | * @return array |
||
823 | */ |
||
824 | public function provideLanguageAndSiteIdSpecialPage() |
||
825 | { |
||
826 | return array( |
||
827 | array('fr', '2', 1), |
||
828 | array('en', '2', 1), |
||
829 | array('de', '2', 1), |
||
830 | array('fr', '3', 0), |
||
831 | array('en', '3', 0), |
||
832 | array('de', '3', 0), |
||
833 | ); |
||
834 | } |
||
835 | |||
836 | /** |
||
837 | * @param string $nodeId |
||
838 | * @param string $language |
||
839 | * @param string $siteId |
||
840 | * @param string $name |
||
841 | * @param int $count |
||
842 | * |
||
843 | * @dataProvider provideCountOtherNodeWithSameSpecialPageName |
||
844 | */ |
||
845 | public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count) |
||
846 | { |
||
847 | $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name); |
||
848 | $this->assertSame($count, $nodesCount); |
||
849 | } |
||
850 | |||
851 | /** |
||
852 | * @return array |
||
853 | */ |
||
854 | public function provideCountOtherNodeWithSameSpecialPageName() |
||
855 | { |
||
856 | return array( |
||
857 | array('root', 'fr', '2', 'DEFAULT', 1), |
||
858 | array('root', 'en', '2', 'DEFAULT', 1), |
||
859 | array('root', 'de', '2', 'DEFAULT', 1), |
||
860 | array('root', 'fr', '2', 'FAKE', 0), |
||
861 | array('root', 'en', '2', 'FAKE', 0), |
||
862 | array('root', 'de', '2', 'FAKE', 0), |
||
863 | array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0), |
||
864 | array('fixture_page_contact', 'en', '2', 'DEFAULT', 0), |
||
865 | array('fixture_page_contact', 'de', '2', 'DEFAULT', 0), |
||
866 | ); |
||
867 | } |
||
868 | |||
869 | /** |
||
870 | * Test update use Reference |
||
871 | */ |
||
872 | public function testUpdateUseReference() |
||
873 | { |
||
874 | $nodeId = 'root'; |
||
875 | $siteId = '3'; |
||
876 | $entityType = NodeInterface::ENTITY_TYPE; |
||
877 | $referenceNodeId = 'fakeReferenceId'; |
||
878 | $this->repository->updateUseReference($referenceNodeId, $nodeId, $siteId, $entityType); |
||
879 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
880 | foreach ($nodes as $node) { |
||
881 | $this->assertTrue(array_key_exists($referenceNodeId, $node->getUseReferences($entityType))); |
||
882 | } |
||
883 | } |
||
884 | |||
885 | /** |
||
886 | * Test soft delete node |
||
887 | */ |
||
888 | public function testSoftDeleteAndRestoreNode() |
||
889 | { |
||
890 | $nodeId = 'root'; |
||
891 | $siteId = '2'; |
||
892 | |||
893 | $this->repository->softDeleteNode($nodeId, $siteId); |
||
894 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
895 | foreach ($nodes as $node) { |
||
896 | $this->assertTrue($node->isDeleted()); |
||
897 | } |
||
898 | $this->repository->restoreDeletedNode($nodeId, $siteId); |
||
899 | |||
900 | $documentManager = static::$kernel->getContainer()->get('object_manager'); |
||
901 | $documentManager->clear(); |
||
902 | $documentManager->close(); |
||
903 | |||
904 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
905 | foreach ($nodes as $node) { |
||
906 | $this->assertFalse($node->isDeleted()); |
||
907 | } |
||
908 | } |
||
909 | |||
910 | /** |
||
911 | * @param string $nodeId |
||
912 | * @param string $siteId |
||
913 | * @param bool $has |
||
914 | * |
||
915 | * @dataProvider provideNodeNotOffline |
||
916 | */ |
||
917 | public function testHasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId, $has) |
||
918 | { |
||
919 | $this->assertSame($has, $this->repository->hasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId)); |
||
920 | } |
||
921 | |||
922 | /** |
||
923 | * @return array |
||
924 | */ |
||
925 | public function provideNodeNotOffline() |
||
926 | { |
||
927 | return array( |
||
928 | array('root', '2', true), |
||
929 | array('fixture_page_contact', '2', true) |
||
930 | ); |
||
931 | } |
||
932 | |||
933 | /** |
||
934 | * @param string $parentId |
||
935 | * @param string $siteId |
||
936 | * @param int $count |
||
937 | * |
||
938 | * @dataProvider provideCountByParentId |
||
939 | */ |
||
940 | public function testCountByParentId($parentId, $siteId, $count) |
||
941 | { |
||
942 | $this->assertEquals($count, $this->repository->countByParentId($parentId, $siteId)); |
||
943 | } |
||
944 | |||
945 | /** |
||
946 | * @return array |
||
947 | */ |
||
948 | public function provideCountByParentId() |
||
949 | { |
||
950 | return array( |
||
951 | array('fixture_page_contact', '2', 0), |
||
952 | array('root', '2', 15) |
||
953 | ); |
||
954 | } |
||
955 | |||
956 | /** |
||
957 | * Test update embedded status |
||
958 | */ |
||
959 | View Code Duplication | public function testUpdateEmbeddedStatus() |
|
0 ignored issues
–
show
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...
|
|||
960 | { |
||
961 | $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
962 | $status = $statusRepository->findOneByName('published'); |
||
963 | $fakeColor = 'fakeColor'; |
||
964 | $saveColor = $status->getDisplayColor(); |
||
965 | $status->setDisplayColor($fakeColor); |
||
966 | $this->repository->updateEmbeddedStatus($status); |
||
967 | |||
968 | $node = $this->repository->findOnePublished('root', 'fr', '2'); |
||
969 | $this->assertEquals($fakeColor, $node->getStatus()->getDisplayColor()); |
||
970 | |||
971 | $status->setDisplayColor($saveColor); |
||
972 | $this->repository->updateEmbeddedStatus($status); |
||
973 | } |
||
974 | } |
||
975 |
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.