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