[BUGFIX] Use correct array structure for EM error messages 67/31267/2
authorSascha Egerer <sascha.egerer@dkd.de>
Mon, 30 Jun 2014 09:27:51 +0000 (11:27 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Tue, 1 Jul 2014 17:19:25 +0000 (19:19 +0200)
The extension manager stores errors (like exceptions that
are thrown while installing an extension) in an array and
passes them to a fluid template.

The array has to be in a defined structure like
$errorMessages[extension name][i] = array(
»       error code,
»       error message
)

Currently, if an extension is installed from ter and an error occurs
while downloading the extension, the code and text are stored directly
under the extension name and therefore the array is not correctly parsed
by the fluid template.

Resolves: #59991
Releases: 6.3, 6.2
Change-Id: Id330f0af2a99ab99cb8b736332cb8506c857716c
Reviewed-on: https://review.typo3.org/31267
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
typo3/sysext/extensionmanager/Classes/Controller/DownloadController.php
typo3/sysext/extensionmanager/Tests/Unit/Controller/DownloadControllerTest.php [new file with mode: 0644]

index 71b8e00..2cb75b6 100644 (file)
@@ -220,8 +220,10 @@ class DownloadController extends AbstractController {
                } catch (\TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException $e) {
                        $errorMessages = array(
                                $extension->getExtensionKey() => array(
-                                       'code' => $e->getCode(),
-                                       'message' => $e->getMessage(),
+                                       array(
+                                               'code' => $e->getCode(),
+                                               'message' => $e->getMessage(),
+                                       )
                                ),
                        );
                }
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Controller/DownloadControllerTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Controller/DownloadControllerTest.php
new file mode 100644 (file)
index 0000000..dfdd720
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Controller;
+
+/**
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Download from TER controller test
+ *
+ */
+class DownloadControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
+
+       /**
+        * @test
+        *
+        * @return void
+        */
+       public function installFromTerReturnsArrayWithBooleanResultAndErrorArrayWhenExtensionManagerExceptionIsThrown() {
+               $dummyExceptionMessage = 'exception message';
+               $dummyException = new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException($dummyExceptionMessage);
+
+               $dummyExtensionName = 'dummy_extension';
+               $dummyExtension = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $dummyExtension->expects($this->any())->method('getExtensionKey')->will($this->returnValue($dummyExtensionName));
+
+               $downloadUtilityMock = $this->getMock('\\TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility');
+               $downloadUtilityMock->expects($this->any())->method('setDownloadPath')->willThrowException($dummyException);
+
+               $subject = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\DownloadController', array('dummy'));
+               $subject->_set('downloadUtility', $downloadUtilityMock);
+
+               $result = $subject->_call('installFromTer', $dummyExtension);
+
+               $expectedResult = array(
+                       FALSE,
+                       array(
+                               $dummyExtensionName => array(
+                                       array(
+                                               'code' => 0,
+                                               'message' => $dummyExceptionMessage
+                                       )
+                               )
+                       )
+               );
+
+               $this->assertSame($expectedResult, $result);
+       }
+
+}