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() |
|
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 | public function provideLanguageLastVersionAndSiteIdNotPublished() |
||
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 | public function provideNodeLanguageLastVersionAndSiteId() |
||
106 | { |
||
107 | return array( |
||
108 | array('fixture_page_community', '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
|
|||
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 | * @param string $path |
||
211 | * @param string $siteId |
||
212 | * @param int $count |
||
213 | * |
||
214 | * @dataProvider providePathSiteIdAndCount |
||
215 | */ |
||
216 | public function testFindByIncludedPathAndSiteId($path, $siteId, $count) |
||
217 | { |
||
218 | $nodes = $this->repository->findByIncludedPathAndSiteId($path, $siteId); |
||
219 | |||
220 | $this->assertGreaterThanOrEqual($count, count($nodes)); |
||
221 | } |
||
222 | |||
223 | /** |
||
224 | * @return array |
||
225 | */ |
||
226 | public function providePathSiteIdAndCount() |
||
227 | { |
||
228 | return array( |
||
229 | array('root', '2', 5), |
||
230 | array('root/fixture_page_community', '2', 0), |
||
231 | array('transverse', '2', 0), |
||
232 | ); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Tets find last version by type |
||
237 | */ |
||
238 | public function testFindLastVersionByType() |
||
239 | { |
||
240 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
241 | $nodes = $this->repository->findLastVersionByType('2'); |
||
242 | |||
243 | $this->assertSameNode('fr', $node->getVersion(), '2', $nodes[NodeInterface::ROOT_NODE_ID]); |
||
244 | } |
||
245 | |||
246 | /** |
||
247 | * @param string $language |
||
248 | * @param int $version |
||
249 | * @param string $siteId |
||
250 | * @param NodeInterface $node |
||
251 | * @param string $nodeId |
||
252 | */ |
||
253 | protected function assertSameNode($language, $version, $siteId, $node, $nodeId = NodeInterface::ROOT_NODE_ID) |
||
254 | { |
||
255 | $this->assertInstanceOf('OpenOrchestra\ModelInterface\Model\NodeInterface', $node); |
||
256 | $this->assertSame($nodeId, $node->getNodeId()); |
||
257 | $this->assertSame($language, $node->getLanguage()); |
||
258 | $this->assertSame($version, $node->getVersion()); |
||
259 | $this->assertSame($siteId, $node->getSiteId()); |
||
260 | $this->assertSame(false, $node->isDeleted()); |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @param string $siteId |
||
265 | * @param int $nodeNumber |
||
266 | * @param int $version |
||
267 | * @param string $language |
||
268 | * @param string|null $nodeId |
||
269 | * |
||
270 | * @dataProvider provideForGetFooter() |
||
271 | */ |
||
272 | View Code Duplication | public function testGetFooterTree($siteId, $nodeNumber, $version, $language = 'fr', $nodeId = null) |
|
273 | { |
||
274 | $nodes = $this->repository->getFooterTree($language, $siteId); |
||
275 | |||
276 | $this->assertCount($nodeNumber, $nodes); |
||
277 | 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...
|
|||
278 | $this->assertSameNode($language, $version, $siteId, $nodes[0], $nodeId); |
||
279 | $this->assertSame('published', $nodes[0]->getStatus()->getName()); |
||
280 | } |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * @return array |
||
285 | */ |
||
286 | public function provideForGetFooter() |
||
287 | { |
||
288 | return array( |
||
289 | array('2', 1, '1', 'fr', 'fixture_page_legal_mentions'), |
||
290 | array('2', 1, '1', 'en'), |
||
291 | array('2', 1, '1'), |
||
292 | ); |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @param string $siteId |
||
297 | * @param int $nodeNumber |
||
298 | * @param int $version |
||
299 | * @param string $language |
||
300 | * |
||
301 | * @dataProvider provideForGetMenu() |
||
302 | */ |
||
303 | View Code Duplication | public function testGetMenuTree($siteId, $nodeNumber, $version, $language = 'fr') |
|
304 | { |
||
305 | $nodes = $this->repository->getMenuTree($language, $siteId); |
||
306 | |||
307 | $this->assertCount($nodeNumber, $nodes); |
||
308 | $this->assertSameNode($language, $version, $siteId, $nodes[0]); |
||
309 | $this->assertSame('published', $nodes[0]->getStatus()->getName()); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @return array |
||
314 | */ |
||
315 | public function provideForGetMenu() |
||
316 | { |
||
317 | return array( |
||
318 | array('2', 4, '1', 'fr'), |
||
319 | array('2', 4, '1', 'en'), |
||
320 | ); |
||
321 | } |
||
322 | |||
323 | /** |
||
324 | * @param string $nodeId |
||
325 | * @param int $nbLevel |
||
326 | * @param int $nodeNumber |
||
327 | * @param int $version |
||
328 | * @param string $siteId |
||
329 | * @param string $local |
||
330 | * |
||
331 | * @dataProvider provideForGetSubMenu |
||
332 | */ |
||
333 | public function testGetSubMenu($nodeId, $nbLevel, $nodeNumber, $version, $siteId, $local) |
||
334 | { |
||
335 | $nodes = $this->repository->getSubMenu($nodeId, $nbLevel, $local, $siteId); |
||
336 | |||
337 | $this->assertCount($nodeNumber, $nodes); |
||
338 | if ($nodeNumber > 0) { |
||
339 | $this->assertSameNode($local, $version, $siteId, $nodes[0], $nodeId); |
||
340 | $this->assertSame('published', $nodes[0]->getStatus()->getName()); |
||
341 | } |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @return array |
||
346 | */ |
||
347 | public function provideForGetSubMenu() |
||
348 | { |
||
349 | return array( |
||
350 | array(NodeInterface::ROOT_NODE_ID, 1, 6, '1', '2', 'fr'), |
||
351 | array(NodeInterface::ROOT_NODE_ID, 2, 6, '1', '2', 'fr'), |
||
352 | array(NodeInterface::ROOT_NODE_ID, 0, 6, '1', '2', 'fr'), |
||
353 | array(NodeInterface::ROOT_NODE_ID, 0, 5, '1', '2', 'en'), |
||
354 | array('fixture_page_community', 1, 1, '1', '2', 'fr'), |
||
355 | array('fixture_page_community', 1, 1, '1', '2', 'en'), |
||
356 | array('page_unexistant', 1, 0, 1, '2', 'fr'), |
||
357 | ); |
||
358 | } |
||
359 | |||
360 | /** |
||
361 | * @param string $language |
||
362 | * @param string $siteId |
||
363 | * @param int $count |
||
364 | * |
||
365 | * @dataProvider provideLanguageSiteIdAndCount |
||
366 | */ |
||
367 | public function testFindPublishedByLanguageAndSiteId($language, $siteId, $count) |
||
368 | { |
||
369 | $nodes = $this->repository->findPublishedByLanguageAndSiteId($language, $siteId); |
||
370 | |||
371 | $this->assertCount($count, $nodes); |
||
372 | foreach ($nodes as $node) { |
||
373 | $this->assertSame($language, $node->getLanguage()); |
||
374 | } |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @return array |
||
379 | */ |
||
380 | View Code Duplication | public function provideLanguageSiteIdAndCount() |
|
381 | { |
||
382 | return array( |
||
383 | array('en', '2', 5), |
||
384 | array('fr', '2', 6), |
||
385 | ); |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @param string $user |
||
390 | * @param string $siteId |
||
391 | * @param array $eventTypes |
||
392 | * @param boolean|null $published |
||
393 | * @param int $limit |
||
394 | * @param array|null $sort |
||
395 | * @param int $count |
||
396 | * |
||
397 | * @dataProvider provideFindByHistoryAndSiteId |
||
398 | */ |
||
399 | View Code Duplication | public function testFindByHistoryAndSiteId($user, $siteId, array $eventTypes, $published, $limit, $sort, $count) |
|
400 | { |
||
401 | $user = $this->userRepository->findOneByUsername($user); |
||
402 | |||
403 | $this->assertCount( |
||
404 | $count, |
||
405 | $this->repository->findByHistoryAndSiteId($user->getId(), $siteId, $eventTypes, $published, $limit, $sort) |
||
406 | ); |
||
407 | } |
||
408 | |||
409 | /** |
||
410 | * @return array |
||
411 | */ |
||
412 | public function provideFindByHistoryAndSiteId() |
||
413 | { |
||
414 | return array( |
||
415 | array('p-admin', '2', array(NodeEvents::NODE_CREATION), null, 10, array('updatedAt' => -1), 0), |
||
416 | array('p-admin', '2', array(NodeEvents::NODE_CREATION), false, 10, null, 0), |
||
417 | array('p-admin', '2', array(NodeEvents::NODE_CREATION), true, 10, null, 0), |
||
418 | array('developer', '2', array(NodeEvents::NODE_UPDATE, NodeEvents::NODE_CREATION), false, 10, null, 1), |
||
419 | ); |
||
420 | } |
||
421 | |||
422 | /** |
||
423 | * @param string $nodeId |
||
424 | * @param string $language |
||
425 | * @param int $count |
||
426 | * |
||
427 | * @dataProvider provideFindPublishedSortedVersionData |
||
428 | */ |
||
429 | public function testFindPublishedSortedByVersion($nodeId, $language, $count) |
||
430 | { |
||
431 | $this->assertCount($count, $this->repository->findPublishedSortedByVersion($nodeId, $language, '2')); |
||
432 | } |
||
433 | |||
434 | /** |
||
435 | * @return array |
||
436 | */ |
||
437 | public function provideFindPublishedSortedVersionData() |
||
438 | { |
||
439 | return array( |
||
440 | array(NodeInterface::ROOT_NODE_ID, 'fr', 1), |
||
441 | array(NodeInterface::ROOT_NODE_ID, 'en', 1), |
||
442 | array('fixture_page_contact', 'en', 1), |
||
443 | ); |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @param string $language |
||
448 | * @apram int $expectedCount |
||
449 | * |
||
450 | * @dataProvider provideLanguage |
||
451 | */ |
||
452 | public function testFindSubTreeByPath($language, $expectedCount) |
||
453 | { |
||
454 | $nodes = $this->repository->findSubTreeByPath('root', '2', $language); |
||
455 | |||
456 | $this->assertCount($expectedCount, $nodes); |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @return array |
||
461 | */ |
||
462 | public function provideLanguage() |
||
463 | { |
||
464 | return array( |
||
465 | array('en', 4), |
||
466 | array('fr', 5), |
||
467 | ); |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * @param string $parentId |
||
472 | * @param string $routePattern |
||
473 | * @param string $nodeId |
||
474 | * |
||
475 | * @dataProvider provideParentRouteAndNodeId |
||
476 | */ |
||
477 | public function testFindByParentAndRoutePattern($parentId, $routePattern, $nodeId) |
||
478 | { |
||
479 | $this->assertEmpty($this->repository->findByParentAndRoutePattern($parentId, $routePattern, $nodeId, '2')); |
||
480 | } |
||
481 | |||
482 | /** |
||
483 | * @return array |
||
484 | */ |
||
485 | public function provideParentRouteAndNodeId() |
||
486 | { |
||
487 | return array( |
||
488 | array(NodeInterface::ROOT_NODE_ID, 'page-contact', 'fixture_page_contact'), |
||
489 | array(NodeInterface::ROOT_NODE_ID, 'mentions-legales', 'fixture_page_legal_mentions'), |
||
490 | ); |
||
491 | } |
||
492 | |||
493 | /** |
||
494 | * @param string $parentId |
||
495 | * @param int $order |
||
496 | * @param string $nodeId |
||
497 | * @param bool $expectedValue |
||
498 | * @param string $siteId |
||
499 | * |
||
500 | * @dataProvider provideParentAndOrder |
||
501 | */ |
||
502 | public function testHasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $expectedValue, $siteId = '2') |
||
503 | { |
||
504 | $this->assertSame($expectedValue, $this->repository->hasOtherNodeWithSameParentAndOrder($parentId, $order, $nodeId, $siteId)); |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * @return array |
||
509 | */ |
||
510 | public function provideParentAndOrder() |
||
511 | { |
||
512 | return array( |
||
513 | array(NodeInterface::ROOT_NODE_ID, 10, 'fixture_page_contact', true), |
||
514 | array(NodeInterface::ROOT_NODE_ID, 0, 'fixture_page_contact', false), |
||
515 | array('fixture_page_legal_mentions', 0, 'fakeID', false), |
||
516 | array(NodeInterface::ROOT_NODE_ID, 0, 'fakeID', false, '3'), |
||
517 | ); |
||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Test has statused element |
||
522 | */ |
||
523 | View Code Duplication | public function testHasStatusedElement() |
|
524 | { |
||
525 | $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
526 | $status = $statusRepository->findOneByInitial(); |
||
527 | |||
528 | $this->assertTrue($this->repository->hasStatusedElement($status)); |
||
529 | } |
||
530 | |||
531 | /** |
||
532 | * @return array |
||
533 | */ |
||
534 | public function provideNodeIdAndLanguageForPublishedFlag() |
||
535 | { |
||
536 | return array( |
||
537 | 'root in fr' => array(NodeInterface::ROOT_NODE_ID, 'fr'), |
||
538 | 'root in en' => array(NodeInterface::ROOT_NODE_ID, 'en'), |
||
539 | 'community in fr' => array('fixture_page_community', 'fr'), |
||
540 | 'community in en' => array('fixture_page_community', 'en'), |
||
541 | ); |
||
542 | } |
||
543 | |||
544 | /** |
||
545 | * @param string $siteId |
||
546 | * @param integer $expectedCount |
||
547 | * |
||
548 | * @dataProvider provideFindPublishedByType |
||
549 | */ |
||
550 | public function testFindPublishedByType($siteId, $expectedCount) |
||
551 | { |
||
552 | $this->assertCount($expectedCount, $this->repository->findPublishedByType($siteId)); |
||
553 | } |
||
554 | |||
555 | /** |
||
556 | * @return array |
||
557 | */ |
||
558 | public function provideFindPublishedByType() |
||
559 | { |
||
560 | return array( |
||
561 | array("1", 0), |
||
562 | array("2", 16), |
||
563 | ); |
||
564 | } |
||
565 | |||
566 | /** |
||
567 | * @param string $path |
||
568 | * @param string $siteId |
||
569 | * @param string $language |
||
570 | * @param integer $expectedCount |
||
571 | * |
||
572 | * @dataProvider provideFindPublishedByPathAndLanguage |
||
573 | */ |
||
574 | public function testFindPublishedByPathAndLanguage($path, $siteId, $language, $expectedCount) |
||
575 | { |
||
576 | $this->assertCount($expectedCount, $this->repository->findPublishedByPathAndLanguage($path, $siteId, $language)); |
||
577 | } |
||
578 | |||
579 | /** |
||
580 | * @return array |
||
581 | */ |
||
582 | View Code Duplication | public function provideFindPublishedByPathAndLanguage() |
|
583 | { |
||
584 | return array( |
||
585 | array("root", "2", "en", 5), |
||
586 | array("transverse", "2", "en", 0), |
||
587 | ); |
||
588 | } |
||
589 | |||
590 | /** |
||
591 | * @param string $path |
||
592 | * @param string $siteId |
||
593 | * @param string $language |
||
594 | * @param integer $expectedCount |
||
595 | * |
||
596 | * @dataProvider provideFindByIncludedPathSiteIdAndLanguage |
||
597 | */ |
||
598 | public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount) |
||
599 | { |
||
600 | $this->assertCount($expectedCount, $this->repository->findByIncludedPathSiteIdAndLanguage($path, $siteId, $language)); |
||
601 | } |
||
602 | |||
603 | /** |
||
604 | * @return array |
||
605 | */ |
||
606 | public function provideFindByIncludedPathSiteIdAndLanguage() |
||
607 | { |
||
608 | return array( |
||
609 | array("root", "2", "en", 6), |
||
610 | ); |
||
611 | } |
||
612 | |||
613 | /** |
||
614 | * test find tree node |
||
615 | */ |
||
616 | public function testFindTreeNode() |
||
617 | { |
||
618 | $tree = $this->repository->findTreeNode('2', 'fr', '-'); |
||
619 | |||
620 | $this->assertCount(3, $tree); |
||
621 | |||
622 | $nodeRootTree = $tree[0]; |
||
623 | $nodeRoot = $nodeRootTree['node']; |
||
624 | $this->assertCount(5, $nodeRootTree['child']); |
||
625 | $this->assertSame('root', $nodeRoot['nodeId']); |
||
626 | $childrenRoot = $nodeRootTree['child']; |
||
627 | $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish'); |
||
628 | foreach ($childrenRoot as $index => $child) { |
||
629 | $this->assertCount(0, $child['child']); |
||
630 | $this->assertSame($orderNodeId[$index], $child['node']['nodeId']); |
||
631 | } |
||
632 | |||
633 | $node404Tree = $tree[1]; |
||
634 | $node404 = $node404Tree['node']; |
||
635 | $this->assertCount(0, $node404Tree['child']); |
||
636 | $this->assertSame('errorPage404', $node404['nodeId']); |
||
637 | |||
638 | $node503Tree = $tree[2]; |
||
639 | $node503 = $node503Tree['node']; |
||
640 | $this->assertCount(0, $node503Tree['child']); |
||
641 | $this->assertSame('errorPage503', $node503['nodeId']); |
||
642 | } |
||
643 | |||
644 | /** |
||
645 | * @param string $siteId |
||
646 | * @param string $language |
||
647 | * @param int $count |
||
648 | * |
||
649 | * @dataProvider provideSiteIdAndLanguage |
||
650 | */ |
||
651 | public function testCount($siteId, $language, $count) |
||
652 | { |
||
653 | $this->assertEquals($count, $this->repository->count($siteId, $language)); |
||
654 | } |
||
655 | |||
656 | /** |
||
657 | * @return array |
||
658 | */ |
||
659 | public function provideSiteIdAndLanguage() |
||
660 | { |
||
661 | return array( |
||
662 | array('2', 'fr', 8), |
||
663 | array('2', 'en', 8), |
||
664 | array('2', 'de', 7), |
||
665 | array('3', 'fr', 1), |
||
666 | ); |
||
667 | } |
||
668 | |||
669 | /** |
||
670 | * @param PaginateFinderConfiguration $configuration |
||
671 | * @param string $siteId |
||
672 | * @param string $language |
||
673 | * @param int $count |
||
674 | * |
||
675 | * @dataProvider provideCountWithFilterPaginateConfiguration |
||
676 | */ |
||
677 | public function testCountWithFilter($configuration, $siteId, $language, $count) |
||
678 | { |
||
679 | $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language)); |
||
680 | } |
||
681 | |||
682 | /** |
||
683 | * @return array |
||
684 | */ |
||
685 | public function provideCountWithFilterPaginateConfiguration() |
||
686 | { |
||
687 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
688 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
689 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
690 | |||
691 | return array( |
||
692 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
693 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
694 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
695 | ); |
||
696 | } |
||
697 | |||
698 | /** |
||
699 | * @param PaginateFinderConfiguration $configuration |
||
700 | * @param string $siteId |
||
701 | * @param string $language |
||
702 | * @param int $count |
||
703 | * |
||
704 | * @dataProvider provideFindWithFilterPaginateConfiguration |
||
705 | */ |
||
706 | public function testFindForPaginate($configuration, $siteId, $language, $count) |
||
707 | { |
||
708 | $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language)); |
||
709 | } |
||
710 | |||
711 | /** |
||
712 | * @return array |
||
713 | */ |
||
714 | public function provideFindWithFilterPaginateConfiguration() |
||
715 | { |
||
716 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
717 | $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array()); |
||
718 | $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array()); |
||
719 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
720 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
721 | |||
722 | return array( |
||
723 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
724 | 'limit' => array($configurationLimit, '2', 'fr', 2), |
||
725 | 'skip' => array($configurationSkip, '2', 'fr', 6), |
||
726 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
727 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
728 | ); |
||
729 | } |
||
730 | |||
731 | /** |
||
732 | * Test update order of brothers |
||
733 | */ |
||
734 | public function testUpdateOrderOfBrothers() |
||
735 | { |
||
736 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
737 | $nodeNews = $this->repository->findOneByNodeId('fixture_page_news'); |
||
738 | $nodeCommunity = $this->repository->findOneByNodeId('fixture_page_community'); |
||
739 | $nodeContact= $this->repository->findOneByNodeId('fixture_page_contact'); |
||
740 | $dm->detach($nodeContact); |
||
741 | $dm->detach($nodeCommunity); |
||
742 | $dm->detach($nodeNews); |
||
743 | |||
744 | $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId()); |
||
745 | |||
746 | $nodeNewsAfterUpdate = $this->repository->findOneByNodeId('fixture_page_news'); |
||
747 | $nodeCommunityAfterUpdate = $this->repository->findOneByNodeId('fixture_page_community'); |
||
748 | $nodeContactAfterUpdate = $this->repository->findOneByNodeId('fixture_page_contact'); |
||
749 | |||
750 | $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder()); |
||
751 | $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder()); |
||
752 | $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder()); |
||
753 | |||
754 | } |
||
755 | |||
756 | /** |
||
757 | * Test remove block in area |
||
758 | */ |
||
759 | public function testRemoveBlockInArea() |
||
760 | { |
||
761 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
762 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
763 | $block = $node->getArea('main')->getBlocks()[0]; |
||
764 | $this->assertCount(2, $node->getArea('main')->getBlocks()); |
||
765 | |||
766 | $this->repository->removeBlockInArea($block->getId(), 'main', $node->getNodeId(), $node->getSiteId(), $node->getLanguage(), $node->getVersion()); |
||
767 | |||
768 | $dm->detach($node); |
||
769 | $dm->detach($block); |
||
770 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
771 | $blocks = $node->getArea('main')->getBlocks(); |
||
772 | $this->assertCount(1, $blocks); |
||
773 | |||
774 | $node->getArea('main')->addBlock($block); |
||
775 | $dm->persist($block); |
||
776 | $dm->flush(); |
||
777 | } |
||
778 | |||
779 | /** |
||
780 | * @param string $nodeId |
||
781 | * @param string $siteId |
||
782 | * @param string $areaId |
||
783 | * @param int $count |
||
784 | * |
||
785 | * @dataProvider provideFindByNodeIdAndSiteIdWithBlocksInArea |
||
786 | */ |
||
787 | public function testFindByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId, $count) |
||
788 | { |
||
789 | $nodes = $this->repository->findByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId); |
||
790 | $this->assertCount($count, $nodes); |
||
791 | } |
||
792 | |||
793 | /** |
||
794 | * @return array |
||
795 | */ |
||
796 | public function provideFindByNodeIdAndSiteIdWithBlocksInArea() |
||
797 | { |
||
798 | return array( |
||
799 | array('root', '2', 'main', 3), |
||
800 | array('root', 'fake', 'footer', 0), |
||
801 | ); |
||
802 | } |
||
803 | |||
804 | /** |
||
805 | * Test remove node version |
||
806 | */ |
||
807 | View Code Duplication | public function testRemoveVersion() |
|
808 | { |
||
809 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
810 | $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', '1'); |
||
811 | $storageIds = array($node->geTId()); |
||
812 | $dm->detach($node); |
||
813 | |||
814 | $this->repository->removeNodeVersions($storageIds); |
||
815 | $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', '1')); |
||
816 | |||
817 | $dm->persist($node); |
||
818 | $dm->flush(); |
||
819 | } |
||
820 | |||
821 | /** |
||
822 | * @param string $language |
||
823 | * @param string $siteId |
||
824 | * @param int $count |
||
825 | * |
||
826 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
827 | */ |
||
828 | public function testFindAllPublishedSpecialPage($language, $siteId, $count) |
||
829 | { |
||
830 | $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId); |
||
831 | $this->assertCount($count, $nodes); |
||
832 | } |
||
833 | |||
834 | /** |
||
835 | * @param string $language |
||
836 | * @param string $siteId |
||
837 | * @param int $count |
||
838 | * |
||
839 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
840 | */ |
||
841 | public function testFindAllSpecialPage($language, $siteId, $count) |
||
842 | { |
||
843 | $nodes = $this->repository->findAllSpecialPage($language, $siteId); |
||
844 | $this->assertCount($count, $nodes); |
||
845 | } |
||
846 | |||
847 | /** |
||
848 | * @return array |
||
849 | */ |
||
850 | public function provideLanguageAndSiteIdSpecialPage() |
||
851 | { |
||
852 | return array( |
||
853 | array('fr', '2', 1), |
||
854 | array('en', '2', 1), |
||
855 | array('de', '2', 1), |
||
856 | array('fr', '3', 0), |
||
857 | array('en', '3', 0), |
||
858 | array('de', '3', 0), |
||
859 | ); |
||
860 | } |
||
861 | |||
862 | /** |
||
863 | * @param string $nodeId |
||
864 | * @param string $language |
||
865 | * @param string $siteId |
||
866 | * @param string $name |
||
867 | * @param int $count |
||
868 | * |
||
869 | * @dataProvider provideCountOtherNodeWithSameSpecialPageName |
||
870 | */ |
||
871 | public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count) |
||
872 | { |
||
873 | $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name); |
||
874 | $this->assertSame($count, $nodesCount); |
||
875 | } |
||
876 | |||
877 | /** |
||
878 | * @return array |
||
879 | */ |
||
880 | public function provideCountOtherNodeWithSameSpecialPageName() |
||
881 | { |
||
882 | return array( |
||
883 | array('root', 'fr', '2', 'DEFAULT', 1), |
||
884 | array('root', 'en', '2', 'DEFAULT', 1), |
||
885 | array('root', 'de', '2', 'DEFAULT', 1), |
||
886 | array('root', 'fr', '2', 'FAKE', 0), |
||
887 | array('root', 'en', '2', 'FAKE', 0), |
||
888 | array('root', 'de', '2', 'FAKE', 0), |
||
889 | array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0), |
||
890 | array('fixture_page_contact', 'en', '2', 'DEFAULT', 0), |
||
891 | array('fixture_page_contact', 'de', '2', 'DEFAULT', 0), |
||
892 | ); |
||
893 | } |
||
894 | |||
895 | /** |
||
896 | * Test update use Reference |
||
897 | */ |
||
898 | public function testUpdateUseReference() |
||
899 | { |
||
900 | $nodeId = 'root'; |
||
901 | $siteId = '3'; |
||
902 | $entityType = NodeInterface::ENTITY_TYPE; |
||
903 | $referenceNodeId = 'fakeReferenceId'; |
||
904 | $this->repository->updateUseReference($referenceNodeId, $nodeId, $siteId, $entityType); |
||
905 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
906 | foreach ($nodes as $node) { |
||
907 | $this->assertTrue(array_key_exists($referenceNodeId, $node->getUseReferences($entityType))); |
||
908 | } |
||
909 | } |
||
910 | } |
||
911 |
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: