This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
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 | View Code Duplication | 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 | View Code Duplication | 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 | View Code Duplication | public function provideNodeLanguageLastVersionAndSiteId() |
|
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++) { |
||
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) |
|
247 | { |
||
248 | $nodes = $this->repository->getFooterTree($language, $siteId); |
||
249 | |||
250 | $this->assertCount($nodeNumber, $nodes); |
||
251 | if ($nodeId) { |
||
0 ignored issues
–
show
|
|||
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() |
|
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() |
|
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() |
|
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) |
|
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() |
|
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() |
|
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 integer $expectedCount |
||
568 | * |
||
569 | * @dataProvider provideFindByPath |
||
570 | */ |
||
571 | public function testFindByPath($path, $siteId, $expectedCount) |
||
572 | { |
||
573 | $this->assertCount($expectedCount, $this->repository->findNodeIdByIncludedPathSiteId($path, $siteId)); |
||
574 | } |
||
575 | |||
576 | /** |
||
577 | * @return array |
||
578 | */ |
||
579 | View Code Duplication | public function provideFindByPath() |
|
580 | { |
||
581 | return array( |
||
582 | array("root", "2", 23), |
||
583 | array("transverse", "2", 0), |
||
584 | ); |
||
585 | } |
||
586 | |||
587 | /** |
||
588 | * @param string $path |
||
589 | * @param string $siteId |
||
590 | * @param string $language |
||
591 | * @param integer $expectedCount |
||
592 | * |
||
593 | * @dataProvider provideFindByIncludedPathSiteIdAndLanguage |
||
594 | */ |
||
595 | public function testFindByIncludedPathSiteIdAndLanguage($path, $siteId, $language, $expectedCount) |
||
596 | { |
||
597 | $this->assertCount($expectedCount, $this->repository->findNodeIdByIncludedPathSiteIdAndLanguage($path, $siteId, $language)); |
||
598 | } |
||
599 | |||
600 | /** |
||
601 | * @return array |
||
602 | */ |
||
603 | public function provideFindByIncludedPathSiteIdAndLanguage() |
||
604 | { |
||
605 | return array( |
||
606 | array("root", "2", "en", 6), |
||
607 | ); |
||
608 | } |
||
609 | |||
610 | /** |
||
611 | * Test find all router pattern |
||
612 | */ |
||
613 | public function testFindAllRoutePattern() |
||
614 | { |
||
615 | $routePatterns = $this->repository->findAllRoutePattern( 'fr', '2'); |
||
616 | $this->assertCount(12, $routePatterns); |
||
617 | |||
618 | $routePattern = $routePatterns[0]; |
||
619 | $this->assertArrayHasKey('routePattern', $routePattern); |
||
620 | $this->assertArrayHasKey('nodeId', $routePattern); |
||
621 | $this->assertArrayHasKey('parentId', $routePattern); |
||
622 | } |
||
623 | |||
624 | /** |
||
625 | * test find tree node |
||
626 | */ |
||
627 | public function testFindTreeNode() |
||
628 | { |
||
629 | $tree = $this->repository->findTreeNode('2', 'fr', '-'); |
||
630 | |||
631 | $this->assertCount(3, $tree); |
||
632 | |||
633 | $nodeRootTree = $tree[0]; |
||
634 | $nodeRoot = $nodeRootTree['node']; |
||
635 | $this->assertCount(5, $nodeRootTree['child']); |
||
636 | $this->assertSame('root', $nodeRoot['nodeId']); |
||
637 | $childrenRoot = $nodeRootTree['child']; |
||
638 | $orderNodeId = array('fixture_page_community', 'fixture_page_news', 'fixture_page_contact', 'fixture_page_legal_mentions', 'fixture_auto_unpublish'); |
||
639 | foreach ($childrenRoot as $index => $child) { |
||
640 | $this->assertCount(0, $child['child']); |
||
641 | $this->assertSame($orderNodeId[$index], $child['node']['nodeId']); |
||
642 | } |
||
643 | |||
644 | $node404Tree = $tree[1]; |
||
645 | $node404 = $node404Tree['node']; |
||
646 | $this->assertCount(0, $node404Tree['child']); |
||
647 | $this->assertSame('errorPage404', $node404['nodeId']); |
||
648 | |||
649 | $node503Tree = $tree[2]; |
||
650 | $node503 = $node503Tree['node']; |
||
651 | $this->assertCount(0, $node503Tree['child']); |
||
652 | $this->assertSame('errorPage503', $node503['nodeId']); |
||
653 | } |
||
654 | |||
655 | /** |
||
656 | * @param string $siteId |
||
657 | * @param string $language |
||
658 | * @param int $count |
||
659 | * |
||
660 | * @dataProvider provideSiteIdAndLanguage |
||
661 | */ |
||
662 | public function testCount($siteId, $language, $count) |
||
663 | { |
||
664 | $this->assertEquals($count, $this->repository->count($siteId, $language)); |
||
665 | } |
||
666 | |||
667 | /** |
||
668 | * @return array |
||
669 | */ |
||
670 | View Code Duplication | public function provideSiteIdAndLanguage() |
|
671 | { |
||
672 | return array( |
||
673 | array('2', 'fr', 8), |
||
674 | array('2', 'en', 8), |
||
675 | array('2', 'de', 7), |
||
676 | array('3', 'fr', 1), |
||
677 | ); |
||
678 | } |
||
679 | |||
680 | /** |
||
681 | * @param PaginateFinderConfiguration $configuration |
||
682 | * @param string $siteId |
||
683 | * @param string $language |
||
684 | * @param int $count |
||
685 | * |
||
686 | * @dataProvider provideCountWithFilterPaginateConfiguration |
||
687 | */ |
||
688 | public function testCountWithFilter($configuration, $siteId, $language, $count) |
||
689 | { |
||
690 | $this->assertEquals($count, $this->repository->countWithFilter($configuration, $siteId, $language)); |
||
691 | } |
||
692 | |||
693 | /** |
||
694 | * @return array |
||
695 | */ |
||
696 | public function provideCountWithFilterPaginateConfiguration() |
||
697 | { |
||
698 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
699 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
700 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
701 | |||
702 | return array( |
||
703 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
704 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
705 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
706 | ); |
||
707 | } |
||
708 | |||
709 | /** |
||
710 | * @param PaginateFinderConfiguration $configuration |
||
711 | * @param string $siteId |
||
712 | * @param string $language |
||
713 | * @param int $count |
||
714 | * |
||
715 | * @dataProvider provideFindWithFilterPaginateConfiguration |
||
716 | */ |
||
717 | public function testFindForPaginate($configuration, $siteId, $language, $count) |
||
718 | { |
||
719 | $this->assertCount($count, $this->repository->findForPaginate($configuration, $siteId, $language)); |
||
720 | } |
||
721 | |||
722 | /** |
||
723 | * @return array |
||
724 | */ |
||
725 | public function provideFindWithFilterPaginateConfiguration() |
||
726 | { |
||
727 | $configurationAllPaginate = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array()); |
||
728 | $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 2, array()); |
||
729 | $configurationSkip = PaginateFinderConfiguration::generateFromVariable(array(), 2, 100, array()); |
||
730 | $configurationOrder = PaginateFinderConfiguration::generateFromVariable(array('updated_at' => 'desc'), 0, 100, array('updated_at' => 'updatedAt')); |
||
731 | $configurationFilter = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('name' => 'orchestra')); |
||
732 | |||
733 | return array( |
||
734 | 'all' => array($configurationAllPaginate, '2', 'fr', 8), |
||
735 | 'limit' => array($configurationLimit, '2', 'fr', 2), |
||
736 | 'skip' => array($configurationSkip, '2', 'fr', 6), |
||
737 | 'order' => array($configurationOrder, '2', 'fr', 8), |
||
738 | 'filter' => array($configurationFilter, '2', 'fr', 1), |
||
739 | ); |
||
740 | } |
||
741 | |||
742 | /** |
||
743 | * Test update order of brothers |
||
744 | */ |
||
745 | public function testUpdateOrderOfBrothers() |
||
746 | { |
||
747 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
748 | $nodeNews = $this->repository->findOneByNodeAndSite('fixture_page_news', '2'); |
||
749 | $nodeCommunity = $this->repository->findOneByNodeAndSite('fixture_page_community', '2'); |
||
750 | $nodeContact= $this->repository->findOneByNodeAndSite('fixture_page_contact', '2'); |
||
751 | $dm->detach($nodeContact); |
||
752 | $dm->detach($nodeCommunity); |
||
753 | $dm->detach($nodeNews); |
||
754 | |||
755 | $this->repository->updateOrderOfBrothers($nodeNews->getSiteId(), $nodeNews->getNodeId(), $nodeNews->getOrder(), $nodeNews->getParentId()); |
||
756 | |||
757 | $nodeNewsAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_news', '2'); |
||
758 | $nodeCommunityAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_community', '2'); |
||
759 | $nodeContactAfterUpdate = $this->repository->findOneByNodeAndSite('fixture_page_contact', '2'); |
||
760 | |||
761 | $this->assertSame($nodeNews->getOrder(), $nodeNewsAfterUpdate->getOrder()); |
||
762 | $this->assertSame($nodeCommunity->getOrder(), $nodeCommunityAfterUpdate->getOrder()); |
||
763 | $this->assertSame($nodeContact->getOrder() + 1, $nodeContactAfterUpdate->getOrder()); |
||
764 | |||
765 | } |
||
766 | |||
767 | /** |
||
768 | * Test remove block in area |
||
769 | */ |
||
770 | public function testRemoveBlockInArea() |
||
771 | { |
||
772 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
773 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
774 | $block = $node->getArea('main')->getBlocks()[0]; |
||
775 | $this->assertCount(2, $node->getArea('main')->getBlocks()); |
||
776 | |||
777 | $this->repository->removeBlockInArea($block->getId(), 'main', $node->getNodeId(), $node->getSiteId(), $node->getLanguage(), $node->getVersion()); |
||
778 | |||
779 | $dm->detach($node); |
||
780 | $dm->detach($block); |
||
781 | $node = $this->repository->findInLastVersion('root', 'fr', '2'); |
||
782 | $blocks = $node->getArea('main')->getBlocks(); |
||
783 | $this->assertCount(1, $blocks); |
||
784 | |||
785 | $node->getArea('main')->addBlock($block); |
||
786 | $dm->persist($block); |
||
787 | $dm->flush(); |
||
788 | } |
||
789 | |||
790 | /** |
||
791 | * @param string $nodeId |
||
792 | * @param string $siteId |
||
793 | * @param string $areaId |
||
794 | * @param int $count |
||
795 | * |
||
796 | * @dataProvider provideFindByNodeIdAndSiteIdWithBlocksInArea |
||
797 | */ |
||
798 | public function testFindByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId, $count) |
||
799 | { |
||
800 | $nodes = $this->repository->findByNodeIdAndSiteIdWithBlocksInArea($nodeId, $siteId, $areaId); |
||
801 | $this->assertCount($count, $nodes); |
||
802 | } |
||
803 | |||
804 | /** |
||
805 | * @return array |
||
806 | */ |
||
807 | public function provideFindByNodeIdAndSiteIdWithBlocksInArea() |
||
808 | { |
||
809 | return array( |
||
810 | array('root', '2', 'main', 3), |
||
811 | array('root', 'fake', 'footer', 0), |
||
812 | ); |
||
813 | } |
||
814 | |||
815 | /** |
||
816 | * Test remove node version |
||
817 | */ |
||
818 | View Code Duplication | public function testRemoveVersion() |
|
819 | { |
||
820 | $dm = static::$kernel->getContainer()->get('object_manager'); |
||
821 | $node = $this->repository->findVersionNotDeleted('root', 'fr', '2', '1'); |
||
822 | $storageIds = array($node->geTId()); |
||
823 | $dm->detach($node); |
||
824 | |||
825 | $this->repository->removeNodeVersions($storageIds); |
||
826 | $this->assertNull($this->repository->findVersionNotDeleted('root', 'fr', '2', '1')); |
||
827 | |||
828 | $dm->persist($node); |
||
829 | $dm->flush(); |
||
830 | } |
||
831 | |||
832 | /** |
||
833 | * @param string $language |
||
834 | * @param string $siteId |
||
835 | * @param int $count |
||
836 | * |
||
837 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
838 | */ |
||
839 | public function testFindAllPublishedSpecialPage($language, $siteId, $count) |
||
840 | { |
||
841 | $nodes = $this->repository->findAllPublishedSpecialPage($language, $siteId); |
||
842 | $this->assertCount($count, $nodes); |
||
843 | } |
||
844 | |||
845 | /** |
||
846 | * @param string $language |
||
847 | * @param string $siteId |
||
848 | * @param int $count |
||
849 | * |
||
850 | * @dataProvider provideLanguageAndSiteIdSpecialPage |
||
851 | */ |
||
852 | public function testFindAllSpecialPage($language, $siteId, $count) |
||
853 | { |
||
854 | $nodes = $this->repository->findAllSpecialPage($language, $siteId); |
||
855 | $this->assertCount($count, $nodes); |
||
856 | } |
||
857 | |||
858 | /** |
||
859 | * @return array |
||
860 | */ |
||
861 | public function provideLanguageAndSiteIdSpecialPage() |
||
862 | { |
||
863 | return array( |
||
864 | array('fr', '2', 1), |
||
865 | array('en', '2', 1), |
||
866 | array('de', '2', 1), |
||
867 | array('fr', '3', 0), |
||
868 | array('en', '3', 0), |
||
869 | array('de', '3', 0), |
||
870 | ); |
||
871 | } |
||
872 | |||
873 | /** |
||
874 | * @param string $nodeId |
||
875 | * @param string $language |
||
876 | * @param string $siteId |
||
877 | * @param string $name |
||
878 | * @param int $count |
||
879 | * |
||
880 | * @dataProvider provideCountOtherNodeWithSameSpecialPageName |
||
881 | */ |
||
882 | public function testCountOtherNodeWithSameSpecialPageName($nodeId, $language, $siteId, $name, $count) |
||
883 | { |
||
884 | $nodesCount = $this->repository->countOtherNodeWithSameSpecialPageName($nodeId, $siteId, $language, $name); |
||
885 | $this->assertSame($count, $nodesCount); |
||
886 | } |
||
887 | |||
888 | /** |
||
889 | * @return array |
||
890 | */ |
||
891 | public function provideCountOtherNodeWithSameSpecialPageName() |
||
892 | { |
||
893 | return array( |
||
894 | array('root', 'fr', '2', 'DEFAULT', 1), |
||
895 | array('root', 'en', '2', 'DEFAULT', 1), |
||
896 | array('root', 'de', '2', 'DEFAULT', 1), |
||
897 | array('root', 'fr', '2', 'FAKE', 0), |
||
898 | array('root', 'en', '2', 'FAKE', 0), |
||
899 | array('root', 'de', '2', 'FAKE', 0), |
||
900 | array('fixture_page_contact', 'fr', '2', 'DEFAULT', 0), |
||
901 | array('fixture_page_contact', 'en', '2', 'DEFAULT', 0), |
||
902 | array('fixture_page_contact', 'de', '2', 'DEFAULT', 0), |
||
903 | ); |
||
904 | } |
||
905 | |||
906 | /** |
||
907 | * Test update use Reference |
||
908 | */ |
||
909 | public function testUpdateUseReference() |
||
910 | { |
||
911 | $nodeId = 'root'; |
||
912 | $siteId = '3'; |
||
913 | $entityType = NodeInterface::ENTITY_TYPE; |
||
914 | $referenceNodeId = 'fakeReferenceId'; |
||
915 | $this->repository->updateUseReference($referenceNodeId, $nodeId, $siteId, $entityType); |
||
916 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
917 | foreach ($nodes as $node) { |
||
918 | $this->assertTrue(array_key_exists($referenceNodeId, $node->getUseReferences($entityType))); |
||
919 | } |
||
920 | } |
||
921 | |||
922 | /** |
||
923 | * Test soft delete node |
||
924 | */ |
||
925 | public function testSoftDeleteAndRestoreNode() |
||
926 | { |
||
927 | $nodeId = 'root'; |
||
928 | $siteId = '2'; |
||
929 | |||
930 | $this->repository->softDeleteNode($nodeId, $siteId); |
||
931 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
932 | foreach ($nodes as $node) { |
||
933 | $this->assertTrue($node->isDeleted()); |
||
934 | } |
||
935 | $this->repository->restoreDeletedNode($nodeId, $siteId); |
||
936 | |||
937 | $documentManager = static::$kernel->getContainer()->get('object_manager'); |
||
938 | $documentManager->clear(); |
||
939 | $documentManager->close(); |
||
940 | |||
941 | $nodes = $this->repository->findByNodeAndSite($nodeId, $siteId); |
||
942 | foreach ($nodes as $node) { |
||
943 | $this->assertFalse($node->isDeleted()); |
||
944 | } |
||
945 | } |
||
946 | |||
947 | /** |
||
948 | * @param string $nodeId |
||
949 | * @param string $siteId |
||
950 | * @param bool $has |
||
951 | * |
||
952 | * @dataProvider provideNodeNotOffline |
||
953 | */ |
||
954 | public function testHasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId, $has) |
||
955 | { |
||
956 | $this->assertSame($has, $this->repository->hasNodeIdWithoutAutoUnpublishToState($nodeId, $siteId)); |
||
957 | } |
||
958 | |||
959 | /** |
||
960 | * @return array |
||
961 | */ |
||
962 | public function provideNodeNotOffline() |
||
963 | { |
||
964 | return array( |
||
965 | array('root', '2', true), |
||
966 | array('fixture_page_contact', '2', true) |
||
967 | ); |
||
968 | } |
||
969 | |||
970 | /** |
||
971 | * @param string $parentId |
||
972 | * @param string $siteId |
||
973 | * @param int $count |
||
974 | * |
||
975 | * @dataProvider provideCountByParentId |
||
976 | */ |
||
977 | public function testCountByParentId($parentId, $siteId, $count) |
||
978 | { |
||
979 | $this->assertEquals($count, $this->repository->countByParentId($parentId, $siteId)); |
||
980 | } |
||
981 | |||
982 | /** |
||
983 | * @return array |
||
984 | */ |
||
985 | View Code Duplication | public function provideCountByParentId() |
|
986 | { |
||
987 | return array( |
||
988 | array('fixture_page_contact', '2', 0), |
||
989 | array('root', '2', 15) |
||
990 | ); |
||
991 | } |
||
992 | |||
993 | /** |
||
994 | * @param string $nodeId |
||
995 | * @param string $siteId |
||
996 | * @param int $count |
||
997 | * |
||
998 | * @dataProvider provideCountById |
||
999 | */ |
||
1000 | public function testCountById($nodeId, $siteId, $count) |
||
1001 | { |
||
1002 | $this->assertEquals($count, $this->repository->countById($nodeId, $siteId)); |
||
1003 | } |
||
1004 | |||
1005 | /** |
||
1006 | * @return array |
||
1007 | */ |
||
1008 | View Code Duplication | public function provideCountById() |
|
1009 | { |
||
1010 | return array( |
||
1011 | array('fixture_page_contact', '2', 3), |
||
1012 | array('root', '2', 5) |
||
1013 | ); |
||
1014 | } |
||
1015 | |||
1016 | /** |
||
1017 | * Test update embedded status |
||
1018 | */ |
||
1019 | View Code Duplication | public function testUpdateEmbeddedStatus() |
|
1020 | { |
||
1021 | $statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status'); |
||
1022 | $status = $statusRepository->findOneByName('published'); |
||
1023 | $fakeColor = 'fakeColor'; |
||
1024 | $saveColor = $status->getDisplayColor(); |
||
1025 | $status->setDisplayColor($fakeColor); |
||
1026 | $this->repository->updateEmbeddedStatus($status); |
||
1027 | |||
1028 | $node = $this->repository->findOnePublished('root', 'fr', '2'); |
||
1029 | $this->assertEquals($fakeColor, $node->getStatus()->getDisplayColor()); |
||
1030 | |||
1031 | $status->setDisplayColor($saveColor); |
||
1032 | $this->repository->updateEmbeddedStatus($status); |
||
1033 | } |
||
1034 | |||
1035 | /** |
||
1036 | * Test findLastVersionByLanguage |
||
1037 | * @param string $siteId |
||
1038 | * @param string $language |
||
1039 | * @param int $count |
||
1040 | * |
||
1041 | * @dataProvider provideSiteAndLanguage |
||
1042 | */ |
||
1043 | public function testFindLastVersionByLanguage($siteId, $language, $count) |
||
1044 | { |
||
1045 | $nodes = $this->repository->findLastVersionByLanguage($siteId, $language); |
||
1046 | |||
1047 | $this->assertEquals($count, count($nodes)); |
||
1048 | } |
||
1049 | |||
1050 | /** |
||
1051 | * @return array |
||
1052 | */ |
||
1053 | View Code Duplication | public function provideSiteAndLanguage() |
|
1054 | { |
||
1055 | return array( |
||
1056 | array('2', 'fr', 8), |
||
1057 | array('2', 'en', 8), |
||
1058 | array('2', 'es', 0), |
||
1059 | array('3', 'fr', 1), |
||
1060 | ); |
||
1061 | } |
||
1062 | |||
1063 | } |
||
1064 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
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: