[BUGFIX] Follow-up to: Use an extension as repository 29/24129/3
authorSusanne Moog <typo3@susannemoog.de>
Sun, 8 Sep 2013 12:04:50 +0000 (14:04 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 28 Sep 2013 18:33:21 +0000 (20:33 +0200)
Add missing files that got lost during conflict resolving

Change-Id: If9fc0e23aba97659222bee0c5b2205c5030411fc
Resolves: #51835
Releases: 6.2
Reviewed-on: https://review.typo3.org/24129
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/extensionmanager/Classes/Utility/ExtensionModelUtility.php [new file with mode: 0644]
typo3/sysext/extensionmanager/Tests/Unit/Utility/ExtensionModelUtilityTest.php [new file with mode: 0644]

diff --git a/typo3/sysext/extensionmanager/Classes/Utility/ExtensionModelUtility.php b/typo3/sysext/extensionmanager/Classes/Utility/ExtensionModelUtility.php
new file mode 100644 (file)
index 0000000..5a8a8b4
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Utility;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Susanne Moog <susanne.moog@typo3.org>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *  A copy is found in the textfile GPL.txt and important notices to the license
+ *  from the author is found in LICENSE.txt distributed with these scripts.
+ *
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Utility for dealing with extension model related helper functions
+ *
+ * @author Susanne Moog <susanne.moog@typo3.org>
+ */
+class ExtensionModelUtility {
+
+       /**
+        * @var \TYPO3\CMS\Extbase\Object\ObjectManager
+        * @inject
+        */
+       protected $objectManager;
+
+       /**
+        * Map a legacy extension array to an object
+        *
+        * @param array $extensionArray
+        * @return \TYPO3\CMS\Extensionmanager\Domain\Model\Extension
+        */
+       public function mapExtensionArrayToModel(array $extensionArray) {
+               /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extension */
+               $extension = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
+               $extension->setExtensionKey($extensionArray['key']);
+               if (isset($extensionArray['version'])) {
+                       $extension->setVersion($extensionArray['version']);
+               }
+               if (isset($extensionArray['constraints'])) {
+                       $extension->setDependencies($this->convertDependenciesToObjects(serialize($extensionArray['constraints'])));
+               }
+               return $extension;
+       }
+
+       /**
+        * Converts string dependencys to an object storage of dependencies
+        *
+        * @param string $dependencies
+        * @return \SplObjectStorage
+        */
+       public function convertDependenciesToObjects($dependencies) {
+               $unserializedDependencies = unserialize($dependencies);
+               $dependenciesObject = new \SplObjectStorage();
+               foreach ($unserializedDependencies as $dependencyType => $dependencyValues) {
+                       foreach ($dependencyValues as $dependency => $versions) {
+                               if ($dependencyType && $dependency) {
+                                       $versionNumbers = \TYPO3\CMS\Core\Utility\VersionNumberUtility::convertVersionsStringToVersionNumbers($versions);
+                                       $lowest = $versionNumbers[0];
+                                       if (count($versionNumbers) === 2) {
+                                               $highest = $versionNumbers[1];
+                                       } else {
+                                               $highest = '';
+                                       }
+                                       /** @var $dependencyObject \TYPO3\CMS\Extensionmanager\Domain\Model\Dependency */
+                                       $dependencyObject = $this->objectManager->get('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency');
+                                       $dependencyObject->setType($dependencyType);
+                                       $dependencyObject->setIdentifier($dependency);
+                                       $dependencyObject->setLowestVersion($lowest);
+                                       $dependencyObject->setHighestVersion($highest);
+                                       $dependenciesObject->attach($dependencyObject);
+                                       unset($dependencyObject);
+                               }
+                       }
+               }
+               return $dependenciesObject;
+       }
+}
+
+?>
\ No newline at end of file
diff --git a/typo3/sysext/extensionmanager/Tests/Unit/Utility/ExtensionModelUtilityTest.php b/typo3/sysext/extensionmanager/Tests/Unit/Utility/ExtensionModelUtilityTest.php
new file mode 100644 (file)
index 0000000..17b94b0
--- /dev/null
@@ -0,0 +1,151 @@
+<?php
+namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
+
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2012
+ * All rights reserved
+ *
+ * This script is part of the TYPO3 project. The TYPO3 project is
+ * free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * The GNU General Public License can be found at
+ * http://www.gnu.org/copyleft/gpl.html.
+ *
+ * This script is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+/**
+ * Test for ExtensionModelUtilityTest
+ *
+ */
+class ExtensionModelUtilityTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+       /**
+        * @test
+        * @return void
+        */
+       public function convertDependenciesToObjectsCreatesObjectStorage() {
+               $serializedDependencies = serialize(array(
+                       'depends' => array(
+                               'php' => '5.1.0-0.0.0',
+                               'typo3' => '4.2.0-4.4.99',
+                               'fn_lib' => ''
+                       )
+               ));
+               /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
+               $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
+               $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
+               $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('dummy'));
+               $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
+               $dependencyUtility->_set('objectManager', $objectManagerMock);
+               $objectStorage = $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
+               $this->assertTrue($objectStorage instanceof \SplObjectStorage);
+       }
+
+       /**
+        * @test
+        * @return void
+        */
+       public function convertDependenciesToObjectsSetsIdentifier() {
+               $serializedDependencies = serialize(array(
+                       'depends' => array(
+                               'php' => '5.1.0-0.0.0',
+                               'typo3' => '4.2.0-4.4.99',
+                               'fn_lib' => ''
+                       )
+               ));
+               /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
+               $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
+               $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
+               $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setIdentifier'));
+               $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
+               $dependencyUtility->_set('objectManager', $objectManagerMock);
+               $dependencyModelMock->expects($this->at(0))->method('setIdentifier')->with('php');
+               $dependencyModelMock->expects($this->at(1))->method('setIdentifier')->with('typo3');
+               $dependencyModelMock->expects($this->at(2))->method('setIdentifier')->with('fn_lib');
+               $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
+       }
+
+       /**
+        * @return array
+        */
+       public function convertDependenciesToObjectSetsVersionDataProvider() {
+               return array(
+                       'everything ok' => array(
+                               array(
+                                       'depends' => array(
+                                               'typo3' => '4.2.0-4.4.99'
+                                       )
+                               ),
+                               array(
+                                       '4.2.0',
+                                       '4.4.99'
+                               )
+                       ),
+                       'empty high value' => array(
+                               array(
+                                       'depends' => array(
+                                               'typo3' => '4.2.0-0.0.0'
+                                       )
+                               ),
+                               array(
+                                       '4.2.0',
+                                       ''
+                               )
+                       ),
+                       'empty low value' => array(
+                               array(
+                                       'depends' => array(
+                                               'typo3' => '0.0.0-4.4.99'
+                                       )
+                               ),
+                               array(
+                                       '',
+                                       '4.4.99'
+                               )
+                       ),
+                       'only one value' => array(
+                               array(
+                                       'depends' => array(
+                                               'typo3' => '4.4.99'
+                                       )
+                               ),
+                               array(
+                                       '4.4.99',
+                                       '',
+                               )
+                       ),
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider convertDependenciesToObjectSetsVersionDataProvider
+        * @param array $dependencies
+        * @param array $returnValue
+        * @return void
+        */
+       public function convertDependenciesToObjectSetsVersion(array $dependencies, array $returnValue) {
+               $serializedDependencies = serialize($dependencies);
+               /** @var $dependencyUtility \TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility */
+               $dependencyUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility', array('dummy'));
+               $objectManagerMock = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager', array('get'));
+               $dependencyModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Dependency', array('setHighestVersion', 'setLowestVersion'));
+               $objectManagerMock->expects($this->any())->method('get')->will($this->returnValue($dependencyModelMock));
+               $dependencyUtility->_set('objectManager', $objectManagerMock);
+               $dependencyModelMock->expects($this->atLeastOnce())->method('setLowestVersion')->with($this->identicalTo($returnValue[0]));
+               $dependencyModelMock->expects($this->atLeastOnce())->method('setHighestVersion')->with($this->identicalTo($returnValue[1]));
+               $dependencyUtility->convertDependenciesToObjects($serializedDependencies);
+       }
+}
+
+?>
\ No newline at end of file