eff4fe9840261091438c3c5be939779e7277618f
[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->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
99 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
100 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
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->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
129 ->setMethods(['getExtensionKey'])
130 ->getMock();
131 $extensionModelMock->setExtensionKey('foobar');
132 $extensionModelMock->setVersion('1.0.0');
133 $downloadQueue = [
134 $extensionModelMock
135 ];
136
137 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
138 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
139 $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
140 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
141 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
142 $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
143 $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
144 $managementMock->_set('installUtility', $installUtilityMock);
145 $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
146
147 $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
148 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
149 $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
150 $managementMock->_set('downloadUtility', $downloadUtilityMock);
151 $managementMock->_set('downloadQueue', $downloadQueueMock);
152 $managementMock->_call('downloadDependencies', $downloadQueue);
153 }
154
155 /**
156 * @test
157 * @return void
158 */
159 public function downloadDependenciesReturnsResolvedDependencies()
160 {
161 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
162 'dummy'
163 ]);
164
165 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
166 $extensionModelMock->_set('extensionKey', 'foobar');
167 $extensionModelMock->_set('version', '1.0.0');
168 $downloadQueue = [
169 $extensionModelMock
170 ];
171
172 $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
173 $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
174 $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
175 $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
176 $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
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::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
183 $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['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(['downloaded' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
189 }
190
191 /**
192 * @test
193 * @return void
194 */
195 public function uninstallDependenciesToBeUpdatedCallsUninstall()
196 {
197 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
198 'dummy'
199 ]);
200 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['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 = [
205 $extensionModelMock
206 ];
207 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', 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 {
219 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
220 'dummy'
221 ]);
222 $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
223 $extensionModelMock->_set('extensionKey', 'foobar');
224 $extensionModelMock->_set('version', '1.0.0');
225 $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
226 $downloadQueue = [
227 $extensionModelMock
228 ];
229 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
230 $managementMock->_set('installUtility', $installUtility);
231 $resolvedDependencies = $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
232 $this->assertEquals(['updated' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
233 }
234
235 /**
236 * @test
237 * @return void
238 */
239 public function installDependenciesCallsInstall()
240 {
241 $managementMock = $this->getAccessibleMock(
242 \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
243 ['emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal']
244 );
245 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
246 $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
247 ->setMethods(['dummy'])
248 ->getMock();
249 $extensionMock->setExtensionKey('foobar');
250 $installQueue = [
251 'foobar' => $extensionMock,
252 ];
253 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
254 $installUtility->expects($this->once())->method('install')->with('foobar');
255 $managementMock->_set('installUtility', $installUtility);
256 $managementMock->_call('installDependencies', $installQueue);
257 }
258
259 /**
260 * @test
261 * @return void
262 */
263 public function installDependenciesReturnsResolvedDependencies()
264 {
265 $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
266 'emitWillInstallExtensionsSignal',
267 'emitHasInstalledExtensionSignal'
268 ]);
269 /** @var \TYPO3\CMS\Extensionmanager\Domain\Model\Extension $extensionMock */
270 $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
271 ->setMethods(['dummy'])
272 ->getMock();
273 $extensionMock->setExtensionKey('foobar');
274 $installQueue = [
275 'foobar' => $extensionMock,
276 ];
277 $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
278 $installUtility->expects($this->once())->method('install')->with('foobar');
279 $managementMock->_set('installUtility', $installUtility);
280 $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
281 $this->assertEquals([
282 'installed' => [
283 'foobar' => 'foobar'
284 ]
285 ], $resolvedDependencies);
286 }
287 }