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 = $this->
getAccessibleMock(
'TYPO3\\CMS\\Core\\Package\\PackageManager', array(
'sortAndSavePackageStates'));
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); ");
47 $mockClassLoader = $this->getMock(
'TYPO3\CMS\Core\Core\ClassLoader', array(), array(\
TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getApplicationContext()));
48 $mockClassLoader->expects($this->any())->method(
'setCacheIdentifier')->will($this->returnSelf());
50 $composerNameToPackageKeyMap = array(
51 'typo3/flow' =>
'TYPO3.Flow' 54 $this->packageManager->injectClassLoader($mockClassLoader);
55 $this->packageManager->injectCoreCache($mockCache);
56 $this->
inject($this->packageManager,
'composerNameToPackageKeyMap', $composerNameToPackageKeyMap);
57 $this->packageManager->_set(
'packagesBasePath',
'vfs://Test/Packages/');
58 $this->packageManager->_set(
'packageStatesPathAndFilename',
'vfs://Test/Configuration/PackageStates.php');
59 $this->packageManager->initialize($mockBootstrap);
66 $this->packageManager->createPackage(
'TYPO3.Flow');
68 $package = $this->packageManager->getPackage(
'TYPO3.Flow');
69 $this->assertInstanceOf(
'TYPO3\Flow\Package\PackageInterface', $package,
'The result of getPackage() was no valid package object.');
77 $this->packageManager->getPackage(
'PrettyUnlikelyThatThisPackageExists');
85 $mockFlowMetadata = $this->getMock(
'TYPO3\Flow\Package\MetaDataInterface');
86 $mockFlowMetadata->expects($this->any())->method(
'getConstraintsByType')->will($this->returnValue(array(
87 new \
TYPO3\Flow\Package\MetaData\PackageConstraint(
'depends',
'TYPO3.Fluid'),
88 new \
TYPO3\Flow\Package\MetaData\PackageConstraint(
'depends',
'Doctrine.ORM')
90 $mockFlowPackage = $this->getMock(
'TYPO3\Flow\Package\PackageInterface');
91 $mockFlowPackage->expects($this->any())->method(
'getPackageMetaData')->will($this->returnValue($mockFlowMetadata));
93 $mockFluidMetadata = $this->getMock(
'TYPO3\Flow\Package\MetaDataInterface');
94 $mockFluidMetadata->expects($this->any())->method(
'getConstraintsByType')->will($this->returnValue(array(
95 new \
TYPO3\Flow\Package\MetaData\PackageConstraint(
'depends',
'TYPO3.Flow')
97 $mockFluidPackage = $this->getMock(
'TYPO3\Flow\Package\PackageInterface');
98 $mockFluidPackage->expects($this->any())->method(
'getPackageMetaData')->will($this->returnValue($mockFluidMetadata));
100 $mockOrmMetadata = $this->getMock(
'TYPO3\Flow\Package\MetaDataInterface');
101 $mockOrmMetadata->expects($this->any())->method(
'getConstraintsByType')->will($this->returnValue(array(
102 new \
TYPO3\Flow\Package\MetaData\PackageConstraint(
'depends',
'Doctrine.DBAL')
104 $mockOrmPackage = $this->getMock(
'TYPO3\Flow\Package\PackageInterface');
105 $mockOrmPackage->expects($this->any())->method(
'getPackageMetaData')->will($this->returnValue($mockOrmMetadata));
107 $mockDbalMetadata = $this->getMock(
'TYPO3\Flow\Package\MetaDataInterface');
108 $mockDbalMetadata->expects($this->any())->method(
'getConstraintsByType')->will($this->returnValue(array(
109 new \
TYPO3\Flow\Package\MetaData\PackageConstraint(
'depends',
'Doctrine.Common')
111 $mockDbalPackage = $this->getMock(
'TYPO3\Flow\Package\PackageInterface');
112 $mockDbalPackage->expects($this->any())->method(
'getPackageMetaData')->will($this->returnValue($mockDbalMetadata));
114 $mockCommonMetadata = $this->getMock(
'TYPO3\Flow\Package\MetaDataInterface');
115 $mockCommonMetadata->expects($this->any())->method(
'getConstraintsByType')->will($this->returnValue(array()));
116 $mockCommonPackage = $this->getMock(
'TYPO3\Flow\Package\PackageInterface');
117 $mockCommonPackage->expects($this->any())->method(
'getPackageMetaData')->will($this->returnValue($mockCommonMetadata));
120 'TYPO3.Flow' => $mockFlowPackage,
121 'TYPO3.Fluid' => $mockFluidPackage,
122 'Doctrine.ORM' => $mockOrmPackage,
123 'Doctrine.DBAL' => $mockDbalPackage,
124 'Doctrine.Common' => $mockCommonPackage
129 $dependencyArray =
$packageManager->_call(
'getDependencyArrayForPackage',
'TYPO3.Flow');
131 $this->assertEquals(array(
'Doctrine.Common',
'Doctrine.DBAL',
'Doctrine.ORM',
'TYPO3.Fluid'), $dependencyArray);
139 $packageManager->_set(
'packageKeys', array(
'acme.testpackage' =>
'Acme.TestPackage'));
140 $this->assertEquals(
'Acme.TestPackage',
$packageManager->getCaseSensitivePackageKey(
'acme.testpackage'));
147 $expectedPackageKeys = array(
154 foreach ($expectedPackageKeys as $packageKey) {
155 $packagePath =
'vfs://Test/Packages/Application/' . $packageKey .
'/';
157 mkdir($packagePath, 0770, TRUE);
158 mkdir($packagePath .
'Classes');
159 file_put_contents($packagePath .
'composer.json',
'{"name": "' . $packageKey .
'", "type": "flow-test"}');
164 $packageManager->_set(
'packageStatesPathAndFilename',
'vfs://Test/Configuration/PackageStates.php');
166 $packageFactory = new \TYPO3\Flow\Package\PackageFactory(
$packageManager);
172 $packageStates = require(
'vfs://Test/Configuration/PackageStates.php');
173 $actualPackageKeys = array_keys($packageStates[
'packages']);
174 $this->assertEquals(sort($expectedPackageKeys), sort($actualPackageKeys));
181 $expectedPackageKeys = array(
188 foreach ($expectedPackageKeys as $packageKey) {
189 $packagePath =
'vfs://Test/Packages/Application/' . $packageKey .
'/';
191 mkdir($packagePath, 0770, TRUE);
192 mkdir($packagePath .
'Classes');
193 file_put_contents($packagePath .
'composer.json',
'{"name": "' . $packageKey .
'", "type": "flow-test"}');
198 $packageManager->_set(
'packageStatesPathAndFilename',
'vfs://Test/Configuration/PackageStates.php');
200 $packageFactory = new \TYPO3\Flow\Package\PackageFactory(
$packageManager);
205 $packageKey => array(
206 'state' =>
'inactive',
208 'packagePath' =>
'Application/' . $packageKey .
'/',
209 'classesPath' =>
'Classes/' 217 $packageStates = require(
'vfs://Test/Configuration/PackageStates.php');
218 $this->assertEquals(
'inactive', $packageStates[
'packages'][$packageKey][
'state']);
226 if (version_compare(phpversion(),
'5.4.0',
'<')) {
227 $this->markTestSkipped(
'This test is not reliable with PHP version below 5.4.0');
230 $packageKeys = array(
231 $this->
getUniqueId(
'RobertLemke.Flow.NothingElse'),
236 foreach ($packageKeys as $packageKey) {
237 $packagePath =
'vfs://Test/Packages/Application/' . $packageKey .
'/';
239 mkdir($packagePath, 0770, TRUE);
240 mkdir($packagePath .
'Classes');
241 file_put_contents($packagePath .
'composer.json',
'{"name": "' . $packageKey .
'", "type": "flow-test"}');
246 $packageManager->_set(
'packageStatesPathAndFilename',
'vfs://Test/Configuration/PackageStates.php');
248 $packageFactory = new \TYPO3\Flow\Package\PackageFactory(
$packageManager);
254 $expectedPackageStatesConfiguration = array();
255 foreach ($packageKeys as $packageKey) {
256 $expectedPackageStatesConfiguration[$packageKey] = array(
258 'packagePath' =>
'Application/' . $packageKey .
'/',
259 'classesPath' =>
'Classes/',
260 'manifestPath' =>
'',
261 'composerName' => $packageKey
265 $actualPackageStatesConfiguration =
$packageManager->_get(
'packageStatesConfiguration');
266 $this->assertEquals($expectedPackageStatesConfiguration, $actualPackageStatesConfiguration[
'packages']);
276 array(
'TYPO3.YetAnotherTestPackage',
'vfs://Test/Packages/Application/TYPO3.YetAnotherTestPackage/'),
277 array(
'RobertLemke.Flow.NothingElse',
'vfs://Test/Packages/Application/RobertLemke.Flow.NothingElse/')
286 $actualPackage = $this->packageManager->createPackage($packageKey);
287 $actualPackagePath = $actualPackage->getPackagePath();
289 $this->assertEquals($expectedPackagePath, $actualPackagePath);
290 $this->assertTrue(is_dir($actualPackagePath),
'Package path should exist after createPackage()');
291 $this->assertEquals($packageKey, $actualPackage->getPackageKey());
292 $this->assertTrue($this->packageManager->isPackageAvailable($packageKey));
299 $metaData = new \TYPO3\Flow\Package\MetaData(
'Acme.YetAnotherTestPackage');
300 $metaData->setDescription(
'Yet Another Test Package');
302 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage', $metaData);
304 $json = file_get_contents($package->getPackagePath() .
'/composer.json');
305 $composerManifest = json_decode($json);
307 $this->assertEquals(
'acme/yetanothertestpackage', $composerManifest->name);
308 $this->assertEquals(
'Yet Another Test Package', $composerManifest->description);
315 $metaData = new \TYPO3\Flow\Package\MetaData(
'Acme.YetAnotherTestPackage2');
316 $metaData->setDescription(
'Yet Another Test Package');
317 $metaData->setPackageType(
'flow-custom-package');
319 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage2', $metaData);
321 $json = file_get_contents($package->getPackagePath() .
'/composer.json');
322 $composerManifest = json_decode($json);
324 $this->assertEquals(
'flow-custom-package', $composerManifest->type);
333 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
334 $packagePath = $package->getPackagePath();
352 $this->packageManager->createPackage(
'Invalid.PackageKey');
353 }
catch (\
TYPO3\Flow\Package\
Exception\InvalidPackageKeyException $exception) {
355 $this->assertFalse(is_dir(
'vfs://Test/Packages/Application/Invalid_PackageKey'),
'Package folder with invalid package key was created');
365 $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
366 $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
373 $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
374 $this->assertTrue($this->packageManager->isPackageActive(
'Acme.YetAnotherTestPackage'));
381 $packageKey =
'Acme.YetAnotherTestPackage';
383 $this->packageManager->createPackage($packageKey);
385 $this->packageManager->deactivatePackage($packageKey);
386 $this->assertFalse($this->packageManager->isPackageActive($packageKey));
388 $this->packageManager->activatePackage($packageKey);
389 $this->assertTrue($this->packageManager->isPackageActive($packageKey));
397 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
398 $package->setProtected(TRUE);
399 $this->packageManager->deactivatePackage(
'Acme.YetAnotherTestPackage');
407 $this->packageManager->deletePackage(
'PrettyUnlikelyThatThisPackageExists');
415 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
416 $package->setProtected(TRUE);
417 $this->packageManager->deletePackage(
'Acme.YetAnotherTestPackage');
424 $package = $this->packageManager->createPackage(
'Acme.YetAnotherTestPackage');
425 $packagePath = $package->getPackagePath();
428 $this->assertTrue($this->packageManager->isPackageActive(
'Acme.YetAnotherTestPackage'));
429 $this->assertTrue($this->packageManager->isPackageAvailable(
'Acme.YetAnotherTestPackage'));
431 $this->packageManager->deletePackage(
'Acme.YetAnotherTestPackage');
433 $this->assertFalse(is_dir($packagePath . PackageInterface::DIRECTORY_METADATA));
434 $this->assertFalse($this->packageManager->isPackageActive(
'Acme.YetAnotherTestPackage'));
435 $this->assertFalse($this->packageManager->isPackageAvailable(
'Acme.YetAnotherTestPackage'));
443 array(
'imagine/Imagine',
'imagine.Imagine'),
444 array(
'imagine/imagine',
'imagine.Imagine'),
445 array(
'typo3/flow',
'TYPO3.Flow'),
446 array(
'TYPO3/Flow',
'TYPO3.Flow')
455 $packageStatesConfiguration = array(
'packages' =>
457 'TYPO3.Flow' => array(
458 'composerName' =>
'typo3/flow' 460 'imagine.Imagine' => array(
461 'composerName' =>
'imagine/Imagine' 467 $packageManager->_set(
'packageStatesConfiguration', $packageStatesConfiguration);
469 $this->assertEquals($packageKey,
$packageManager->_call(
'getPackageKeyFromComposerName', $composerName));
deletePackageThrowsErrorIfPackageIsNotAvailable()
createPackageCanChangePackageTypeInComposerManifest()
inject($target, $name, $dependency)
deletePackageThrowsAnExceptionIfPackageIsProtected()
const DIRECTORY_TESTS_UNIT
getPackageThrowsExceptionOnUnknownPackage()
getPackageReturnsTheSpecifiedPackage()
scanAvailablePackagesKeepsExistingPackageConfiguration()
createPackageCreatesPackageFolderAndReturnsPackage($packageKey, $expectedPackagePath)
deactivatePackageThrowsAnExceptionIfPackageIsProtected()
activatePackageAndDeactivatePackageActivateAndDeactivateTheGivenPackage()
createPackageThrowsExceptionOnInvalidPackageKey()
packageStatesConfigurationContainsRelativePaths()
deletePackageRemovesPackageFromAvailableAndActivePackagesAndDeletesThePackageDirectory()
getAccessibleMock( $originalClassName, array $methods=array(), array $arguments=array(), $mockClassName='', $callOriginalConstructor=TRUE, $callOriginalClone=TRUE, $callAutoload=TRUE)
const DIRECTORY_CONFIGURATION
createPackageWritesAComposerManifestUsingTheGivenMetaObject()
const DIRECTORY_RESOURCES
scanAvailablePackagesTraversesThePackagesDirectoryAndRegistersPackagesItFinds()
createPackageActivatesTheNewlyCreatedPackage()
createPackageThrowsExceptionForExistingPackageKey()
getDependencyArrayForPackageReturnsCorrectResult()
const DIRECTORY_TESTS_FUNCTIONAL
createPackageCreatesCommonFolders()
getPackageKeyFromComposerNameIgnoresCaseDifferences($composerName, $packageKey)
const DIRECTORY_DOCUMENTATION
getCaseSensitivePackageKeyReturnsTheUpperCamelCaseVersionOfAGivenPackageKeyIfThePackageIsRegistered()
composerNamesAndPackageKeys()