‪TYPO3CMS  10.4
ExtensionManagementServiceTest.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Prophecy\Argument;
21 use Psr\EventDispatcher\EventDispatcherInterface;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
30 
34 class ‪ExtensionManagementServiceTest extends UnitTestCase
35 {
40  protected ‪$downloadQueue;
42 
43  public function ‪setUp(): void
44  {
45  parent::setUp();
46  $this->resetSingletonInstances = true;
47  $this->managementService = new ‪ExtensionManagementService();
48  $this->managementService->injectEventDispatcher($this->prophesize(EventDispatcherInterface::class)->reveal());
49 
50  $this->downloadUtilityProphecy = $this->prophesize(DownloadUtility::class);
51  $this->dependencyUtilityProphecy = $this->prophesize(DependencyUtility::class);
52  $this->installUtilityProphecy = $this->prophesize(InstallUtility::class);
53  $this->downloadQueue = new ‪DownloadQueue();
54  $this->extensionModelUtilityProphecy = $this->prophesize(ExtensionModelUtility::class);
55 
56  $this->managementService->injectDependencyUtility($this->dependencyUtilityProphecy->reveal());
57  $this->managementService->injectDownloadUtility($this->downloadUtilityProphecy->reveal());
58  $this->managementService->injectInstallUtility($this->installUtilityProphecy->reveal());
59  $this->managementService->injectDownloadQueue($this->downloadQueue);
60  $this->managementService->injectExtensionModelUtility($this->extensionModelUtilityProphecy->reveal());
61  }
62 
67  {
68  $extension = new ‪Extension();
69  $extension->setExtensionKey('foobar');
70  $extension->setVersion('1.0.0');
71  // an extension with a uid means it needs to be downloaded
72  $extension->_setProperty('uid', 123);
73 
74  $this->managementService->installExtension($extension);
75  $this->downloadUtilityProphecy->download($extension)->shouldHaveBeenCalled();
76  }
77 
82  {
83  $extension = new ‪Extension();
84  $this->dependencyUtilityProphecy->setLocalExtensionStorage(Argument::any())->willReturn();
85  $this->dependencyUtilityProphecy->setSkipDependencyCheck(false)->willReturn();
86  $this->dependencyUtilityProphecy->checkDependencies($extension)->willReturn();
87 
88  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(true);
89 
90  $result = $this->managementService->installExtension($extension);
91  self::assertFalse($result);
92  }
93 
98  {
99  $extension = new ‪Extension();
100  $extension->setExtensionKey('foo');
101 
102  $result = $this->managementService->installExtension($extension);
103  self::assertSame(['installed' => ['foo' => 'foo']], $result);
104  }
105 
110  {
112  $extension = new ‪Extension();
113  $extension->setExtensionKey('foo');
114  ‪$downloadQueue->addExtensionToQueue($extension);
115  $this->managementService->injectDownloadQueue(‪$downloadQueue);
116  $this->installUtilityProphecy->enrichExtensionWithDetails('foo')->willReturn([]);
117  $this->installUtilityProphecy->reloadAvailableExtensions()->willReturn();
118  $this->installUtilityProphecy->install('foo')->willReturn();
119  $this->extensionModelUtilityProphecy->mapExtensionArrayToModel([])->willReturn($extension);
120 
121  $result = $this->managementService->installExtension($extension);
122  self::assertSame(['downloaded' => ['foo' => $extension], 'installed' => ['foo' => 'foo']], $result);
123  }
124 
129  {
131  $extension = new ‪Extension();
132  $extension->setExtensionKey('foo');
133  ‪$downloadQueue->addExtensionToQueue($extension, 'update');
134  $this->managementService->injectDownloadQueue(‪$downloadQueue);
135  $this->installUtilityProphecy->enrichExtensionWithDetails('foo')->willReturn([]);
136  $this->installUtilityProphecy->reloadAvailableExtensions()->willReturn();
137  $this->extensionModelUtilityProphecy->mapExtensionArrayToModel([])->willReturn($extension);
138 
139  // an extension update will uninstall the extension and install it again
140  $this->installUtilityProphecy->uninstall('foo')->shouldBeCalled();
141  $this->installUtilityProphecy->install('foo')->shouldBeCalled();
142 
143  $result = $this->managementService->installExtension($extension);
144 
145  self::assertSame(['updated' => ['foo' => $extension], 'installed' => ['foo' => 'foo']], $result);
146  }
147 
152  {
153  $this->managementService->markExtensionForCopy('ext', 'some/folder/');
154 
155  self::assertSame(['ext' => 'some/folder/'], $this->downloadQueue->resetExtensionCopyStorage());
156  }
157 
162  {
163  $extension = new ‪Extension();
164  $extension->setExtensionKey('foo');
165  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(false);
166  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldBeCalled();
167 
168  $this->managementService->markExtensionForDownload($extension);
169 
170  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldHaveBeenCalled();
171  self::assertSame(['download' => ['foo' => $extension]], $this->downloadQueue->getExtensionQueue());
172  }
173 
178  {
179  $extension = new ‪Extension();
180  $extension->setExtensionKey('foo');
181  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(false);
182  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldBeCalled();
183 
184  $this->managementService->markExtensionForUpdate($extension);
185 
186  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldHaveBeenCalled();
187  self::assertSame(['update' => ['foo' => $extension]], $this->downloadQueue->getExtensionQueue());
188  }
189 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$downloadQueue
‪$downloadQueue
Definition: ExtensionManagementServiceTest.php:40
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$managementService
‪$managementService
Definition: ExtensionManagementServiceTest.php:36
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnDownloadedExtensions
‪installExtensionWillReturnDownloadedExtensions()
Definition: ExtensionManagementServiceTest.php:109
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnUpdatedExtensions
‪installExtensionWillReturnUpdatedExtensions()
Definition: ExtensionManagementServiceTest.php:128
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnInstalledExtensions
‪installExtensionWillReturnInstalledExtensions()
Definition: ExtensionManagementServiceTest.php:97
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest
Definition: ExtensionManagementServiceTest.php:35
‪TYPO3\CMS\Extensionmanager\Utility\ExtensionModelUtility
Definition: ExtensionModelUtility.php:28
‪TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue
Definition: DownloadQueue.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installDownloadsExtensionIfNecessary
‪installDownloadsExtensionIfNecessary()
Definition: ExtensionManagementServiceTest.php:66
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\markExtensionForCopyAddsExtensionToCopyQueue
‪markExtensionForCopyAddsExtensionToCopyQueue()
Definition: ExtensionManagementServiceTest.php:151
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$installUtilityProphecy
‪$installUtilityProphecy
Definition: ExtensionManagementServiceTest.php:39
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$downloadUtilityProphecy
‪$downloadUtilityProphecy
Definition: ExtensionManagementServiceTest.php:37
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:55
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:38
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$dependencyUtilityProphecy
‪$dependencyUtilityProphecy
Definition: ExtensionManagementServiceTest.php:38
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\setUp
‪setUp()
Definition: ExtensionManagementServiceTest.php:43
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$extensionModelUtilityProphecy
‪$extensionModelUtilityProphecy
Definition: ExtensionManagementServiceTest.php:41
‪TYPO3\CMS\Extensionmanager\Utility\DownloadUtility
Definition: DownloadUtility.php:29
‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
Definition: ExtensionManagementService.php:33
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\markExtensionForUpdateAddsExtensionToUpdateQueueAndChecksDependencies
‪markExtensionForUpdateAddsExtensionToUpdateQueueAndChecksDependencies()
Definition: ExtensionManagementServiceTest.php:177
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionReturnsFalseIfDependenciesCannotBeResolved
‪installExtensionReturnsFalseIfDependenciesCannotBeResolved()
Definition: ExtensionManagementServiceTest.php:81
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service
Definition: ExtensionManagementServiceTest.php:18
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\markExtensionForDownloadAddsExtensionToDownloadQueueAndChecksDependencies
‪markExtensionForDownloadAddsExtensionToDownloadQueueAndChecksDependencies()
Definition: ExtensionManagementServiceTest.php:161