[TASK] Introduce unique signal registration
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Service / ExtensionManagementServiceTest.php
index 197c7ce..bf0f2ac 100644 (file)
@@ -23,29 +23,28 @@ namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Service;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+
 /**
- * Testcase for the Tx_Extensionmanager_Service_ManagementServiceTest
- * class in the TYPO3 Core.
+ * Testcase
  *
- * @package Extension Manager
- * @subpackage Tests
  */
-class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+class ExtensionManagementServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @test
         * @return void
         */
        public function resolveDependenciesCallsDownloadDependenciesIfDownloadKeyExistsInQueue() {
-               $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
-                       'downloadDependencies',
-                       'updateDependencies'
-               ));
+               $managementMock = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
+                       array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
+               );
+               $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
                $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
                $extensionModelMock->_set('extensionKey', 'foobar');
                $extensionModelMock->_set('version', '1.0.0');
-               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('buildExtensionDependenciesTree'));
-               $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
+               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkDependencies'));
+               $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
                $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
                $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
                $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
@@ -54,8 +53,8 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                        )
                )));
                $managementMock->_set('downloadQueue', $downloadQueueMock);
-               $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock));
-               $managementMock->_call('resolveDependenciesAndInstall', $extensionModelMock);
+               $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
+               $managementMock->_call('installExtension', $extensionModelMock);
        }
 
        /**
@@ -63,15 +62,16 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
         * @return void
         */
        public function resolveDependenciesCallsUpdateAndDownloadDependenciesIfUpdateKeyExistsInQueue() {
-               $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
-                       'downloadDependencies',
-                       'uninstallDependenciesToBeUpdated'
-               ));
+               $managementMock = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
+                       array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
+               );
+               $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
                $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
                $extensionModelMock->_set('extensionKey', 'foobar');
                $extensionModelMock->_set('version', '1.0.0');
-               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('buildExtensionDependenciesTree'));
-               $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
+               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('checkDependencies'));
+               $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
                $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
                $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
                $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
@@ -80,9 +80,9 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                        )
                )));
                $managementMock->_set('downloadQueue', $downloadQueueMock);
-               $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock));
-               $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(array('foo' => $extensionModelMock));
-               $managementMock->_call('resolveDependenciesAndInstall', $extensionModelMock);
+               $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
+               $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
+               $managementMock->_call('installExtension', $extensionModelMock);
        }
 
        /**
@@ -93,15 +93,27 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
                        'dummy'
                ));
+
                $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
                $extensionModelMock->_set('extensionKey', 'foobar');
                $extensionModelMock->_set('version', '1.0.0');
+
+               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
+               $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
+               $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
+               $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
+               $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
+               $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
+               $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
+               $managementMock->_set('installUtility', $installUtilityMock);
+               $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
+
                $downloadQueue = array(
                        $extensionModelMock
                );
                $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
                $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
-               $downloadUtilityMock->expects($this->once())->method('download')->with(clone $extensionModelMock);
+               $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
                $managementMock->_set('downloadUtility', $downloadUtilityMock);
                $managementMock->_set('downloadQueue', $downloadQueueMock);
                $managementMock->_call('downloadDependencies', $downloadQueue);
@@ -115,15 +127,28 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
                        'dummy'
                ));
-               $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
-               $extensionModelMock->_set('extensionKey', 'foobar');
-               $extensionModelMock->_set('version', '1.0.0');
+
+               /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionModelMock */
+               $extensionModelMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
+               $extensionModelMock->setExtensionKey('foobar');
+               $extensionModelMock->setVersion('1.0.0');
                $downloadQueue = array(
                        $extensionModelMock
                );
+
+               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
+               $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
+               $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
+               $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
+               $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
+               $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
+               $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
+               $managementMock->_set('installUtility', $installUtilityMock);
+               $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
+
                $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
                $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
-               $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with(clone $extensionModelMock);
+               $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
                $managementMock->_set('downloadUtility', $downloadUtilityMock);
                $managementMock->_set('downloadQueue', $downloadQueueMock);
                $managementMock->_call('downloadDependencies', $downloadQueue);
@@ -137,12 +162,24 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
                        'dummy'
                ));
+
                $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
                $extensionModelMock->_set('extensionKey', 'foobar');
                $extensionModelMock->_set('version', '1.0.0');
                $downloadQueue = array(
                        $extensionModelMock
                );
+
+               $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
+               $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
+               $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
+               $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
+               $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
+               $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
+               $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
+               $managementMock->_set('installUtility', $installUtilityMock);
+               $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
+
                $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
                $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
                $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
@@ -167,7 +204,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $downloadQueue = array(
                        $extensionModelMock
                );
-               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'));
+               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
                $installUtility->expects($this->once())->method('uninstall')->with('foobar');
                $managementMock->_set('installUtility', $installUtility);
                $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
@@ -188,7 +225,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $downloadQueue = array(
                        $extensionModelMock
                );
-               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'));
+               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
                $managementMock->_set('installUtility', $installUtility);
                $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
                $this->assertEquals(array('updated' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
@@ -199,16 +236,17 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
         * @return void
         */
        public function installDependenciesCallsInstall() {
-               $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
-                       'dummy'
-               ));
+               $managementMock = $this->getAccessibleMock(
+                       'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
+                       array('emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal')
+               );
                $installQueue = array(
                        'foobar' => array(
                                'key' => 'foobar',
                                'siteRelPath' => 'path'
                        )
                );
-               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install'));
+               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensionsSignal'), array(), '', FALSE);
                $installUtility->expects($this->once())->method('install')->with(array(
                        'key' => 'foobar',
                        'siteRelPath' => 'path'
@@ -223,12 +261,13 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
         */
        public function installDependenciesReturnsResolvedDependencies() {
                $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
-                       'dummy'
+                       'emitWillInstallExtensionsSignal',
+                       'emitHasInstalledExtensionSignal'
                ));
                $installQueue = array(
                        'foobar' => 'foobar'
                );
-               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install'));
+               $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensionsSignal'), array(), '', FALSE);
                $installUtility->expects($this->once())->method('install')->with('foobar');
                $managementMock->_set('installUtility', $installUtility);
                $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
@@ -240,6 +279,3 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        }
 
 }
-
-
-?>
\ No newline at end of file