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