[BUGFIX] Incomplete mock in ext:install 55/31355/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Sat, 5 Jul 2014 16:01:21 +0000 (18:01 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Sat, 5 Jul 2014 17:28:28 +0000 (19:28 +0200)
"ExtensionCompatibilityTesterTests" triggers loadBaseTca() that
loads TCA and TCA overrides of all active packages. Since the
unit test package manager activates all extensions found, this
may lead to unexpected effects with extensions hanging around
in typo3conf/ext.
The patch creates a backup of the package manager and mocks it
properly in some tests.

Change-Id: Ia5b1ccb449f1611837e6436cab226820b22a9047
Resolves: #60120
Related: #59770
Releases: 6.3, 6.2
Reviewed-on: https://review.typo3.org/31355
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/install/Tests/Unit/Controller/Action/Ajax/ExtensionCompatibilityTesterTest.php

index 78c458f..de77658 100644 (file)
@@ -22,11 +22,29 @@ use TYPO3\CMS\Core\Utility;
 class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
+        * @var \TYPO3\CMS\Core\Package\UnitTestPackageManager A backup of unit test package manager
+        */
+       protected $backupPackageManager = NULL;
+
+       /**
+        * Set up
+        *
+        * @return void
+        */
+       public function setUp() {
+               // Package manager is mocked in some tests. Backup the original one here to re-inject it to
+               // ExtensionManagementUtility in tearDown() again. makeInstance() is allowed to be used here
+               // since the PackageManager is registered as singleton by bootstrap.
+               $this->backupPackageManager = Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager');
+       }
+
+       /**
         * Tear down
         *
         * @return void
         */
        public function tearDown() {
+               Utility\ExtensionManagementUtility::setPackageManager($this->backupPackageManager);
                if (file_exists(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt')) {
                        unlink(PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt');
                }
@@ -106,6 +124,13 @@ class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         * @test
         */
        public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsLoadExtTablesForExtension() {
+               // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
+               // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
+               // not trigger unwanted side effects.
+               $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
+               $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
+               Utility\ExtensionManagementUtility::setPackageManager($packageManager);
+
                $extension = array(
                        'demo1' => array(
                                'type' => 'L',
@@ -121,6 +146,13 @@ class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         * @test
         */
        public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsLoadExtLocalconfForExtension() {
+               // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
+               // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
+               // not trigger unwanted side effects.
+               $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
+               $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
+               Utility\ExtensionManagementUtility::setPackageManager($packageManager);
+
                $extension = array(
                        'demo1' => array(
                                'type' => 'L',
@@ -153,6 +185,13 @@ class ExtensionCompatibilityTesterTest extends \TYPO3\CMS\Core\Tests\UnitTestCas
         * @test
         */
        public function tryToLoadExtLocalconfAndExtTablesOfExtensionsCallsWriteCurrentExtensionToFile() {
+               // tryToLoadExtLocalconfAndExtTablesOfExtensions() triggers a call to ExtensionManagementUtility::loadBaseTca
+               // that works on our UnitTestPackageManager to do things. This package manager needs to be mocked here to
+               // not trigger unwanted side effects.
+               $packageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array(), array(), '', FALSE);
+               $packageManager->expects($this->any())->method('getActivePackages')->will($this->returnValue(array()));
+               Utility\ExtensionManagementUtility::setPackageManager($packageManager);
+
                $extension = array(
                        'demo1' => array(
                                'type' => 'L',