TYPO3 CMS  TYPO3_8-7
ExtensionManagementServiceTest.php
Go to the documentation of this file.
1 <?php
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 
20 class ExtensionManagementServiceTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
26  {
27  $managementMock = $this->getAccessibleMock(
28  \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
29  ['downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension', 'isAutomaticInstallationEnabled']
30  );
31  $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue([]));
32  $managementMock->expects($this->any())->method('isAutomaticInstallationEnabled')->will($this->returnValue([false]));
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, ['checkDependencies']);
37  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
38  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
39  $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['isCopyQueueEmpty', 'isQueueEmpty', 'resetExtensionQueue', 'addExtensionToInstallQueue']);
40  $downloadQueueMock->expects($this->any())->method('isCopyQueueEmpty')->willReturn(true);
41  $downloadQueueMock->expects($this->at(1))->method('isQueueEmpty')->with('download')->willReturn(false);
42  $downloadQueueMock->expects($this->at(4))->method('isQueueEmpty')->with('download')->willReturn(true);
43  $downloadQueueMock->expects($this->at(5))->method('isQueueEmpty')->with('update')->willReturn(true);
44  $downloadQueueMock->expects($this->atLeastOnce())->method('resetExtensionQueue')->will($this->returnValue([
45  'download' => [
46  'foo' => $extensionModelMock
47  ]
48  ]));
49  $managementMock->_set('downloadQueue', $downloadQueueMock);
50  $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
51  $managementMock->_call('installExtension', $extensionModelMock);
52  }
53 
58  {
59  $managementMock = $this->getAccessibleMock(
60  \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
61  ['downloadDependencies', 'uninstallDependenciesToBeUpdated', 'setInExtensionRepository', 'downloadMainExtension', 'isAutomaticInstallationEnabled']
62  );
63  $managementMock->expects($this->any())->method('downloadMainExtension')->will($this->returnValue([]));
64  $managementMock->expects($this->any())->method('isAutomaticInstallationEnabled')->will($this->returnValue(true));
65  $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class);
66  $extensionModelMock->_set('extensionKey', 'foobar');
67  $extensionModelMock->_set('version', '1.0.0');
68  $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class, ['checkDependencies']);
69  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
70  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
71  $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['isCopyQueueEmpty', 'isQueueEmpty', 'resetExtensionQueue', 'addExtensionToInstallQueue']);
72  $downloadQueueMock->expects($this->any())->method('isCopyQueueEmpty')->willReturn(true);
73  $downloadQueueMock->expects($this->at(1))->method('isQueueEmpty')->with('download')->willReturn(false);
74  $downloadQueueMock->expects($this->at(4))->method('isQueueEmpty')->with('download')->willReturn(true);
75  $downloadQueueMock->expects($this->at(5))->method('isQueueEmpty')->with('update')->willReturn(true);
76  $downloadQueueMock->expects($this->atLeastOnce())->method('resetExtensionQueue')->will($this->returnValue([
77  'update' => [
78  'foo' => $extensionModelMock
79  ]
80  ]));
81  $managementMock->_set('downloadQueue', $downloadQueueMock);
82  $managementMock->expects($this->once())->method('downloadDependencies')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
83  $managementMock->expects($this->once())->method('uninstallDependenciesToBeUpdated')->with(['foo' => $extensionModelMock])->will($this->returnValue([]));
84  $managementMock->_call('installExtension', $extensionModelMock);
85  }
86 
91  {
92  $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
93  'dummy'
94  ]);
95 
96  $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
97  $extensionModelMock->_set('extensionKey', 'foobar');
98  $extensionModelMock->_set('version', '1.0.0');
99 
100  $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
101  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
102  $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
103  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
104  $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
105  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
106  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
107  $managementMock->_set('installUtility', $installUtilityMock);
108  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
109 
110  $downloadQueue = [
111  $extensionModelMock
112  ];
113  $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
114  $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
115  $downloadUtilityMock->expects($this->once())->method('download')->with($extensionModelMock);
116  $managementMock->_set('downloadUtility', $downloadUtilityMock);
117  $managementMock->_set('downloadQueue', $downloadQueueMock);
118  $managementMock->_call('downloadDependencies', $downloadQueue);
119  }
120 
124  public function downloadDependenciesCallsRemoveExtensionFromQueue()
125  {
126  $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
127  'dummy'
128  ]);
129 
131  $extensionModelMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
132  ->setMethods(['getExtensionKey'])
133  ->getMock();
134  $extensionModelMock->setExtensionKey('foobar');
135  $extensionModelMock->setVersion('1.0.0');
136  $downloadQueue = [
137  $extensionModelMock
138  ];
139 
140  $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
141  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
142  $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
143  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
144  $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
145  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
146  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
147  $managementMock->_set('installUtility', $installUtilityMock);
148  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
149 
150  $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
151  $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
152  $downloadQueueMock->expects($this->once())->method('removeExtensionFromQueue')->with($extensionModelMock);
153  $managementMock->_set('downloadUtility', $downloadUtilityMock);
154  $managementMock->_set('downloadQueue', $downloadQueueMock);
155  $managementMock->_call('downloadDependencies', $downloadQueue);
156  }
157 
162  {
163  $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
164  'dummy'
165  ]);
166 
167  $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
168  $extensionModelMock->_set('extensionKey', 'foobar');
169  $extensionModelMock->_set('version', '1.0.0');
170  $downloadQueue = [
171  $extensionModelMock
172  ];
173 
174  $dependencyUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DependencyUtility::class);
175  $dependencyUtilityMock->expects($this->atLeastOnce())->method('checkDependencies');
176  $installUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class)->getMock();
177  $installUtilityMock->expects($this->any())->method('enrichExtensionWithDetails')->will($this->returnValue([]));
178  $extensionModelUtilityMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility::class)->getMock();
179  $extensionModelUtilityMock->expects($this->any())->method('mapExtensionArrayToModel')->will($this->returnValue($extensionModelMock));
180  $managementMock->_set('dependencyUtility', $dependencyUtilityMock);
181  $managementMock->_set('installUtility', $installUtilityMock);
182  $managementMock->_set('extensionModelUtility', $extensionModelUtilityMock);
183 
184  $downloadQueueMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue::class, ['removeExtensionFromQueue', 'addExtensionToInstallQueue']);
185  $downloadUtilityMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\DownloadUtility::class, ['download']);
186  $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
187  $managementMock->_set('downloadUtility', $downloadUtilityMock);
188  $managementMock->_set('downloadQueue', $downloadQueueMock);
189  $resolvedDependencies = $managementMock->_call('downloadDependencies', $downloadQueue);
190  $this->assertEquals(['downloaded' => ['foobar' => $extensionModelMock]], $resolvedDependencies);
191  }
192 
197  {
198  $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
199  'dummy'
200  ]);
201  $extensionModelMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class, ['getExtensionKey']);
202  $extensionModelMock->_set('extensionKey', 'foobar');
203  $extensionModelMock->_set('version', '1.0.0');
204  $extensionModelMock->expects($this->atLeastOnce())->method('getExtensionKey')->will($this->returnValue('foobar'));
205  $downloadQueue = [
206  $extensionModelMock
207  ];
208  $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['uninstall'], [], '', false);
209  $installUtility->expects($this->once())->method('uninstall')->with('foobar');
210  $managementMock->_set('installUtility', $installUtility);
211  $managementMock->_call('uninstallDependenciesToBeUpdated', $downloadQueue);
212  }
213 
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 
238  public function installDependenciesCallsInstall()
239  {
240  $managementMock = $this->getAccessibleMock(
241  \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class,
242  ['emitWillInstallExtensionsSignal', 'emitHasInstalledExtensionSignal']
243  );
245  $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
246  ->setMethods(['dummy'])
247  ->getMock();
248  $extensionMock->setExtensionKey('foobar');
249  $installQueue = [
250  'foobar' => $extensionMock,
251  ];
252  $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
253  $installUtility->expects($this->once())->method('install')->with('foobar');
254  $managementMock->_set('installUtility', $installUtility);
255  $managementMock->_call('installDependencies', $installQueue);
256  }
257 
261  public function installDependenciesReturnsResolvedDependencies()
262  {
263  $managementMock = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class, [
264  'emitWillInstallExtensionsSignal',
265  'emitHasInstalledExtensionSignal'
266  ]);
268  $extensionMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Domain\Model\Extension::class)
269  ->setMethods(['dummy'])
270  ->getMock();
271  $extensionMock->setExtensionKey('foobar');
272  $installQueue = [
273  'foobar' => $extensionMock,
274  ];
275  $installUtility = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Utility\InstallUtility::class, ['install', 'emitWillInstallExtensionsSignal'], [], '', false);
276  $installUtility->expects($this->once())->method('install')->with('foobar');
277  $managementMock->_set('installUtility', $installUtility);
278  $resolvedDependencies = $managementMock->_call('installDependencies', $installQueue);
279  $this->assertEquals([
280  'installed' => [
281  'foobar' => 'foobar'
282  ]
283  ], $resolvedDependencies);
284  }
285 }