[TASK] Introduce unique signal registration
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Service / ExtensionManagementServiceTest.php
index a8dcf43..bf0f2ac 100644 (file)
@@ -28,7 +28,7 @@ namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Service;
  * Testcase
  *
  */
-class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
+class ExtensionManagementServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
 
        /**
         * @test
@@ -37,13 +37,14 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        public function resolveDependenciesCallsDownloadDependenciesIfDownloadKeyExistsInQueue() {
                $managementMock = $this->getAccessibleMock(
                        'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
-                       array('downloadDependencies', 'uninstallDependenciesToBeUpdated')
+                       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(
@@ -53,7 +54,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                )));
                $managementMock->_set('downloadQueue', $downloadQueueMock);
                $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
-               $managementMock->_call('resolveDependenciesAndInstall', $extensionModelMock);
+               $managementMock->_call('installExtension', $extensionModelMock);
        }
 
        /**
@@ -63,13 +64,14 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        public function resolveDependenciesCallsUpdateAndDownloadDependenciesIfUpdateKeyExistsInQueue() {
                $managementMock = $this->getAccessibleMock(
                        'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
-                       array('downloadDependencies', 'uninstallDependenciesToBeUpdated')
+                       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,7 +82,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                $managementMock->_set('downloadQueue', $downloadQueueMock);
                $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('resolveDependenciesAndInstall', $extensionModelMock);
+               $managementMock->_call('installExtension', $extensionModelMock);
        }
 
        /**
@@ -91,9 +93,21 @@ 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
                );
@@ -113,12 +127,25 @@ 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($extensionModelMock);
@@ -135,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'));
@@ -165,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);
@@ -186,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,7 +238,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        public function installDependenciesCallsInstall() {
                $managementMock = $this->getAccessibleMock(
                        'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
-                       array('dummy')
+                       array('emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal')
                );
                $installQueue = array(
                        'foobar' => array(
@@ -207,7 +246,7 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
                                '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'
@@ -222,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);
@@ -239,6 +279,3 @@ class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseT
        }
 
 }
-
-
-?>
\ No newline at end of file