[BUGFIX] Fix tests according to changes in #57199
[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\Core\Tests\UnitTestCase {
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
97 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
98 $extensionModelMock->_set('extensionKey', 'foobar');
99 $extensionModelMock->_set('version', '1.0.0');
100
101 $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
102 $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
103 $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
104 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
105 $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
106 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
107 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
108 $managementMock->_set('installUtility', $installUtilityMock);
109 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
110
111 $downloadQueue = array(
112 $extensionModelMock
113 );
114 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
115 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
116 $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
117 $managementMock->_set('downloadUtility', $downloadUtilityMock);
118 $managementMock->_set('downloadQueue', $downloadQueueMock);
119 $managementMock->_call('downloadDependencies', $downloadQueue);
120 }
121
122 /**
123 * @test
124 * @return void
125 */
126 public function downloadDependenciesCallsRemoveExtensionFromQueue() {
127 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
128 'dummy'
129 ));
130
131 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
132 $extensionModelMock->_set('extensionKey', 'foobar');
133 $extensionModelMock->_set('version', '1.0.0');
134 $downloadQueue = array(
135 $extensionModelMock
136 );
137
138 $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
139 $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
140 $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
141 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
142 $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
143 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
144 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
145 $managementMock->_set('installUtility', $installUtilityMock);
146 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
147
148 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
149 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
150 $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
151 $managementMock->_set('downloadUtility', $downloadUtilityMock);
152 $managementMock->_set('downloadQueue', $downloadQueueMock);
153 $managementMock->_call('downloadDependencies', $downloadQueue);
154 }
155
156 /**
157 * @test
158 * @return void
159 */
160 public function downloadDependenciesReturnsResolvedDependencies() {
161 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
162 'dummy'
163 ));
164
165 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
166 $extensionModelMock->_set('extensionKey', 'foobar');
167 $extensionModelMock->_set('version', '1.0.0');
168 $downloadQueue = array(
169 $extensionModelMock
170 );
171
172 $dependencyUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DependencyUtility');
173 $dependencyUtilityMock->expects($this->atLeastOnce())->method('buildExtensionDependenciesTree');
174 $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility');
175 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue(array()));
176 $extensionModelUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\ExtensionModelUtility');
177 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
178 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
179 $managementMock->_set('installUtility', $installUtilityMock);
180 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
181
182 $downloadQueueMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\DownloadQueue', array('removeExtensionFromQueue', 'addExtensionToInstallQueue'));
183 $downloadUtilityMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\DownloadUtility', array('download'));
184 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
185 $managementMock->_set('downloadUtility', $downloadUtilityMock);
186 $managementMock->_set('downloadQueue', $downloadQueueMock);
187 $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
188 $this->assertEquals(array('downloaded' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
189 }
190
191 /**
192 * @test
193 * @return void
194 */
195 public function uninstallDependenciesToBeUpdatedCallsUninstall() {
196 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
197 'dummy'
198 ));
199 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
200 $extensionModelMock->_set('extensionKey', 'foobar');
201 $extensionModelMock->_set('version', '1.0.0');
202 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
203 $downloadQueue = array(
204 $extensionModelMock
205 );
206 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
207 $installUtility->expects($this->once())->method('uninstall')->with('foobar');
208 $managementMock->_set('installUtility', $installUtility);
209 $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
210 }
211
212 /**
213 * @test
214 * @return void
215 */
216 public function uninstallDependenciesToBeUpdatedReturnsResolvedDependencies() {
217 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
218 'dummy'
219 ));
220 $extensionModelMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Domain\\Model\\Extension', array('getExtensionKey'));
221 $extensionModelMock->_set('extensionKey', 'foobar');
222 $extensionModelMock->_set('version', '1.0.0');
223 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
224 $downloadQueue = array(
225 $extensionModelMock
226 );
227 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('uninstall'), array(), '', FALSE);
228 $managementMock->_set('installUtility', $installUtility);
229 $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
230 $this->assertEquals(array('updated' => array('foobar' => $extensionModelMock)), $resolvedDependencies);
231 }
232
233 /**
234 * @test
235 * @return void
236 */
237 public function installDependenciesCallsInstall() {
238 $managementMock = $this->getAccessibleMock(
239 'TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService',
240 array('emitWillInstallExtensions', 'emitHasInstalledExtension')
241 );
242 $installQueue = array(
243 'foobar' => array(
244 'key' => 'foobar',
245 'siteRelPath' => 'path'
246 )
247 );
248 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensions'), array(), '', FALSE);
249 $installUtility->expects($this->once())->method('install')->with(array(
250 'key' => 'foobar',
251 'siteRelPath' => 'path'
252 ));
253 $managementMock->_set('installUtility', $installUtility);
254 $managementMock->_call('installDependencies', $installQueue);
255 }
256
257 /**
258 * @test
259 * @return void
260 */
261 public function installDependenciesReturnsResolvedDependencies() {
262 $managementMock = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Service\\ExtensionManagementService', array(
263 'emitWillInstallExtensions',
264 'emitHasInstalledExtension'
265 ));
266 $installQueue = array(
267 'foobar' => 'foobar'
268 );
269 $installUtility = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array('install','emitWillInstallExtensions'), array(), '', FALSE);
270 $installUtility->expects($this->once())->method('install')->with('foobar');
271 $managementMock->_set('installUtility', $installUtility);
272 $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
273 $this->assertEquals(array(
274 'installed' => array(
275 'foobar' => 'foobar'
276 )
277 ), $resolvedDependencies);
278 }
279
280 }