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