[BUGFIX] Add missing namespace parts
[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 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Testcase
19 *
20 */
21 class ExtensionManagementServiceTest extends \TYPO3\Components\TestingFramework\Core\Unit\UnitTestCase
22 {
23 /**
24 * @test
25 * @return void
26 */
27 public function resolveDependenciesCallsDownloadDependenciesIfDownloadKeyExistsInQueue()
28 {
29 $managementMock = $this->getAccessibleMock(
30 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
31 ['downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension', 'isAutomaticInstallationEnabled']
32 );
33 $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue([]));
34 $managementMock->expects($this->any())->method('isAutomaticInstallationEnabled')->will($this->returnValue([false]));
35 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
36 $extensionModelMock->_set('extensionKey', 'foobar');
37 $extensionModelMock->_set('version', '1.0.0');
38 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class, ['checkDependencies']);
39 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
40 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
41 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['isCopyQueueEmpty', 'isQueueEmpty', 'resetExtensionQueue', 'addExtensionToInstallQueue']);
42 $downloadQueueMock->expects($this->any())->method('isCopyQueueEmpty')->willReturn(true);
43 $downloadQueueMock->expects($this->at(1))->method('isQueueEmpty')->with('download')->willReturn(false);
44 $downloadQueueMock->expects($this->at(4))->method('isQueueEmpty')->with('download')->willReturn(true);
45 $downloadQueueMock->expects($this->at(5))->method('isQueueEmpty')->with('update')->willReturn(true);
46 $downloadQueueMock->expects($this->atLeastOnce())->method('resetExtensionQueue')->will($this->returnValue([
47 'download' => [
48 'foo' => $extensionModelMock
49 ]
50 ]));
51 $managementMock->_set('downloadQueue', $downloadQueueMock);
52 $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
53 $managementMock->_call('installExtension', $extensionModelMock);
54 }
55
56 /**
57 * @test
58 * @return void
59 */
60 public function resolveDependenciesCallsUpdateAndDownloadDependenciesIfUpdateKeyExistsInQueue()
61 {
62 $managementMock = $this->getAccessibleMock(
63 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
64 ['downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension', 'isAutomaticInstallationEnabled']
65 );
66 $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue([]));
67 $managementMock->expects($this->any())->method('isAutomaticInstallationEnabled')->will($this->returnValue(true));
68 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
69 $extensionModelMock->_set('extensionKey', 'foobar');
70 $extensionModelMock->_set('version', '1.0.0');
71 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class, ['checkDependencies']);
72 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
73 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
74 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['isCopyQueueEmpty', 'isQueueEmpty', 'resetExtensionQueue', 'addExtensionToInstallQueue']);
75 $downloadQueueMock->expects($this->any())->method('isCopyQueueEmpty')->willReturn(true);
76 $downloadQueueMock->expects($this->at(1))->method('isQueueEmpty')->with('download')->willReturn(false);
77 $downloadQueueMock->expects($this->at(4))->method('isQueueEmpty')->with('download')->willReturn(true);
78 $downloadQueueMock->expects($this->at(5))->method('isQueueEmpty')->with('update')->willReturn(true);
79 $downloadQueueMock->expects($this->atLeastOnce())->method('resetExtensionQueue')->will($this->returnValue([
80 'update' => [
81 'foo' => $extensionModelMock
82 ]
83 ]));
84 $managementMock->_set('downloadQueue', $downloadQueueMock);
85 $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
86 $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
87 $managementMock->_call('installExtension', $extensionModelMock);
88 }
89
90 /**
91 * @test
92 * @return void
93 */
94 public function downloadDependenciesCallsDownloadUtilityDownloadMethod()
95 {
96 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
97 'dummy'
98 ]);
99
100 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
101 $extensionModelMock->_set('extensionKey', 'foobar');
102 $extensionModelMock->_set('version', '1.0.0');
103
104 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
105 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
106 $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
107 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
108 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
109 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
110 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
111 $managementMock->_set('installUtility', $installUtilityMock);
112 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
113
114 $downloadQueue = [
115 $extensionModelMock
116 ];
117 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
118 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
119 $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
120 $managementMock->_set('downloadUtility', $downloadUtilityMock);
121 $managementMock->_set('downloadQueue', $downloadQueueMock);
122 $managementMock->_call('downloadDependencies', $downloadQueue);
123 }
124
125 /**
126 * @test
127 * @return void
128 */
129 public function downloadDependenciesCallsRemoveExtensionFromQueue()
130 {
131 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
132 'dummy'
133 ]);
134
135 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionModelMock */
136 $extensionModelMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
137 ->setMethods(['getExtensionKey'])
138 ->getMock();
139 $extensionModelMock->setExtensionKey('foobar');
140 $extensionModelMock->setVersion('1.0.0');
141 $downloadQueue = [
142 $extensionModelMock
143 ];
144
145 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
146 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
147 $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
148 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
149 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
150 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
151 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
152 $managementMock->_set('installUtility', $installUtilityMock);
153 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
154
155 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
156 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
157 $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
158 $managementMock->_set('downloadUtility', $downloadUtilityMock);
159 $managementMock->_set('downloadQueue', $downloadQueueMock);
160 $managementMock->_call('downloadDependencies', $downloadQueue);
161 }
162
163 /**
164 * @test
165 * @return void
166 */
167 public function downloadDependenciesReturnsResolvedDependencies()
168 {
169 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
170 'dummy'
171 ]);
172
173 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
174 $extensionModelMock->_set('extensionKey', 'foobar');
175 $extensionModelMock->_set('version', '1.0.0');
176 $downloadQueue = [
177 $extensionModelMock
178 ];
179
180 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
181 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
182 $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
183 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
184 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
185 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
186 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
187 $managementMock->_set('installUtility', $installUtilityMock);
188 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
189
190 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
191 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
192 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
193 $managementMock->_set('downloadUtility', $downloadUtilityMock);
194 $managementMock->_set('downloadQueue', $downloadQueueMock);
195 $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
196 $this->assertEquals(['downloaded' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
197 }
198
199 /**
200 * @test
201 * @return void
202 */
203 public function uninstallDependenciesToBeUpdatedCallsUninstall()
204 {
205 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
206 'dummy'
207 ]);
208 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
209 $extensionModelMock->_set('extensionKey', 'foobar');
210 $extensionModelMock->_set('version', '1.0.0');
211 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
212 $downloadQueue = [
213 $extensionModelMock
214 ];
215 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
216 $installUtility->expects($this->once())->method('uninstall')->with('foobar');
217 $managementMock->_set('installUtility', $installUtility);
218 $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
219 }
220
221 /**
222 * @test
223 * @return void
224 */
225 public function uninstallDependenciesToBeUpdatedReturnsResolvedDependencies()
226 {
227 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
228 'dummy'
229 ]);
230 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
231 $extensionModelMock->_set('extensionKey', 'foobar');
232 $extensionModelMock->_set('version', '1.0.0');
233 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
234 $downloadQueue = [
235 $extensionModelMock
236 ];
237 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
238 $managementMock->_set('installUtility', $installUtility);
239 $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
240 $this->assertEquals(['updated' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
241 }
242
243 /**
244 * @test
245 * @return void
246 */
247 public function installDependenciesCallsInstall()
248 {
249 $managementMock = $this->getAccessibleMock(
250 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
251 ['emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal']
252 );
253 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
254 $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
255 ->setMethods(['dummy'])
256 ->getMock();
257 $extensionMock->setExtensionKey('foobar');
258 $installQueue = [
259 'foobar' => $extensionMock,
260 ];
261 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
262 $installUtility->expects($this->once())->method('install')->with('foobar');
263 $managementMock->_set('installUtility', $installUtility);
264 $managementMock->_call('installDependencies', $installQueue);
265 }
266
267 /**
268 * @test
269 * @return void
270 */
271 public function installDependenciesReturnsResolvedDependencies()
272 {
273 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
274 'emitWillInstallExtensionsSignal',
275 'emitHasInstalledExtensionSignal'
276 ]);
277 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
278 $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
279 ->setMethods(['dummy'])
280 ->getMock();
281 $extensionMock->setExtensionKey('foobar');
282 $installQueue = [
283 'foobar' => $extensionMock,
284 ];
285 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
286 $installUtility->expects($this->once())->method('install')->with('foobar');
287 $managementMock->_set('installUtility', $installUtility);
288 $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
289 $this->assertEquals([
290 'installed' => [
291 'foobar' => 'foobar'
292 ]
293 ], $resolvedDependencies);
294 }
295 }