e2af8105032af5c7a0f0f8b10eabbb2b49056eaf
[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\CMS\Core\Tests\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, ['getExtensionQueue', 'addExtensionToInstallQueue']);
42 $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue([
43 'download' => [
44 'foo' => $extensionModelMock
45 ]
46 ]));
47 $managementMock->_set('downloadQueue', $downloadQueueMock);
48 $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
49 $managementMock->_call('installExtension', $extensionModelMock);
50 }
51
52 /**
53 * @test
54 * @return void
55 */
56 public function resolveDependenciesCallsUpdateAndDownloadDependenciesIfUpdateKeyExistsInQueue()
57 {
58 $managementMock = $this->getAccessibleMock(
59 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
60 ['downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension', 'isAutomaticInstallationEnabled']
61 );
62 $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue([]));
63 $managementMock->expects($this->any())->method('isAutomaticInstallationEnabled')->will($this->returnValue(true));
64 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
65 $extensionModelMock->_set('extensionKey', 'foobar');
66 $extensionModelMock->_set('version', '1.0.0');
67 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class, ['checkDependencies']);
68 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
69 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
70 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['getExtensionQueue', 'addExtensionToInstallQueue']);
71 $downloadQueueMock->expects($this->atLeastOnce())->method('getExtensionQueue')->will($this->returnValue([
72 'update' => [
73 'foo' => $extensionModelMock
74 ]
75 ]));
76 $managementMock->_set('downloadQueue', $downloadQueueMock);
77 $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
78 $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
79 $managementMock->_call('installExtension', $extensionModelMock);
80 }
81
82 /**
83 * @test
84 * @return void
85 */
86 public function downloadDependenciesCallsDownloadUtilityDownloadMethod()
87 {
88 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
89 'dummy'
90 ]);
91
92 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
93 $extensionModelMock->_set('extensionKey', 'foobar');
94 $extensionModelMock->_set('version', '1.0.0');
95
96 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
97 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
98 $installUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class);
99 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
100 $extensionModelUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class);
101 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
102 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
103 $managementMock->_set('installUtility', $installUtilityMock);
104 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
105
106 $downloadQueue = [
107 $extensionModelMock
108 ];
109 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
110 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
111 $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
112 $managementMock->_set('downloadUtility', $downloadUtilityMock);
113 $managementMock->_set('downloadQueue', $downloadQueueMock);
114 $managementMock->_call('downloadDependencies', $downloadQueue);
115 }
116
117 /**
118 * @test
119 * @return void
120 */
121 public function downloadDependenciesCallsRemoveExtensionFromQueue()
122 {
123 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
124 'dummy'
125 ]);
126
127 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionModelMock */
128 $extensionModelMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
129 $extensionModelMock->setExtensionKey('foobar');
130 $extensionModelMock->setVersion('1.0.0');
131 $downloadQueue = [
132 $extensionModelMock
133 ];
134
135 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
136 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
137 $installUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class);
138 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
139 $extensionModelUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class);
140 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
141 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
142 $managementMock->_set('installUtility', $installUtilityMock);
143 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
144
145 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
146 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
147 $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
148 $managementMock->_set('downloadUtility', $downloadUtilityMock);
149 $managementMock->_set('downloadQueue', $downloadQueueMock);
150 $managementMock->_call('downloadDependencies', $downloadQueue);
151 }
152
153 /**
154 * @test
155 * @return void
156 */
157 public function downloadDependenciesReturnsResolvedDependencies()
158 {
159 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
160 'dummy'
161 ]);
162
163 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
164 $extensionModelMock->_set('extensionKey', 'foobar');
165 $extensionModelMock->_set('version', '1.0.0');
166 $downloadQueue = [
167 $extensionModelMock
168 ];
169
170 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
171 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
172 $installUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class);
173 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
174 $extensionModelUtilityMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class);
175 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
176 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
177 $managementMock->_set('installUtility', $installUtilityMock);
178 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
179
180 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
181 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
182 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
183 $managementMock->_set('downloadUtility', $downloadUtilityMock);
184 $managementMock->_set('downloadQueue', $downloadQueueMock);
185 $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
186 $this->assertEquals(['downloaded' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
187 }
188
189 /**
190 * @test
191 * @return void
192 */
193 public function uninstallDependenciesToBeUpdatedCallsUninstall()
194 {
195 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
196 'dummy'
197 ]);
198 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
199 $extensionModelMock->_set('extensionKey', 'foobar');
200 $extensionModelMock->_set('version', '1.0.0');
201 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
202 $downloadQueue = [
203 $extensionModelMock
204 ];
205 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
206 $installUtility->expects($this->once())->method('uninstall')->with('foobar');
207 $managementMock->_set('installUtility', $installUtility);
208 $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
209 }
210
211 /**
212 * @test
213 * @return void
214 */
215 public function uninstallDependenciesToBeUpdatedReturnsResolvedDependencies()
216 {
217 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
218 'dummy'
219 ]);
220 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['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 = [
225 $extensionModelMock
226 ];
227 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
228 $managementMock->_set('installUtility', $installUtility);
229 $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
230 $this->assertEquals(['updated' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
231 }
232
233 /**
234 * @test
235 * @return void
236 */
237 public function installDependenciesCallsInstall()
238 {
239 $managementMock = $this->getAccessibleMock(
240 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
241 ['emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal']
242 );
243 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
244 $extensionMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['dummy']);
245 $extensionMock->setExtensionKey('foobar');
246 $installQueue = [
247 'foobar' => $extensionMock,
248 ];
249 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
250 $installUtility->expects($this->once())->method('install')->with('foobar');
251 $managementMock->_set('installUtility', $installUtility);
252 $managementMock->_call('installDependencies', $installQueue);
253 }
254
255 /**
256 * @test
257 * @return void
258 */
259 public function installDependenciesReturnsResolvedDependencies()
260 {
261 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
262 'emitWillInstallExtensionsSignal',
263 'emitHasInstalledExtensionSignal'
264 ]);
265 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
266 $extensionMock = $this->getMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['dummy']);
267 $extensionMock->setExtensionKey('foobar');
268 $installQueue = [
269 'foobar' => $extensionMock,
270 ];
271 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
272 $installUtility->expects($this->once())->method('install')->with('foobar');
273 $managementMock->_set('installUtility', $installUtility);
274 $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
275 $this->assertEquals([
276 'installed' => [
277 'foobar' => 'foobar'
278 ]
279 ], $resolvedDependencies);
280 }
281 }