[TASK] Re-work/simplify copyright header in PHP files - Part 4
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Package / DependencyResolverTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Package;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Package\DependencyResolver;
18
19 /**
20 * Testcase for the dependency resolver class
21 *
22 * @author Markus Klein <klein.t3@mfc-linz.at>
23 */
24 class DependencyResolverTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
25
26 /**
27 * @test
28 * @param array $unsortedPackageStatesConfiguration
29 * @param array $frameworkPackageKeys
30 * @param array $expectedGraph
31 * @dataProvider buildDependencyGraphBuildsCorrectGraphDataProvider
32 */
33 public function buildDependencyGraphBuildsCorrectGraph(array $unsortedPackageStatesConfiguration, array $frameworkPackageKeys, array $expectedGraph) {
34 $packageKeys = array_keys($unsortedPackageStatesConfiguration);
35
36 $basePathAssignment = array(
37 array($unsortedPackageStatesConfiguration, '', array(DependencyResolver::SYSEXT_FOLDER), array_diff($packageKeys, $frameworkPackageKeys)),
38 array($unsortedPackageStatesConfiguration, DependencyResolver::SYSEXT_FOLDER, array(), $frameworkPackageKeys),
39 );
40
41 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('getPackageKeysInBasePath'));
42 $dependencyResolver->expects($this->any())->method('getPackageKeysInBasePath')->will($this->returnValueMap($basePathAssignment));
43 $dependencyGraph = $dependencyResolver->_call('buildDependencyGraph', $unsortedPackageStatesConfiguration);
44
45 $this->assertEquals($expectedGraph, $dependencyGraph);
46 }
47
48 /**
49 * @test
50 * @dataProvider packageSortingDataProvider
51 */
52 public function sortPackageStatesConfigurationByDependencyMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays($unsortedPackageStatesConfiguration, $frameworkPackageKeys, $expectedSortedPackageStatesConfiguration) {
53 $packageKeys = array_keys($unsortedPackageStatesConfiguration);
54
55 $basePathAssignment = array(
56 array($unsortedPackageStatesConfiguration, '', array(DependencyResolver::SYSEXT_FOLDER), array_diff($packageKeys, $frameworkPackageKeys)),
57 array($unsortedPackageStatesConfiguration, DependencyResolver::SYSEXT_FOLDER, array(), $frameworkPackageKeys),
58 );
59
60 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('getPackageKeysInBasePath'));
61 $dependencyResolver->expects($this->any())->method('getPackageKeysInBasePath')->will($this->returnValueMap($basePathAssignment));
62 $sortedPackageStatesConfiguration = $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
63
64 $this->assertEquals($expectedSortedPackageStatesConfiguration, $sortedPackageStatesConfiguration, 'The package states configurations have not been ordered according to their dependencies!');
65 }
66
67 /**
68 * @test
69 * @dataProvider buildDependencyGraphForPackagesBuildsCorrectGraphDataProvider
70 */
71 public function buildDependencyGraphForPackagesBuildsCorrectGraph($packages, $expectedGraph) {
72 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
73 $dependencyGraph = $dependencyResolver->_call('buildDependencyGraphForPackages', $packages, array_keys($packages));
74
75 $this->assertEquals($expectedGraph, $dependencyGraph);
76 }
77
78 /**
79 * @test
80 * @expectedException \UnexpectedValueException
81 */
82 public function sortPackageStatesConfigurationByDependencyThrowsExceptionWhenCycleDetected() {
83 $unsortedPackageStatesConfiguration = array(
84 'A' => array(
85 'state' => 'active',
86 'dependencies' => array('B'),
87 'packagePathStack' => array('foo')
88 ),
89 'B' => array(
90 'state' => 'active',
91 'dependencies' => array('A'),
92 'packagePathStack' => array('foo')
93 ),
94 );
95 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
96 $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
97 }
98
99 /**
100 * @test
101 * @expectedException \UnexpectedValueException
102 */
103 public function buildDependencyGraphForPackagesThrowsExceptionWhenDependencyOnUnavailablePackageDetected() {
104 $packages = array(
105 'A' => array(
106 'dependencies' => array('B'),
107 )
108 );
109 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
110 $dependencyResolver->_call('buildDependencyGraphForPackages', $packages, array_keys($packages));
111 }
112
113 /**
114 * @return array
115 */
116 public function buildDependencyGraphBuildsCorrectGraphDataProvider() {
117 return array(
118 'TYPO3 Flow Packages' => array(
119 array(
120 'TYPO3.Flow' => array(
121 'state' => 'active',
122 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
123 ),
124 'Doctrine.ORM' => array(
125 'state' => 'active',
126 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
127 ),
128 'Doctrine.Common' => array(
129 'state' => 'active',
130 'dependencies' => array()
131 ),
132 'Doctrine.DBAL' => array(
133 'state' => 'active',
134 'dependencies' => array('Doctrine.Common')
135 ),
136 'Symfony.Component.Yaml' => array(
137 'state' => 'active',
138 'dependencies' => array()
139 ),
140 ),
141 array(
142 'Doctrine.Common'
143 ),
144 array(
145 'TYPO3.Flow' => array(
146 'TYPO3.Flow' => FALSE,
147 'Doctrine.ORM' => TRUE,
148 'Doctrine.Common' => TRUE,
149 'Doctrine.DBAL' => TRUE,
150 'Symfony.Component.Yaml' => TRUE,
151 ),
152 'Doctrine.ORM' => array(
153 'TYPO3.Flow' => FALSE,
154 'Doctrine.ORM' => FALSE,
155 'Doctrine.Common' => TRUE,
156 'Doctrine.DBAL' => TRUE,
157 'Symfony.Component.Yaml' => FALSE,
158 ),
159 'Doctrine.Common' => array(
160 'TYPO3.Flow' => FALSE,
161 'Doctrine.ORM' => FALSE,
162 'Doctrine.Common' => FALSE,
163 'Doctrine.DBAL' => FALSE,
164 'Symfony.Component.Yaml' => FALSE,
165 ),
166 'Doctrine.DBAL' => array(
167 'TYPO3.Flow' => FALSE,
168 'Doctrine.ORM' => FALSE,
169 'Doctrine.Common' => TRUE,
170 'Doctrine.DBAL' => FALSE,
171 'Symfony.Component.Yaml' => FALSE,
172 ),
173 'Symfony.Component.Yaml' => array(
174 'TYPO3.Flow' => FALSE,
175 'Doctrine.ORM' => FALSE,
176 'Doctrine.Common' => TRUE,
177 'Doctrine.DBAL' => FALSE,
178 'Symfony.Component.Yaml' => FALSE,
179 ),
180 ),
181 ),
182 'TYPO3 CMS Extensions' => array(
183 array(
184 'core' => array(
185 'state' => 'active',
186 'dependencies' => array(),
187 ),
188 'setup' => array (
189 'state' => 'active',
190 'dependencies' => array('core'),
191 ),
192 'openid' => array(
193 'state' => 'active',
194 'dependencies' => array('core', 'setup')
195 ),
196 'news' => array (
197 'state' => 'active',
198 'dependencies' => array('extbase'),
199 ),
200 'extbase' => array (
201 'state' => 'active',
202 'dependencies' => array('core'),
203 ),
204 'pt_extbase' => array (
205 'state' => 'active',
206 'dependencies' => array('extbase'),
207 ),
208 'foo' => array (
209 'state' => 'active',
210 'dependencies' => array(),
211 ),
212 ),
213 array(
214 'core', 'setup', 'openid', 'extbase'
215 ),
216 array(
217 'core' => array(
218 'core' => FALSE,
219 'setup' => FALSE,
220 'openid' => FALSE,
221 'news' => FALSE,
222 'extbase' => FALSE,
223 'pt_extbase' => FALSE,
224 'foo' => FALSE
225 ),
226 'setup' => array(
227 'core' => TRUE,
228 'setup' => FALSE,
229 'openid' => FALSE,
230 'news' => FALSE,
231 'extbase' => FALSE,
232 'pt_extbase' => FALSE,
233 'foo' => FALSE
234 ),
235 'openid' => array (
236 'core' => TRUE,
237 'setup' => TRUE,
238 'openid' => FALSE,
239 'news' => FALSE,
240 'extbase' => FALSE,
241 'pt_extbase' => FALSE,
242 'foo' => FALSE
243 ),
244 'news' => array (
245 'core' => FALSE,
246 'setup' => FALSE,
247 'openid' => TRUE,
248 'news' => FALSE,
249 'extbase' => TRUE,
250 'pt_extbase' => FALSE,
251 'foo' => FALSE
252 ),
253 'extbase' => array (
254 'core' => TRUE,
255 'setup' => FALSE,
256 'openid' => FALSE,
257 'news' => FALSE,
258 'extbase' => FALSE,
259 'pt_extbase' => FALSE,
260 'foo' => FALSE
261 ),
262 'pt_extbase' => array(
263 'core' => FALSE,
264 'setup' => FALSE,
265 'openid' => TRUE,
266 'news' => FALSE,
267 'extbase' => TRUE,
268 'pt_extbase' => FALSE,
269 'foo' => FALSE
270 ),
271 'foo' => array(
272 'core' => FALSE,
273 'setup' => FALSE,
274 'openid' => TRUE,
275 'news' => FALSE,
276 'extbase' => TRUE,
277 'pt_extbase' => FALSE,
278 'foo' => FALSE
279 ),
280 ),
281 ),
282 'Dummy Packages' => array(
283 array(
284 'A' => array(
285 'state' => 'active',
286 'dependencies' => array('B', 'D', 'C'),
287 ),
288 'B' => array(
289 'state' => 'active',
290 'dependencies' => array()
291 ),
292 'C' => array(
293 'state' => 'active',
294 'dependencies' => array('E')
295 ),
296 'D' => array (
297 'state' => 'active',
298 'dependencies' => array('E'),
299 ),
300 'E' => array (
301 'state' => 'active',
302 'dependencies' => array(),
303 ),
304 'F' => array (
305 'state' => 'active',
306 'dependencies' => array(),
307 ),
308 ),
309 array(
310 'B', 'C', 'E'
311 ),
312 array(
313 'A' => array(
314 'A' => FALSE,
315 'B' => TRUE,
316 'C' => TRUE,
317 'D' => TRUE,
318 'E' => FALSE,
319 'F' => FALSE,
320 ),
321 'B' => array(
322 'A' => FALSE,
323 'B' => FALSE,
324 'C' => FALSE,
325 'D' => FALSE,
326 'E' => FALSE,
327 'F' => FALSE,
328 ),
329 'C' => array(
330 'A' => FALSE,
331 'B' => FALSE,
332 'C' => FALSE,
333 'D' => FALSE,
334 'E' => TRUE,
335 'F' => FALSE,
336 ),
337 'D' => array (
338 'A' => FALSE,
339 'B' => TRUE,
340 'C' => TRUE,
341 'D' => FALSE,
342 'E' => FALSE,
343 'F' => FALSE,
344 ),
345 'E' => array (
346 'A' => FALSE,
347 'B' => FALSE,
348 'C' => FALSE,
349 'D' => FALSE,
350 'E' => FALSE,
351 'F' => FALSE,
352 ),
353 'F' => array (
354 'A' => FALSE,
355 'B' => TRUE,
356 'C' => TRUE,
357 'D' => FALSE,
358 'E' => FALSE,
359 'F' => FALSE,
360 ),
361 ),
362 ),
363 );
364 }
365
366 /**
367 * @return array
368 */
369 public function packageSortingDataProvider() {
370 return array(
371 'TYPO3 Flow Packages' => array(
372 array(
373 'TYPO3.Flow' => array(
374 'state' => 'active',
375 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
376 ),
377 'Doctrine.ORM' => array(
378 'state' => 'active',
379 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
380 ),
381 'Doctrine.Common' => array(
382 'state' => 'active',
383 'dependencies' => array()
384 ),
385 'Doctrine.DBAL' => array(
386 'state' => 'active',
387 'dependencies' => array('Doctrine.Common')
388 ),
389 'Symfony.Component.Yaml' => array(
390 'state' => 'active',
391 'dependencies' => array()
392 ),
393 ),
394 array(
395 'Doctrine.Common'
396 ),
397 array(
398 'Doctrine.Common' => array(
399 'state' => 'active',
400 'dependencies' => array()
401 ),
402 'Doctrine.DBAL' => array(
403 'state' => 'active',
404 'dependencies' => array('Doctrine.Common')
405 ),
406 'Doctrine.ORM' => array(
407 'state' => 'active',
408 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
409 ),
410 'Symfony.Component.Yaml' => array(
411 'state' => 'active',
412 'dependencies' => array()
413 ),
414 'TYPO3.Flow' => array(
415 'state' => 'active',
416 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
417 ),
418 ),
419 ),
420 'TYPO3 CMS Extensions' => array(
421 array(
422 'core' => array(
423 'state' => 'active',
424 'dependencies' => array(),
425 ),
426 'setup' => array (
427 'state' => 'active',
428 'dependencies' => array('core'),
429 ),
430 'openid' => array(
431 'state' => 'active',
432 'dependencies' => array('core', 'setup')
433 ),
434 'news' => array (
435 'state' => 'active',
436 'dependencies' => array('extbase'),
437 ),
438 'extbase' => array (
439 'state' => 'active',
440 'dependencies' => array('core'),
441 ),
442 'pt_extbase' => array (
443 'state' => 'active',
444 'dependencies' => array('extbase'),
445 ),
446 'foo' => array (
447 'state' => 'active',
448 'dependencies' => array(),
449 ),
450 ),
451 array(
452 'core', 'setup', 'openid', 'extbase'
453 ),
454 array(
455 'core' => array(
456 'state' => 'active',
457 'dependencies' => array(),
458 ),
459 'setup' => array (
460 'state' => 'active',
461 'dependencies' => array('core'),
462 ),
463 'openid' => array(
464 'state' => 'active',
465 'dependencies' => array('core', 'setup')
466 ),
467 'extbase' => array (
468 'state' => 'active',
469 'dependencies' => array('core'),
470 ),
471 'foo' => array (
472 'state' => 'active',
473 'dependencies' => array(),
474 ),
475 'pt_extbase' => array (
476 'state' => 'active',
477 'dependencies' => array('extbase'),
478 ),
479 'news' => array (
480 'state' => 'active',
481 'dependencies' => array('extbase'),
482 ),
483 ),
484 ),
485 'Dummy Packages' => array(
486 array(
487 'A' => array(
488 'state' => 'active',
489 'dependencies' => array('B', 'D', 'C'),
490 ),
491 'B' => array(
492 'state' => 'active',
493 'dependencies' => array()
494 ),
495 'C' => array(
496 'state' => 'active',
497 'dependencies' => array('E')
498 ),
499 'D' => array (
500 'state' => 'active',
501 'dependencies' => array('E'),
502 ),
503 'E' => array (
504 'state' => 'active',
505 'dependencies' => array(),
506 ),
507 'F' => array (
508 'state' => 'active',
509 'dependencies' => array(),
510 ),
511 ),
512 array(
513 'B', 'C', 'E'
514 ),
515 array(
516 'B' => array(
517 'state' => 'active',
518 'dependencies' => array(),
519 ),
520 'E' => array (
521 'state' => 'active',
522 'dependencies' => array(),
523 ),
524 'C' => array (
525 'state' => 'active',
526 'dependencies' => array('E'),
527 ),
528 'F' => array (
529 'state' => 'active',
530 'dependencies' => array(),
531 ),
532 'D' => array(
533 'state' => 'active',
534 'dependencies' => array('E'),
535 ),
536 'A' => array(
537 'state' => 'active',
538 'dependencies' => array('B', 'D', 'C'),
539 ),
540 ),
541 ),
542 );
543 }
544
545 /**
546 * @return array
547 */
548 public function buildDependencyGraphForPackagesBuildsCorrectGraphDataProvider() {
549 return array(
550 'TYPO3 Flow Packages' => array(
551 array(
552 'TYPO3.Flow' => array(
553 'state' => 'active',
554 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
555 ),
556 'Doctrine.ORM' => array(
557 'state' => 'active',
558 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
559 ),
560 'Doctrine.Common' => array(
561 'state' => 'active',
562 'dependencies' => array()
563 ),
564 'Doctrine.DBAL' => array(
565 'state' => 'active',
566 'dependencies' => array('Doctrine.Common')
567 ),
568 'Symfony.Component.Yaml' => array(
569 'state' => 'active',
570 'dependencies' => array()
571 ),
572 ),
573 array(
574 'TYPO3.Flow' => array(
575 'TYPO3.Flow' => FALSE,
576 'Doctrine.ORM' => TRUE,
577 'Doctrine.Common' => TRUE,
578 'Doctrine.DBAL' => TRUE,
579 'Symfony.Component.Yaml' => TRUE,
580 ),
581 'Doctrine.ORM' => array(
582 'TYPO3.Flow' => FALSE,
583 'Doctrine.ORM' => FALSE,
584 'Doctrine.Common' => TRUE,
585 'Doctrine.DBAL' => TRUE,
586 'Symfony.Component.Yaml' => FALSE,
587 ),
588 'Doctrine.Common' => array(
589 'TYPO3.Flow' => FALSE,
590 'Doctrine.ORM' => FALSE,
591 'Doctrine.Common' => FALSE,
592 'Doctrine.DBAL' => FALSE,
593 'Symfony.Component.Yaml' => FALSE,
594 ),
595 'Doctrine.DBAL' => array(
596 'TYPO3.Flow' => FALSE,
597 'Doctrine.ORM' => FALSE,
598 'Doctrine.Common' => TRUE,
599 'Doctrine.DBAL' => FALSE,
600 'Symfony.Component.Yaml' => FALSE,
601 ),
602 'Symfony.Component.Yaml' => array(
603 'TYPO3.Flow' => FALSE,
604 'Doctrine.ORM' => FALSE,
605 'Doctrine.Common' => FALSE,
606 'Doctrine.DBAL' => FALSE,
607 'Symfony.Component.Yaml' => FALSE,
608 ),
609 ),
610 ),
611 'TYPO3 CMS Extensions' => array(
612 array(
613 'core' => array(
614 'state' => 'active',
615 'dependencies' => array(),
616 ),
617 'openid' => array(
618 'state' => 'active',
619 'dependencies' => array('core', 'setup')
620 ),
621 'scheduler' => array (
622 'state' => 'active',
623 'dependencies' => array('core'),
624 ),
625 'setup' => array (
626 'state' => 'active',
627 'dependencies' => array('core'),
628 ),
629 'sv' => array (
630 'state' => 'active',
631 'dependencies' => array('core'),
632 ),
633 ),
634 array(
635 'core' => array(
636 'core' => FALSE,
637 'setup' => FALSE,
638 'sv' => FALSE,
639 'scheduler' => FALSE,
640 'openid' => FALSE,
641 ),
642 'openid' => array(
643 'core' => TRUE,
644 'setup' => TRUE,
645 'sv' => FALSE,
646 'scheduler' => FALSE,
647 'openid' => FALSE,
648 ),
649 'scheduler' => array (
650 'core' => TRUE,
651 'setup' => FALSE,
652 'sv' => FALSE,
653 'scheduler' => FALSE,
654 'openid' => FALSE,
655 ),
656 'setup' => array (
657 'core' => TRUE,
658 'setup' => FALSE,
659 'sv' => FALSE,
660 'scheduler' => FALSE,
661 'openid' => FALSE,
662 ),
663 'sv' => array (
664 'core' => TRUE,
665 'setup' => FALSE,
666 'sv' => FALSE,
667 'scheduler' => FALSE,
668 'openid' => FALSE,
669 ),
670 ),
671 ),
672 'Dummy Packages' => array(
673 array(
674 'A' => array(
675 'state' => 'active',
676 'dependencies' => array('B', 'D', 'C'),
677 ),
678 'B' => array(
679 'state' => 'active',
680 'dependencies' => array()
681 ),
682 'C' => array(
683 'state' => 'active',
684 'dependencies' => array('E')
685 ),
686 'D' => array (
687 'state' => 'active',
688 'dependencies' => array('E'),
689 ),
690 'E' => array (
691 'state' => 'active',
692 'dependencies' => array(),
693 ),
694 'F' => array (
695 'state' => 'active',
696 'dependencies' => array(),
697 ),
698 ),
699 array(
700 'A' => array(
701 'A' => FALSE,
702 'B' => TRUE,
703 'C' => TRUE,
704 'D' => TRUE,
705 'E' => FALSE,
706 'F' => FALSE,
707 ),
708 'B' => array(
709 'A' => FALSE,
710 'B' => FALSE,
711 'C' => FALSE,
712 'D' => FALSE,
713 'E' => FALSE,
714 'F' => FALSE,
715 ),
716 'C' => array(
717 'A' => FALSE,
718 'B' => FALSE,
719 'C' => FALSE,
720 'D' => FALSE,
721 'E' => TRUE,
722 'F' => FALSE,
723 ),
724 'D' => array (
725 'A' => FALSE,
726 'B' => FALSE,
727 'C' => FALSE,
728 'D' => FALSE,
729 'E' => TRUE,
730 'F' => FALSE,
731 ),
732 'E' => array (
733 'A' => FALSE,
734 'B' => FALSE,
735 'C' => FALSE,
736 'D' => FALSE,
737 'E' => FALSE,
738 'F' => FALSE,
739 ),
740 'F' => array (
741 'A' => FALSE,
742 'B' => FALSE,
743 'C' => FALSE,
744 'D' => FALSE,
745 'E' => FALSE,
746 'F' => FALSE,
747 ),
748 ),
749 ),
750 'Suggestions without reverse dependency' => array(
751 array(
752 'A' => array(
753 'state' => 'active',
754 'suggestions' => array('B'),
755 ),
756 'B' => array(
757 'state' => 'active',
758 ),
759 'C' => array(
760 'state' => 'active',
761 'dependencies' => array('A')
762 ),
763 ),
764 array(
765 'A' => array(
766 'A' => FALSE,
767 'B' => TRUE,
768 'C' => FALSE,
769 ),
770 'B' => array(
771 'A' => FALSE,
772 'B' => FALSE,
773 'C' => FALSE,
774 ),
775 'C' => array(
776 'A' => TRUE,
777 'B' => FALSE,
778 'C' => FALSE,
779 ),
780 ),
781 ),
782 'Suggestions with reverse dependency' => array(
783 array(
784 'A' => array(
785 'state' => 'active',
786 'suggestions' => array('B'),
787 ),
788 'B' => array(
789 'state' => 'active',
790 'dependencies' => array('A')
791 ),
792 'C' => array(
793 'state' => 'active',
794 'dependencies' => array('A')
795 ),
796 ),
797 array(
798 'A' => array(
799 'A' => FALSE,
800 'B' => FALSE,
801 'C' => FALSE,
802 ),
803 'B' => array(
804 'A' => TRUE,
805 'B' => FALSE,
806 'C' => FALSE,
807 ),
808 'C' => array(
809 'A' => TRUE,
810 'B' => FALSE,
811 'C' => FALSE,
812 ),
813 ),
814 ),
815 );
816 }
817
818 /**
819 * @return array
820 */
821 public function findPathInGraphReturnsCorrectPathDataProvider() {
822 return array(
823 'Simple path' => array(
824 array(
825 'A' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => TRUE),
826 'B' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE),
827 'C' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE),
828 'Z' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE)
829 ),
830 'A', 'Z',
831 array('A', 'Z')
832 ),
833 'No path' => array(
834 array(
835 'A' => array('A' => FALSE, 'B' => TRUE, 'C' => FALSE, 'Z' => FALSE),
836 'B' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE),
837 'C' => array('A' => FALSE, 'B' => TRUE, 'C' => FALSE, 'Z' => FALSE),
838 'Z' => array('A' => FALSE, 'B' => TRUE, 'C' => FALSE, 'Z' => FALSE)
839 ),
840 'A', 'C',
841 array()
842 ),
843 'Longer path' => array(
844 array(
845 'A' => array('A' => FALSE, 'B' => TRUE, 'C' => TRUE, 'Z' => TRUE),
846 'B' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE),
847 'C' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => TRUE),
848 'Z' => array('A' => FALSE, 'B' => FALSE, 'C' => FALSE, 'Z' => FALSE)
849 ),
850 'A', 'Z',
851 array('A', 'C', 'Z')
852 ),
853 );
854 }
855
856 /**
857 * @param array $graph
858 * @param string $from
859 * @param string $to
860 * @param array $expected
861 * @test
862 * @dataProvider findPathInGraphReturnsCorrectPathDataProvider
863 */
864 public function findPathInGraphReturnsCorrectPath(array $graph, $from, $to, array $expected) {
865 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
866 $path = $dependencyResolver->_call('findPathInGraph', $graph, $from, $to);
867
868 $this->assertSame($expected, $path);
869 }
870
871 /**
872 * Data provider for getPackageKeysInBasePathReturnsCorrectKeys
873 * @return array
874 */
875 public function getPackageKeysInBasePathReturnsCorrectKeysDataProvider() {
876 return array(
877 'Single paths only, include all' => array(
878 array(
879 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
880 'key2' => array('packagePathStack' => array('somewhereelse')),
881 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
882 ),
883 '',
884 array(),
885 array('key1', 'key2', 'key3')
886 ),
887 'Single paths only, include sysext' => array(
888 array(
889 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
890 'key2' => array('packagePathStack' => array('somewhereelse')),
891 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
892 ),
893 DependencyResolver::SYSEXT_FOLDER,
894 array(),
895 array('key1', 'key3')
896 ),
897 'Single paths only, exclude sysext' => array(
898 array(
899 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
900 'key2' => array('packagePathStack' => array('somewhereelse')),
901 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
902 ),
903 '',
904 array(DependencyResolver::SYSEXT_FOLDER),
905 array('key2')
906 ),
907 'Multiple paths, include sysext' => array(
908 array(
909 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
910 'key2' => array('packagePathStack' => array('somewhereelse')),
911 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
912 ),
913 DependencyResolver::SYSEXT_FOLDER,
914 array(),
915 array('key1', 'key3')
916 ),
917 'Multiple paths, exclude sysext' => array(
918 array(
919 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
920 'key2' => array('packagePathStack' => array('somewhereelse')),
921 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
922 'key4' => array('packagePathStack' => array('elsewhere')),
923 ),
924 '',
925 array(DependencyResolver::SYSEXT_FOLDER),
926 array('key2', 'key4')
927 ),
928 'Multiple paths, include somewhereelse' => array(
929 array(
930 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
931 'key2' => array('packagePathStack' => array('somewhereelse')),
932 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
933 ),
934 'somewhereelse',
935 array(),
936 array('key1', 'key2')
937 ),
938 'Multiple paths, include somewhereelse, exclude sysext' => array(
939 array(
940 'key1' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER, 'somewhereelse')),
941 'key2' => array('packagePathStack' => array('somewhereelse')),
942 'key3' => array('packagePathStack' => array(DependencyResolver::SYSEXT_FOLDER)),
943 'key4' => array('packagePathStack' => array('elsewhere')),
944 ),
945 'somewhereelse',
946 array(DependencyResolver::SYSEXT_FOLDER),
947 array('key2')
948 ),
949 );
950 }
951
952 /**
953 * @test
954 * @dataProvider getPackageKeysInBasePathReturnsCorrectKeysDataProvider
955 */
956 public function getPackageKeysInBasePathReturnsCorrectKeys(array $packageStates, $include, array $exclude, array $expectedKeys) {
957 $dependencyResolver = $this->getAccessibleMock('\TYPO3\CMS\Core\Package\DependencyResolver', array('dummy'));
958 $keys = $dependencyResolver->_call('getPackageKeysInBasePath', $packageStates, $include, $exclude);
959 $this->assertSame($expectedKeys, $keys);
960 }
961 }