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