[FEATURE] Integrate preliminary PackageManager API
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Package / PackageManagerTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Package;
3
4 /* *
5 * This script belongs to the TYPO3 Flow framework. *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13
14 use TYPO3\Flow\Package\PackageInterface;
15 use org\bovigo\vfs\vfsStream;
16
17 /**
18 * Testcase for the default package manager
19 *
20 */
21 class PackageManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
22
23 /**
24 * @var \TYPO3\Flow\Package\PackageManager
25 */
26 protected $packageManager;
27
28 /**
29 * Sets up this test case
30 *
31 */
32 protected function setUp() {
33 vfsStream::setup('Test');
34 $mockBootstrap = $this->getMock('TYPO3\CMS\Core\Core\Bootstrap', array(), array(), '', FALSE);
35 $mockCache = $this->getMock('TYPO3\CMS\Core\Cache\Frontend\PhpFrontend', array('has', 'set', 'getBackend'), array(), '', FALSE);
36 $mockCacheBackend = $this->getMock('TYPO3\CMS\Core\Cache\Backend\SimpleFileBackend', array('has', 'set', 'getBackend'), array(), '', FALSE);
37 $mockCache->expects($this->any())->method('has')->will($this->returnValue(FALSE));
38 $mockCache->expects($this->any())->method('set')->will($this->returnValue(TRUE));
39 $mockCache->expects($this->any())->method('getBackend')->will($this->returnValue($mockCacheBackend));
40 $mockCacheBackend->expects($this->any())->method('getCacheDirectory')->will($this->returnValue('vfs://Test/Cache'));
41 $this->packageManager = new \TYPO3\CMS\Core\Package\PackageManager();
42
43 mkdir('vfs://Test/Packages/Application', 0700, TRUE);
44 mkdir('vfs://Test/Configuration');
45 file_put_contents('vfs://Test/Configuration/PackageStates.php', "<?php return array ('packages' => array(), 'version' => 4); ");
46
47 $mockClassLoader = $this->getMock('TYPO3\CMS\Core\Core\ClassLoader');
48 $mockClassLoader->expects($this->any())->method('setCacheIdentifier')->will($this->returnSelf());
49
50 $composerNameToPackageKeyMap = array(
51 'typo3/flow' => 'TYPO3.Flow'
52 );
53
54 $this->packageManager->injectClassLoader($mockClassLoader);
55 $this->packageManager->injectCoreCache($mockCache);
56 $this->inject($this->packageManager, 'composerNameToPackageKeyMap', $composerNameToPackageKeyMap);
57 $this->packageManager->initialize($mockBootstrap, 'vfs://Test/Packages/', 'vfs://Test/Configuration/PackageStates.php');
58 }
59
60 /**
61 * @test
62 */
63 public function getPackageReturnsTheSpecifiedPackage() {
64 $this->packageManager->createPackage('TYPO3.Flow');
65
66 $package = $this->packageManager->getPackage('TYPO3.Flow');
67 $this->assertInstanceOf('TYPO3\Flow\Package\PackageInterface', $package, 'The result of getPackage() was no valid package object.');
68 }
69
70 /**
71 * @test
72 * @expectedException \TYPO3\Flow\Package\Exception\UnknownPackageException
73 */
74 public function getPackageThrowsExceptionOnUnknownPackage() {
75 $this->packageManager->getPackage('PrettyUnlikelyThatThisPackageExists');
76 }
77
78 /**
79 * @test
80 */
81 public function getCaseSensitivePackageKeyReturnsTheUpperCamelCaseVersionOfAGivenPackageKeyIfThePackageIsRegistered() {
82 $packageManager = $this->getAccessibleMock('TYPO3\Flow\Package\PackageManager', array('dummy'));
83 $packageManager->_set('packageKeys', array('acme.testpackage' => 'Acme.TestPackage'));
84 $this->assertEquals('Acme.TestPackage', $packageManager->getCaseSensitivePackageKey('acme.testpackage'));
85 }
86
87 /**
88 * @test
89 */
90 public function scanAvailablePackagesTraversesThePackagesDirectoryAndRegistersPackagesItFinds() {
91 $expectedPackageKeys = array(
92 'TYPO3.Flow' . md5(uniqid(mt_rand(), TRUE)),
93 'TYPO3.Flow.Test' . md5(uniqid(mt_rand(), TRUE)),
94 'TYPO3.YetAnotherTestPackage' . md5(uniqid(mt_rand(), TRUE)),
95 'RobertLemke.Flow.NothingElse' . md5(uniqid(mt_rand(), TRUE))
96 );
97
98 foreach ($expectedPackageKeys as $packageKey) {
99 $packagePath = 'vfs://Test/Packages/Application/' . $packageKey . '/';
100
101 mkdir($packagePath, 0770, TRUE);
102 mkdir($packagePath . 'Classes');
103 file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
104 }
105
106 $packageManager = $this->getAccessibleMock('TYPO3\Flow\Package\PackageManager', array('dummy'));
107 $packageManager->_set('packagesBasePath', 'vfs://Test/Packages/');
108 $packageManager->_set('packageStatesPathAndFilename', 'vfs://Test/Configuration/PackageStates.php');
109
110 $packageFactory = new \TYPO3\Flow\Package\PackageFactory($packageManager);
111 $this->inject($packageManager, 'packageFactory', $packageFactory);
112
113 $packageManager->_set('packages', array());
114 $packageManager->_call('scanAvailablePackages');
115
116 $packageStates = require('vfs://Test/Configuration/PackageStates.php');
117 $actualPackageKeys = array_keys($packageStates['packages']);
118 $this->assertEquals(sort($expectedPackageKeys), sort($actualPackageKeys));
119 }
120
121 /**
122 * @test
123 */
124 public function scanAvailablePackagesKeepsExistingPackageConfiguration() {
125 $expectedPackageKeys = array(
126 'TYPO3.Flow' . md5(uniqid(mt_rand(), TRUE)),
127 'TYPO3.Flow.Test' . md5(uniqid(mt_rand(), TRUE)),
128 'TYPO3.YetAnotherTestPackage' . md5(uniqid(mt_rand(), TRUE)),
129 'RobertLemke.Flow.NothingElse' . md5(uniqid(mt_rand(), TRUE))
130 );
131
132 foreach ($expectedPackageKeys as $packageKey) {
133 $packagePath = 'vfs://Test/Packages/Application/' . $packageKey . '/';
134
135 mkdir($packagePath, 0770, TRUE);
136 mkdir($packagePath . 'Classes');
137 file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
138 }
139
140 $packageManager = $this->getAccessibleMock('TYPO3\Flow\Package\PackageManager', array('dummy'));
141 $packageManager->_set('packagesBasePath', 'vfs://Test/Packages/');
142 $packageManager->_set('packageStatesPathAndFilename', 'vfs://Test/Configuration/PackageStates.php');
143
144 $packageFactory = new \TYPO3\Flow\Package\PackageFactory($packageManager);
145 $this->inject($packageManager, 'packageFactory', $packageFactory);
146
147 $packageManager->_set('packageStatesConfiguration', array(
148 'packages' => array(
149 $packageKey => array(
150 'state' => 'inactive',
151 'frozen' => FALSE,
152 'packagePath' => 'Application/' . $packageKey . '/',
153 'classesPath' => 'Classes/'
154 )
155 ),
156 'version' => 2
157 ));
158 $packageManager->_call('scanAvailablePackages');
159 $packageManager->_call('sortAndsavePackageStates');
160
161 $packageStates = require('vfs://Test/Configuration/PackageStates.php');
162 $this->assertEquals('inactive', $packageStates['packages'][$packageKey]['state']);
163 }
164
165
166 /**
167 * @test
168 */
169 public function packageStatesConfigurationContainsRelativePaths() {
170 $packageKeys = array(
171 'RobertLemke.Flow.NothingElse' . md5(uniqid(mt_rand(), TRUE)),
172 'TYPO3.Flow' . md5(uniqid(mt_rand(), TRUE)),
173 'TYPO3.YetAnotherTestPackage' . md5(uniqid(mt_rand(), TRUE)),
174 );
175
176 foreach ($packageKeys as $packageKey) {
177 $packagePath = 'vfs://Test/Packages/Application/' . $packageKey . '/';
178
179 mkdir($packagePath, 0770, TRUE);
180 mkdir($packagePath . 'Classes');
181 file_put_contents($packagePath . 'composer.json', '{"name": "' . $packageKey . '", "type": "flow-test"}');
182 }
183
184 $packageManager = $this->getAccessibleMock('TYPO3\Flow\Package\PackageManager', array('updateShortcuts'), array(), '', FALSE);
185 $packageManager->_set('packagesBasePath', 'vfs://Test/Packages/');
186 $packageManager->_set('packageStatesPathAndFilename', 'vfs://Test/Configuration/PackageStates.php');
187
188 $packageFactory = new \TYPO3\Flow\Package\PackageFactory($packageManager);
189 $this->inject($packageManager, 'packageFactory', $packageFactory);
190
191 $packageManager->_set('packages', array());
192 $packageManager->_call('scanAvailablePackages');
193
194 $expectedPackageStatesConfiguration = array();
195 foreach ($packageKeys as $packageKey) {
196 $expectedPackageStatesConfiguration[$packageKey] = array(
197 'state' => 'active',
198 'packagePath' => 'Application/' . $packageKey . '/',
199 'classesPath' => 'Classes/',
200 'manifestPath' => '',
201 'composerName' => $packageKey
202 );
203 }
204
205 $actualPackageStatesConfiguration = $packageManager->_get('packageStatesConfiguration');
206 $this->assertEquals($expectedPackageStatesConfiguration, $actualPackageStatesConfiguration['packages']);
207 }
208
209 /**
210 * Data Provider returning valid package keys and the corresponding path
211 *
212 * @return array
213 */
214 public function packageKeysAndPaths() {
215 return array(
216 array('TYPO3.YetAnotherTestPackage', 'vfs://Test/Packages/Application/TYPO3.YetAnotherTestPackage/'),
217 array('RobertLemke.Flow.NothingElse', 'vfs://Test/Packages/Application/RobertLemke.Flow.NothingElse/')
218 );
219 }
220
221 /**
222 * @test
223 * @dataProvider packageKeysAndPaths
224 */
225 public function createPackageCreatesPackageFolderAndReturnsPackage($packageKey, $expectedPackagePath) {
226 $actualPackage = $this->packageManager->createPackage($packageKey);
227 $actualPackagePath = $actualPackage->getPackagePath();
228
229 $this->assertEquals($expectedPackagePath, $actualPackagePath);
230 $this->assertTrue(is_dir($actualPackagePath), 'Package path should exist after createPackage()');
231 $this->assertEquals($packageKey, $actualPackage->getPackageKey());
232 $this->assertTrue($this->packageManager->isPackageAvailable($packageKey));
233 }
234
235 /**
236 * @test
237 */
238 public function createPackageWritesAComposerManifestUsingTheGivenMetaObject() {
239 $metaData = new \TYPO3\Flow\Package\MetaData('Acme.YetAnotherTestPackage');
240 $metaData->setDescription('Yet Another Test Package');
241
242 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage', $metaData);
243
244 $json = file_get_contents($package->getPackagePath() . '/composer.json');
245 $composerManifest = json_decode($json);
246
247 $this->assertEquals('acme/yetanothertestpackage', $composerManifest->name);
248 $this->assertEquals('Yet Another Test Package', $composerManifest->description);
249 }
250
251 /**
252 * @test
253 */
254 public function createPackageCanChangePackageTypeInComposerManifest() {
255 $metaData = new \TYPO3\Flow\Package\MetaData('Acme.YetAnotherTestPackage2');
256 $metaData->setDescription('Yet Another Test Package');
257 $metaData->setPackageType('flow-custom-package');
258
259 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage2', $metaData);
260
261 $json = file_get_contents($package->getPackagePath() . '/composer.json');
262 $composerManifest = json_decode($json);
263
264 $this->assertEquals('flow-custom-package', $composerManifest->type);
265 }
266
267 /**
268 * Checks if createPackage() creates the folders for classes, configuration, documentation, resources and tests.
269 *
270 * @test
271 */
272 public function createPackageCreatesCommonFolders() {
273 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
274 $packagePath = $package->getPackagePath();
275
276 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_CLASSES), "Classes directory was not created");
277 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_CONFIGURATION), "Configuration directory was not created");
278 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_DOCUMENTATION), "Documentation directory was not created");
279 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_RESOURCES), "Resources directory was not created");
280 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_TESTS_UNIT), "Tests/Unit directory was not created");
281 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_TESTS_FUNCTIONAL), "Tests/Functional directory was not created");
282 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_METADATA), "Metadata directory was not created");
283 }
284
285 /**
286 * Makes sure that an exception is thrown and no directory is created on passing invalid package keys.
287 *
288 * @test
289 */
290 public function createPackageThrowsExceptionOnInvalidPackageKey() {
291 try {
292 $this->packageManager->createPackage('Invalid_PackageKey');
293 } catch (\TYPO3\Flow\Package\Exception\InvalidPackageKeyException $exception) {
294 }
295 $this->assertFalse(is_dir('vfs://Test/Packages/Application/Invalid_PackageKey'), 'Package folder with invalid package key was created');
296 }
297
298 /**
299 * Makes sure that duplicate package keys are detected.
300 *
301 * @test
302 * @expectedException \TYPO3\Flow\Package\Exception\PackageKeyAlreadyExistsException
303 */
304 public function createPackageThrowsExceptionForExistingPackageKey() {
305 $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
306 $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
307 }
308
309 /**
310 * @test
311 */
312 public function createPackageActivatesTheNewlyCreatedPackage() {
313 $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
314 $this->assertTrue($this->packageManager->isPackageActive('Acme.YetAnotherTestPackage'));
315 }
316
317 /**
318 * @test
319 */
320 public function activatePackageAndDeactivatePackageActivateAndDeactivateTheGivenPackage() {
321 $packageKey = 'Acme.YetAnotherTestPackage';
322
323 $this->packageManager->createPackage($packageKey);
324
325 $this->packageManager->deactivatePackage($packageKey);
326 $this->assertFalse($this->packageManager->isPackageActive($packageKey));
327
328 $this->packageManager->activatePackage($packageKey);
329 $this->assertTrue($this->packageManager->isPackageActive($packageKey));
330 }
331
332 /**
333 * @test
334 * @expectedException \TYPO3\Flow\Package\Exception\ProtectedPackageKeyException
335 */
336 public function deactivatePackageThrowsAnExceptionIfPackageIsProtected() {
337 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
338 $package->setProtected(TRUE);
339 $this->packageManager->deactivatePackage('Acme.YetAnotherTestPackage');
340 }
341
342 /**
343 * @test
344 * @expectedException \TYPO3\Flow\Package\Exception\UnknownPackageException
345 */
346 public function deletePackageThrowsErrorIfPackageIsNotAvailable() {
347 $this->packageManager->deletePackage('PrettyUnlikelyThatThisPackageExists');
348 }
349
350 /**
351 * @test
352 * @expectedException \TYPO3\Flow\Package\Exception\ProtectedPackageKeyException
353 */
354 public function deletePackageThrowsAnExceptionIfPackageIsProtected() {
355 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
356 $package->setProtected(TRUE);
357 $this->packageManager->deletePackage('Acme.YetAnotherTestPackage');
358 }
359
360 /**
361 * @test
362 */
363 public function deletePackageRemovesPackageFromAvailableAndActivePackagesAndDeletesThePackageDirectory() {
364 $package = $this->packageManager->createPackage('Acme.YetAnotherTestPackage');
365 $packagePath = $package->getPackagePath();
366
367 $this->assertTrue(is_dir($packagePath . PackageInterface::DIRECTORY_METADATA));
368 $this->assertTrue($this->packageManager->isPackageActive('Acme.YetAnotherTestPackage'));
369 $this->assertTrue($this->packageManager->isPackageAvailable('Acme.YetAnotherTestPackage'));
370
371 $this->packageManager->deletePackage('Acme.YetAnotherTestPackage');
372
373 $this->assertFalse(is_dir($packagePath . PackageInterface::DIRECTORY_METADATA));
374 $this->assertFalse($this->packageManager->isPackageActive('Acme.YetAnotherTestPackage'));
375 $this->assertFalse($this->packageManager->isPackageAvailable('Acme.YetAnotherTestPackage'));
376 }
377
378 /**
379 * @test
380 */
381 public function getDependencyArrayForPackageReturnsCorrectResult() {
382 $mockFlowMetadata = $this->getMock('TYPO3\Flow\Package\MetaDataInterface');
383 $mockFlowMetadata->expects($this->any())->method('getConstraintsByType')->will($this->returnValue(array(
384 new \TYPO3\Flow\Package\MetaData\PackageConstraint('depends', 'TYPO3.Fluid'),
385 new \TYPO3\Flow\Package\MetaData\PackageConstraint('depends', 'Doctrine.ORM')
386 )));
387 $mockFlowPackage = $this->getMock('TYPO3\Flow\Package\PackageInterface');
388 $mockFlowPackage->expects($this->any())->method('getPackageMetaData')->will($this->returnValue($mockFlowMetadata));
389
390 $mockFluidMetadata = $this->getMock('TYPO3\Flow\Package\MetaDataInterface');
391 $mockFluidMetadata->expects($this->any())->method('getConstraintsByType')->will($this->returnValue(array(
392 new \TYPO3\Flow\Package\MetaData\PackageConstraint('depends', 'TYPO3.Flow')
393 )));
394 $mockFluidPackage = $this->getMock('TYPO3\Flow\Package\PackageInterface');
395 $mockFluidPackage->expects($this->any())->method('getPackageMetaData')->will($this->returnValue($mockFluidMetadata));
396
397 $mockOrmMetadata = $this->getMock('TYPO3\Flow\Package\MetaDataInterface');
398 $mockOrmMetadata->expects($this->any())->method('getConstraintsByType')->will($this->returnValue(array(
399 new \TYPO3\Flow\Package\MetaData\PackageConstraint('depends', 'Doctrine.DBAL')
400 )));
401 $mockOrmPackage = $this->getMock('TYPO3\Flow\Package\PackageInterface');
402 $mockOrmPackage->expects($this->any())->method('getPackageMetaData')->will($this->returnValue($mockOrmMetadata));
403
404 $mockDbalMetadata = $this->getMock('TYPO3\Flow\Package\MetaDataInterface');
405 $mockDbalMetadata->expects($this->any())->method('getConstraintsByType')->will($this->returnValue(array(
406 new \TYPO3\Flow\Package\MetaData\PackageConstraint('depends', 'Doctrine.Common')
407 )));
408 $mockDbalPackage = $this->getMock('TYPO3\Flow\Package\PackageInterface');
409 $mockDbalPackage->expects($this->any())->method('getPackageMetaData')->will($this->returnValue($mockDbalMetadata));
410
411 $mockCommonMetadata = $this->getMock('TYPO3\Flow\Package\MetaDataInterface');
412 $mockCommonMetadata->expects($this->any())->method('getConstraintsByType')->will($this->returnValue(array()));
413 $mockCommonPackage = $this->getMock('TYPO3\Flow\Package\PackageInterface');
414 $mockCommonPackage->expects($this->any())->method('getPackageMetaData')->will($this->returnValue($mockCommonMetadata));
415
416 $packages = array(
417 'TYPO3.Flow' => $mockFlowPackage,
418 'TYPO3.Fluid' => $mockFluidPackage,
419 'Doctrine.ORM' => $mockOrmPackage,
420 'Doctrine.DBAL' => $mockDbalPackage,
421 'Doctrine.Common' => $mockCommonPackage
422 );
423
424 $packageManager = $this->getAccessibleMock('\TYPO3\Flow\Package\PackageManager', array('dummy'));
425 $packageManager->_set('packages', $packages);
426 $dependencyArray = $packageManager->_call('getDependencyArrayForPackage', 'TYPO3.Flow');
427
428 $this->assertEquals(array('Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM', 'TYPO3.Fluid'), $dependencyArray);
429 }
430
431 /**
432 * @test
433 */
434 public function sortAvailablePackagesByDependenciesMakesSureThatDependantPackagesAreStandingBeforeAPackageInTheInternalPackagesAndPackagesConfigurationArrays() {
435 $doctrineCommon = $this->getMock('\TYPO3\Flow\Package\PackageInterface');
436 $doctrineCommon->expects($this->any())->method('getPackageKey')->will($this->returnValue('Doctrine.Common'));
437
438 $doctrineDbal = $this->getMock('\TYPO3\Flow\Package\PackageInterface');
439 $doctrineDbal->expects($this->any())->method('getPackageKey')->will($this->returnValue('Doctrine.DBAL'));
440
441 $doctrineOrm = $this->getMock('\TYPO3\Flow\Package\PackageInterface');
442 $doctrineOrm->expects($this->any())->method('getPackageKey')->will($this->returnValue('Doctrine.ORM'));
443
444 $typo3Flow = $this->getMock('\TYPO3\Flow\Package\PackageInterface');
445 $typo3Flow->expects($this->any())->method('getPackageKey')->will($this->returnValue('TYPO3.Flow'));
446
447 $symfonyComponentYaml = $this->getMock('\TYPO3\Flow\Package\PackageInterface');
448 $symfonyComponentYaml->expects($this->any())->method('getPackageKey')->will($this->returnValue('Symfony.Component.Yaml'));
449
450 $unsortedPackageStatesConfiguration = array('packages' =>
451 array(
452 'Doctrine.ORM' => array(
453 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
454 ),
455 'Symfony.Component.Yaml' => array(
456 'dependencies' => array()
457 ),
458 'TYPO3.Flow' => array(
459 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
460 ),
461 'Doctrine.Common' => array(
462 'dependencies' => array()
463 ),
464 'Doctrine.DBAL' => array(
465 'dependencies' => array('Doctrine.Common')
466 )
467 )
468 );
469
470 $unsortedPackages = array(
471 'Doctrine.ORM' => $doctrineOrm,
472 'Symfony.Component.Yaml' => $symfonyComponentYaml,
473 'TYPO3.Flow' => $typo3Flow,
474 'Doctrine.Common' => $doctrineCommon,
475 'Doctrine.DBAL' => $doctrineDbal
476 );
477
478 $packageManager = $this->getAccessibleMock('\TYPO3\Flow\Package\PackageManager', array('resolvePackageDependencies'));
479 $packageManager->_set('packages', $unsortedPackages);
480 $packageManager->_set('packageStatesConfiguration', $unsortedPackageStatesConfiguration);
481 $packageManager->_call('sortAvailablePackagesByDependencies');
482
483 $expectedSortedPackageKeys = array(
484 'Doctrine.Common',
485 'Doctrine.DBAL',
486 'Doctrine.ORM',
487 'Symfony.Component.Yaml',
488 'TYPO3.Flow'
489 );
490
491 $expectedSortedPackageStatesConfiguration = array('packages' =>
492 array(
493 'Doctrine.Common' => array(
494 'dependencies' => array()
495 ),
496 'Doctrine.DBAL' => array(
497 'dependencies' => array('Doctrine.Common')
498 ),
499 'Doctrine.ORM' => array(
500 'dependencies' => array('Doctrine.Common', 'Doctrine.DBAL')
501 ),
502 'Symfony.Component.Yaml' => array(
503 'dependencies' => array()
504 ),
505 'TYPO3.Flow' => array(
506 'dependencies' => array('Symfony.Component.Yaml', 'Doctrine.Common', 'Doctrine.DBAL', 'Doctrine.ORM')
507 )
508 )
509 );
510
511 $this->assertEquals($expectedSortedPackageKeys, array_keys($packageManager->_get('packages')), 'The packages have not been ordered according to their dependencies!');
512 $this->assertEquals($expectedSortedPackageStatesConfiguration, $packageManager->_get('packageStatesConfiguration'), 'The package states configurations have not been ordered according to their dependencies!');
513 }
514
515 /**
516 * @return array
517 */
518 public function composerNamesAndPackageKeys() {
519 return array(
520 array('imagine/Imagine', 'imagine.Imagine'),
521 array('imagine/imagine', 'imagine.Imagine'),
522 array('typo3/flow', 'TYPO3.Flow'),
523 array('TYPO3/Flow', 'TYPO3.Flow')
524 );
525 }
526
527 /**
528 * @test
529 * @dataProvider composerNamesAndPackageKeys
530 */
531 public function getPackageKeyFromComposerNameIgnoresCaseDifferences($composerName, $packageKey) {
532
533 $packageStatesConfiguration = array('packages' =>
534 array(
535 'TYPO3.Flow' => array(
536 'composerName' => 'typo3/flow'
537 ),
538 'imagine.Imagine' => array(
539 'composerName' => 'imagine/Imagine'
540 )
541 )
542 );
543
544 $packageManager = $this->getAccessibleMock('\TYPO3\Flow\Package\PackageManager', array('resolvePackageDependencies'));
545 $packageManager->_set('packageStatesConfiguration', $packageStatesConfiguration);
546
547 $this->assertEquals($packageKey, $packageManager->_call('getPackageKeyFromComposerName', $composerName));
548 }
549
550 }