[TASK] Only show active packages in PackageStates.php
[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 use TYPO3\CMS\Core\Service\DependencyOrderingService;
19 use TYPO3\CMS\Core\Tests\UnitTestCase;
20
21 /**
22 * Test case
23 */
24 class DependencyResolverTest extends 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 {
35 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $dependencyResolver */
36 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, array('findFrameworkPackages'));
37 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
38 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
39 $dependencyGraph = $dependencyResolver->_call('buildDependencyGraph', $unsortedPackageStatesConfiguration);
40
41 $this->assertEquals($expectedGraph, $dependencyGraph);
42 }
43
44 /**
45 * @test
46 * @dataProvider packageSortingDataProvider
47 * @param array $unsortedPackageStatesConfiguration
48 * @param array $frameworkPackageKeys
49 * @param array $expectedSortedPackageStatesConfiguration
50 */
51 public function sortPackageStatesConfigurationByDependencyMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays($unsortedPackageStatesConfiguration, $frameworkPackageKeys, $expectedSortedPackageKeys)
52 {
53 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $dependencyResolver */
54 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, array('findFrameworkPackages'));
55 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
56 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn($frameworkPackageKeys);
57 $sortedPackageKeys = $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
58
59 $this->assertEquals($expectedSortedPackageKeys, $sortedPackageKeys, 'The package states configurations have not been ordered according to their dependencies!');
60 }
61
62 /**
63 * @test
64 * @expectedException \UnexpectedValueException
65 */
66 public function sortPackageStatesConfigurationByDependencyThrowsExceptionWhenCycleDetected()
67 {
68 $unsortedPackageStatesConfiguration = array(
69 'A' => array(
70 'dependencies' => array('B'),
71 ),
72 'B' => array(
73 'dependencies' => array('A')
74 ),
75 );
76
77 /** @var DependencyResolver|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface $dependencyResolver */
78 $dependencyResolver = $this->getAccessibleMock(DependencyResolver::class, array('findFrameworkPackages'));
79 $dependencyResolver->injectDependencyOrderingService(new DependencyOrderingService());
80 $dependencyResolver->expects($this->any())->method('findFrameworkPackages')->willReturn(array());
81 $dependencyResolver->_call('sortPackageStatesConfigurationByDependency', $unsortedPackageStatesConfiguration);
82 }
83
84 /**
85 * @return array
86 */
87 public function buildDependencyGraphBuildsCorrectGraphDataProvider()
88 {
89 return array(
90 'TYPO3 Flow Packages' => array(
91 array(
92 'TYPO3.Flow' => array(
93 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
94 ),
95 'Doctrine.ORM' => array(
96 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
97 ),
98 'Doctrine.Common' => array(
99 'dependencies' => array()
100 ),
101 'Doctrine.DBAL' => array(
102 'dependencies' => array('Doctrine.Common')
103 ),
104 'Symfony.Component.Yaml' => array(
105 'dependencies' => array()
106 ),
107 ),
108 array(
109 'Doctrine.Common'
110 ),
111 array(
112 'TYPO3.Flow' => array(
113 'TYPO3.Flow' => false,
114 'Doctrine.ORM' => true,
115 'Doctrine.Common' => true,
116 'Doctrine.DBAL' => true,
117 'Symfony.Component.Yaml' => true,
118 ),
119 'Doctrine.ORM' => array(
120 'TYPO3.Flow' => false,
121 'Doctrine.ORM' => false,
122 'Doctrine.Common' => true,
123 'Doctrine.DBAL' => true,
124 'Symfony.Component.Yaml' => false,
125 ),
126 'Doctrine.Common' => array(
127 'TYPO3.Flow' => false,
128 'Doctrine.ORM' => false,
129 'Doctrine.Common' => false,
130 'Doctrine.DBAL' => false,
131 'Symfony.Component.Yaml' => false,
132 ),
133 'Doctrine.DBAL' => array(
134 'TYPO3.Flow' => false,
135 'Doctrine.ORM' => false,
136 'Doctrine.Common' => true,
137 'Doctrine.DBAL' => false,
138 'Symfony.Component.Yaml' => false,
139 ),
140 'Symfony.Component.Yaml' => array(
141 'TYPO3.Flow' => false,
142 'Doctrine.ORM' => false,
143 'Doctrine.Common' => true,
144 'Doctrine.DBAL' => false,
145 'Symfony.Component.Yaml' => false,
146 ),
147 ),
148 ),
149 'TYPO3 CMS Extensions' => array(
150 array(
151 'core' => array(
152 'dependencies' => array(),
153 ),
154 'setup' => array(
155 'dependencies' => array('core'),
156 ),
157 'openid' => array(
158 'dependencies' => array('core', 'setup')
159 ),
160 'news' => array(
161 'dependencies' => array('extbase'),
162 ),
163 'extbase' => array(
164 'dependencies' => array('core'),
165 ),
166 'pt_extbase' => array(
167 'dependencies' => array('extbase'),
168 ),
169 'foo' => array(
170 'dependencies' => array(),
171 ),
172 ),
173 array(
174 'core', 'setup', 'openid', 'extbase'
175 ),
176 array(
177 'core' => array(
178 'core' => false,
179 'setup' => false,
180 'openid' => false,
181 'news' => false,
182 'extbase' => false,
183 'pt_extbase' => false,
184 'foo' => false
185 ),
186 'setup' => array(
187 'core' => true,
188 'setup' => false,
189 'openid' => false,
190 'news' => false,
191 'extbase' => false,
192 'pt_extbase' => false,
193 'foo' => false
194 ),
195 'openid' => array(
196 'core' => true,
197 'setup' => true,
198 'openid' => false,
199 'news' => false,
200 'extbase' => false,
201 'pt_extbase' => false,
202 'foo' => false
203 ),
204 'news' => array(
205 'core' => false,
206 'setup' => false,
207 'openid' => true,
208 'news' => false,
209 'extbase' => true,
210 'pt_extbase' => false,
211 'foo' => false
212 ),
213 'extbase' => array(
214 'core' => true,
215 'setup' => false,
216 'openid' => false,
217 'news' => false,
218 'extbase' => false,
219 'pt_extbase' => false,
220 'foo' => false
221 ),
222 'pt_extbase' => array(
223 'core' => false,
224 'setup' => false,
225 'openid' => true,
226 'news' => false,
227 'extbase' => true,
228 'pt_extbase' => false,
229 'foo' => false
230 ),
231 'foo' => array(
232 'core' => false,
233 'setup' => false,
234 'openid' => true,
235 'news' => false,
236 'extbase' => true,
237 'pt_extbase' => false,
238 'foo' => false
239 ),
240 ),
241 ),
242 'Dummy Packages' => array(
243 array(
244 'A' => array(
245 'dependencies' => array('B', 'D', 'C'),
246 ),
247 'B' => array(
248 'dependencies' => array()
249 ),
250 'C' => array(
251 'dependencies' => array('E')
252 ),
253 'D' => array(
254 'dependencies' => array('E'),
255 ),
256 'E' => array(
257 'dependencies' => array(),
258 ),
259 'F' => array(
260 'dependencies' => array(),
261 ),
262 ),
263 array(
264 'B', 'C', 'E'
265 ),
266 array(
267 'A' => array(
268 'A' => false,
269 'B' => true,
270 'C' => true,
271 'D' => true,
272 'E' => false,
273 'F' => false,
274 ),
275 'B' => array(
276 'A' => false,
277 'B' => false,
278 'C' => false,
279 'D' => false,
280 'E' => false,
281 'F' => false,
282 ),
283 'C' => array(
284 'A' => false,
285 'B' => false,
286 'C' => false,
287 'D' => false,
288 'E' => true,
289 'F' => false,
290 ),
291 'D' => array(
292 'A' => false,
293 'B' => true,
294 'C' => true,
295 'D' => false,
296 'E' => false,
297 'F' => false,
298 ),
299 'E' => array(
300 'A' => false,
301 'B' => false,
302 'C' => false,
303 'D' => false,
304 'E' => false,
305 'F' => false,
306 ),
307 'F' => array(
308 'A' => false,
309 'B' => true,
310 'C' => true,
311 'D' => false,
312 'E' => false,
313 'F' => false,
314 ),
315 ),
316 ),
317 );
318 }
319
320 /**
321 * @return array
322 */
323 public function packageSortingDataProvider()
324 {
325 return array(
326 'TYPO3 Flow Packages' => array(
327 array(
328 'TYPO3.Flow' => array(
329 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
330 ),
331 'Doctrine.ORM' => array(
332 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
333 ),
334 'Doctrine.Common' => array(
335 'dependencies' => array()
336 ),
337 'Doctrine.DBAL' => array(
338 'dependencies' => array('Doctrine.Common')
339 ),
340 'Symfony.Component.Yaml' => array(
341 'dependencies' => array()
342 ),
343 ),
344 array(
345 'Doctrine.Common'
346 ),
347 array(
348 'Doctrine.Common',
349 'Doctrine.DBAL',
350 'Doctrine.ORM',
351 'Symfony.Component.Yaml',
352 'TYPO3.Flow',
353 ),
354 ),
355 'TYPO3 CMS Extensions' => array(
356 array(
357 'core' => array(
358 'dependencies' => array(),
359 ),
360 'setup' => array(
361 'dependencies' => array('core'),
362 ),
363 'openid' => array(
364 'dependencies' => array('core', 'setup')
365 ),
366 'news' => array(
367 'dependencies' => array('extbase'),
368 ),
369 'extbase' => array(
370 'dependencies' => array('core'),
371 ),
372 'pt_extbase' => array(
373 'dependencies' => array('extbase'),
374 ),
375 'foo' => array(
376 'dependencies' => array(),
377 ),
378 ),
379 array(
380 'core', 'setup', 'openid', 'extbase'
381 ),
382 array(
383 'core',
384 'setup',
385 'openid',
386 'extbase',
387 'foo',
388 'news',
389 'pt_extbase',
390 ),
391 ),
392 'Dummy Packages' => array(
393 array(
394 'A' => array(
395 'dependencies' => array('B', 'D', 'C'),
396 ),
397 'B' => array(
398 'dependencies' => array()
399 ),
400 'C' => array(
401 'dependencies' => array('E')
402 ),
403 'D' => array(
404 'dependencies' => array('E'),
405 ),
406 'E' => array(
407 'dependencies' => array(),
408 ),
409 'F' => array(
410 'dependencies' => array(),
411 ),
412 ),
413 array(
414 'B', 'C', 'E'
415 ),
416 array(
417 'E',
418 'C',
419 'B',
420 'D',
421 'A',
422 'F',
423 ),
424 ),
425 );
426 }
427 }