[BUGFIX] addModule after/before not working 84/27284/12
authorMichiel Roos <michiel@maxserv.nl>
Sun, 2 Feb 2014 23:19:25 +0000 (00:19 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Mon, 3 Feb 2014 22:35:38 +0000 (23:35 +0100)
The cleaned up addModule() method no longer adds the module after a
module, when the target module does not exist.

Expected behaviour: module added to the list.

Observed behaviour: module not added at all.

Change-Id: Ie0d1d0c98f9c7dde81636a40eb18a3a7816392f6
Resolves: #55608
Related: #55122
Releases: 6.2
Reviewed-on: https://review.typo3.org/27284
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionManagementUtilityTest.php

index 0c5a940..48fe8ce 100644 (file)
@@ -827,6 +827,9 @@ class ExtensionManagementUtility {
                if (isset($GLOBALS['TBE_MODULES'][$main]) && $sub) {
                        list($place, $modRef) = GeneralUtility::trimExplode(':', $position, TRUE);
                        $modules = ',' . $GLOBALS['TBE_MODULES'][$main] . ',';
+                       if ($place === NULL || ($modRef !== NULL && !GeneralUtility::inList($modules, $modRef))) {
+                               $place = 'bottom';
+                       }
                        $modRef = ',' . $modRef . ',';
                        if (!GeneralUtility::inList($modules, $sub)) {
                                switch (strtolower($place)) {
index 2b3976b..b7c26df 100644 (file)
@@ -744,60 +744,75 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                ExtensionManagementUtilityAccessibleProxy::loadSingleExtLocalconfFiles();
        }
 
+
        /////////////////////////////////////////
        // Tests concerning addModule
        /////////////////////////////////////////
 
        /**
-        * @test
-        */
-       public function newSubmoduleCanBeAddedToTopOfModule() {
-               $mainModule = 'foobar';
-               $subModule = 'newModule';
-               $GLOBALS['TBE_MODULES'][$mainModule] = 'some,modules';
-
-               ExtensionManagementUtility::addModule($mainModule, $subModule, 'top');
-
-               $this->assertEquals('newModule,some,modules', $GLOBALS['TBE_MODULES'][$mainModule]);
-       }
-
-       /**
-        * @test
-        */
-       public function newSubmoduleCanBeAddedToBottomOfModule() {
-               $mainModule = 'foobar';
-               $subModule = 'newModule';
-               $GLOBALS['TBE_MODULES'][$mainModule] = 'some,modules';
-
-               ExtensionManagementUtility::addModule($mainModule, $subModule, 'bottom');
-
-               $this->assertEquals('some,modules,newModule', $GLOBALS['TBE_MODULES'][$mainModule]);
-       }
-
-       /**
-        * @test
+        * Data provider for addModule tests
+        * @return array
         */
-       public function newSubmoduleCanBeAddedAfterSpecifiedSubmodule() {
-               $mainModule = 'foobar';
-               $subModule = 'newModule';
-               $GLOBALS['TBE_MODULES'][$mainModule] = 'some,modules';
-
-               ExtensionManagementUtility::addModule($mainModule, $subModule, 'after:some');
-
-               $this->assertEquals('some,newModule,modules', $GLOBALS['TBE_MODULES'][$mainModule]);
+       public function addModulePositionTestsDataProvider() {
+               return array(
+                       'can add new main module if none exists' => array(
+                               'top',
+                               '',
+                               'newModule'
+                       ),
+                       'can add new sub module if no position specified' => array(
+                               '',
+                               'some,modules',
+                               'some,modules,newModule'
+                       ),
+                       'can add new sub module to top of module' => array(
+                               'top',
+                               'some,modules',
+                               'newModule,some,modules'
+                       ),
+                       'can add new sub module if bottom of module' => array(
+                               'bottom',
+                               'some,modules',
+                               'some,modules,newModule'
+                       ),
+                       'can add new sub module before specified sub module' => array(
+                               'before:modules',
+                               'some,modules',
+                               'some,newModule,modules'
+                       ),
+                       'can add new sub module after specified sub module' => array(
+                               'after:some',
+                               'some,modules',
+                               'some,newModule,modules'
+                       ),
+                       'can add new sub module at the bottom if specified sub module to add before does not exist' => array(
+                               'before:modules',
+                               'some,otherModules',
+                               'some,otherModules,newModule'
+                       ),
+                       'can add new sub module at the bottom if specified sub module to add after does not exist' => array(
+                               'after:some',
+                               'someOther,modules',
+                               'someOther,modules,newModule'
+                       ),
+               );
        }
 
        /**
         * @test
+        * @dataProvider addModulePositionTestsDataProvider
         */
-       public function newSubmoduleCanBeAddedBeforeSpecifiedSubmodule() {
+       public function addModuleCanAddModule($position, $existing, $expected) {
                $mainModule = 'foobar';
                $subModule = 'newModule';
-               $GLOBALS['TBE_MODULES'][$mainModule] = 'some,modules';
+               if ($existing) {
+                       $GLOBALS['TBE_MODULES'][$mainModule] = $existing;
+               }
 
-               ExtensionManagementUtility::addModule($mainModule, $subModule, 'before:modules');
+               ExtensionManagementUtility::addModule($mainModule, $subModule, $position);
 
-               $this->assertEquals('some,newModule,modules', $GLOBALS['TBE_MODULES'][$mainModule]);
+               $this->assertTrue(isset($GLOBALS['TBE_MODULES'][$mainModule]));
+               $this->assertEquals($expected, $GLOBALS['TBE_MODULES'][$mainModule]);
        }
 
        /////////////////////////////////////////