3036a9e38cf767d833bc62558f7edc71e2c9cd3a
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Service / ExtensionManagementServiceTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Service;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Testcase
29 *
30 */
31 class ExtensionManagementServiceTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
32
33 /**
34 * @test
35 * @return void
36 */
37 public function resolveDependenciesCallsDownloadDependenciesIfDownloadKeyExistsInQueue() {
38 $managementMock = $this->getAccessibleMock(
39 'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
40 array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
41 );
42 $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
43 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
44 $extensionModelMock->_set('extensionKey', 'foobar');
45 $extensionModelMock->_set('version', '1.0.0');
46 $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('buildExtensionDependenciesTree'));
47 $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
48 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
49 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
50 $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
51 'download' => array(
52 'foo' => $extensionModelMock
53 )
54 )));
55 $managementMock->_set('downloadQueue', $downloadQueueMock);
56 $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
57 $managementMock->_call('resolveDependenciesAndInstall', $extensionModelMock);
58 }
59
60 /**
61 * @test
62 * @return void
63 */
64 public function resolveDependenciesCallsUpdateAndDownloadDependenciesIfUpdateKeyExistsInQueue() {
65 $managementMock = $this->getAccessibleMock(
66 'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
67 array('downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension')
68 );
69 $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue(array()));
70 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension');
71 $extensionModelMock->_set('extensionKey', 'foobar');
72 $extensionModelMock->_set('version', '1.0.0');
73 $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility', array('buildExtensionDependenciesTree'));
74 $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
75 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
76 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('getExtensionQueue', 'addExtensionToInstallQueue'));
77 $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue(array(
78 'update' => array(
79 'foo' => $extensionModelMock
80 )
81 )));
82 $managementMock->_set('downloadQueue', $downloadQueueMock);
83 $managementMock->expects($this->once())->method('downloadDependencies')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
84 $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(array('foo' => $extensionModelMock))->will($this->returnValue(array()));
85 $managementMock->_call('resolveDependenciesAndInstall', $extensionModelMock);
86 }
87
88 /**
89 * @test
90 * @return void
91 */
92 public function downloadDependenciesCallsDownloadUtilityDownloadMethod() {
93 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
94 'dummy'
95 ));
96 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
97 $extensionModelMock->_set('extensionKey', 'foobar');
98 $extensionModelMock->_set('version', '1.0.0');
99 $downloadQueue = array(
100 $extensionModelMock
101 );
102 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
103 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
104 $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
105 $managementMock->_set('downloadUtility', $downloadUtilityMock);
106 $managementMock->_set('downloadQueue', $downloadQueueMock);
107 $managementMock->_call('downloadDependencies', $downloadQueue);
108 }
109
110 /**
111 * @test
112 * @return void
113 */
114 public function downloadDependenciesCallsRemoveExtensionFromQueue() {
115 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
116 'dummy'
117 ));
118 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
119 $extensionModelMock->_set('extensionKey', 'foobar');
120 $extensionModelMock->_set('version', '1.0.0');
121 $downloadQueue = array(
122 $extensionModelMock
123 );
124 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
125 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
126 $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
127 $managementMock->_set('downloadUtility', $downloadUtilityMock);
128 $managementMock->_set('downloadQueue', $downloadQueueMock);
129 $managementMock->_call('downloadDependencies', $downloadQueue);
130 }
131
132 /**
133 * @test
134 * @return void
135 */
136 public function downloadDependenciesReturnsResolvedDependencies() {
137 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
138 'dummy'
139 ));
140 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
141 $extensionModelMock->_set('extensionKey', 'foobar');
142 $extensionModelMock->_set('version', '1.0.0');
143 $downloadQueue = array(
144 $extensionModelMock
145 );
146 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
147 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
148 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
149 $managementMock->_set('downloadUtility', $downloadUtilityMock);
150 $managementMock->_set('downloadQueue', $downloadQueueMock);
151 $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
152 $this->assertEquals(array('downloaded' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
153 }
154
155 /**
156 * @test
157 * @return void
158 */
159 public function uninstallDependenciesToBeUpdatedCallsUninstall() {
160 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
161 'dummy'
162 ));
163 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
164 $extensionModelMock->_set('extensionKey', 'foobar');
165 $extensionModelMock->_set('version', '1.0.0');
166 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
167 $downloadQueue = array(
168 $extensionModelMock
169 );
170 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'));
171 $installUtility->expects($this->once())->method('uninstall')->with('foobar');
172 $managementMock->_set('installUtility', $installUtility);
173 $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
174 }
175
176 /**
177 * @test
178 * @return void
179 */
180 public function uninstallDependenciesToBeUpdatedReturnsResolvedDependencies() {
181 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
182 'dummy'
183 ));
184 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
185 $extensionModelMock->_set('extensionKey', 'foobar');
186 $extensionModelMock->_set('version', '1.0.0');
187 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
188 $downloadQueue = array(
189 $extensionModelMock
190 );
191 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'));
192 $managementMock->_set('installUtility', $installUtility);
193 $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
194 $this->assertEquals(array('updated' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
195 }
196
197 /**
198 * @test
199 * @return void
200 */
201 public function installDependenciesCallsInstall() {
202 $managementMock = $this->getAccessibleMock(
203 'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
204 array('dummy')
205 );
206 $installQueue = array(
207 'foobar' => array(
208 'key' => 'foobar',
209 'siteRelPath' => 'path'
210 )
211 );
212 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install'));
213 $installUtility->expects($this->once())->method('install')->with(array(
214 'key' => 'foobar',
215 'siteRelPath' => 'path'
216 ));
217 $managementMock->_set('installUtility', $installUtility);
218 $managementMock->_call('installDependencies', $installQueue);
219 }
220
221 /**
222 * @test
223 * @return void
224 */
225 public function installDependenciesReturnsResolvedDependencies() {
226 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
227 'dummy'
228 ));
229 $installQueue = array(
230 'foobar' => 'foobar'
231 );
232 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install'));
233 $installUtility->expects($this->once())->method('install')->with('foobar');
234 $managementMock->_set('installUtility', $installUtility);
235 $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
236 $this->assertEquals(array(
237 'installed' => array(
238 'foobar' => 'foobar'
239 )
240 ), $resolvedDependencies);
241 }
242
243 }