‪TYPO3CMS  11.5
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;
30 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
31 
35 class ‪ExtensionManagementServiceTest extends UnitTestCase
36 {
37  use \Prophecy\PhpUnit\ProphecyTrait;
41  protected ‪$downloadQueue;
42  protected ‪$remoteRegistry;
43  protected ‪$remote;
44  protected ‪$fileHandlingUtility;
45 
46  public function ‪setUp(): void
47  {
48  parent::setUp();
49  ‪$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['extensionmanager']['offlineMode'] = false;
50  $this->resetSingletonInstances = true;
51  $this->remoteRegistry = $this->prophesize(RemoteRegistry::class);
52  $this->remote = $this->prophesize(ExtensionDownloaderRemoteInterface::class);
53  $this->remoteRegistry->hasRemote(Argument::cetera())->willReturn(true);
54  $this->remoteRegistry->getRemote(Argument::cetera())->willReturn($this->remote->reveal());
55  $this->fileHandlingUtility = $this->prophesize(FileHandlingUtility::class);
56 
57  $this->managementService = new ‪ExtensionManagementService(
58  $this->remoteRegistry->reveal(),
59  $this->fileHandlingUtility->reveal()
60  );
61  $this->managementService->injectEventDispatcher($this->prophesize(EventDispatcherInterface::class)->reveal());
62 
63  $this->dependencyUtilityProphecy = $this->prophesize(DependencyUtility::class);
64  $this->installUtilityProphecy = $this->prophesize(InstallUtility::class);
65  $this->downloadQueue = new ‪DownloadQueue();
66 
67  $this->managementService->injectDependencyUtility($this->dependencyUtilityProphecy->reveal());
68  $this->managementService->injectInstallUtility($this->installUtilityProphecy->reveal());
69  $this->managementService->injectDownloadQueue($this->downloadQueue);
70  }
71 
75  public function ‪installDownloadsExtensionIfNecessary(): void
76  {
77  $extension = new ‪Extension();
78  $extension->setExtensionKey('foobar');
79  $extension->setVersion('1.0.0');
80  // an extension with a uid means it needs to be downloaded
81  $extension->_setProperty('uid', 123);
82  $extension->_setProperty('remote', 'ter');
83 
84  $this->managementService->installExtension($extension);
85  $this->remote->downloadExtension(
86  $extension->getExtensionKey(),
87  $extension->getVersion(),
88  $this->fileHandlingUtility,
89  $extension->getMd5hash(),
90  'Local'
91  )->shouldHaveBeenCalled();
92  }
93 
98  {
99  $extension = new Extension();
100  $this->dependencyUtilityProphecy->setSkipDependencyCheck(false)->willReturn();
101  $this->dependencyUtilityProphecy->checkDependencies($extension)->willReturn();
102 
103  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(true);
104 
105  $result = $this->managementService->installExtension($extension);
106  self::assertFalse($result);
107  }
108 
113  {
114  $extension = new Extension();
115  $extension->setExtensionKey('foo');
116 
117  $result = $this->managementService->installExtension($extension);
118  self::assertSame(['installed' => ['foo' => 'foo']], $result);
119  }
120 
125  {
126  ‪$downloadQueue = new DownloadQueue();
127  $extension = new Extension();
128  $extension->setExtensionKey('foo');
129  $extension->_setProperty('remote', 'ter');
130  ‪$downloadQueue->addExtensionToQueue($extension);
131  $this->managementService->injectDownloadQueue(‪$downloadQueue);
132  $this->installUtilityProphecy->enrichExtensionWithDetails('foo')->willReturn([
133  'key' => 'foo',
134  'remote' => 'ter',
135  ]);
136  $this->installUtilityProphecy->reloadAvailableExtensions()->willReturn();
137  $this->installUtilityProphecy->install('foo')->willReturn();
138 
139  $result = $this->managementService->installExtension($extension);
140  self::assertSame(['downloaded' => ['foo' => $extension], 'installed' => ['foo' => 'foo']], $result);
141  }
142 
146  public function ‪installExtensionWillReturnUpdatedExtensions(): void
147  {
148  ‪$downloadQueue = new DownloadQueue();
149  $extension = new Extension();
150  $extension->setExtensionKey('foo');
151  $extension->_setProperty('remote', 'ter');
152  ‪$downloadQueue->addExtensionToQueue($extension, 'update');
153  $this->managementService->injectDownloadQueue(‪$downloadQueue);
154  $this->installUtilityProphecy->enrichExtensionWithDetails('foo')->willReturn([
155  'key' => 'foo',
156  'remote' => 'ter',
157  ]);
158  $this->installUtilityProphecy->reloadAvailableExtensions()->willReturn();
159 
160  // an extension update will uninstall the extension and install it again
161  $this->installUtilityProphecy->uninstall('foo')->shouldBeCalled();
162  $this->installUtilityProphecy->install('foo')->shouldBeCalled();
163 
164  $result = $this->managementService->installExtension($extension);
165 
166  self::assertSame(['updated' => ['foo' => $extension], 'installed' => ['foo' => 'foo']], $result);
167  }
168 
173  {
174  $extension = new Extension();
175  $extension->setExtensionKey('foo');
176  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(false);
177  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldBeCalled();
178 
179  $this->managementService->markExtensionForDownload($extension);
180 
181  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldHaveBeenCalled();
182  self::assertSame(['download' => ['foo' => $extension]], $this->downloadQueue->getExtensionQueue());
183  }
184 
189  {
190  $extension = new Extension();
191  $extension->setExtensionKey('foo');
192  $this->dependencyUtilityProphecy->hasDependencyErrors()->willReturn(false);
193  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldBeCalled();
194 
195  $this->managementService->markExtensionForUpdate($extension);
196 
197  $this->dependencyUtilityProphecy->checkDependencies($extension)->shouldHaveBeenCalled();
198  self::assertSame(['update' => ['foo' => $extension]], $this->downloadQueue->getExtensionQueue());
199  }
200 }
‪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:37
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnDownloadedExtensions
‪installExtensionWillReturnDownloadedExtensions()
Definition: ExtensionManagementServiceTest.php:123
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:28
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnUpdatedExtensions
‪installExtensionWillReturnUpdatedExtensions()
Definition: ExtensionManagementServiceTest.php:145
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionWillReturnInstalledExtensions
‪installExtensionWillReturnInstalledExtensions()
Definition: ExtensionManagementServiceTest.php:111
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest
Definition: ExtensionManagementServiceTest.php:36
‪TYPO3\CMS\Extensionmanager\Domain\Model\DownloadQueue
Definition: DownloadQueue.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$fileHandlingUtility
‪$fileHandlingUtility
Definition: ExtensionManagementServiceTest.php:43
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installDownloadsExtensionIfNecessary
‪installDownloadsExtensionIfNecessary()
Definition: ExtensionManagementServiceTest.php:74
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$installUtilityProphecy
‪$installUtilityProphecy
Definition: ExtensionManagementServiceTest.php:39
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:36
‪TYPO3\CMS\Extensionmanager\Utility\InstallUtility
Definition: InstallUtility.php:56
‪TYPO3\CMS\Extensionmanager\Utility\DependencyUtility
Definition: DependencyUtility.php:35
‪TYPO3\CMS\Extensionmanager\Remote\ExtensionDownloaderRemoteInterface
Definition: ExtensionDownloaderRemoteInterface.php:28
‪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:45
‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
Definition: ExtensionManagementService.php:36
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$remote
‪$remote
Definition: ExtensionManagementServiceTest.php:42
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\$remoteRegistry
‪$remoteRegistry
Definition: ExtensionManagementServiceTest.php:41
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\markExtensionForUpdateAddsExtensionToUpdateQueueAndChecksDependencies
‪markExtensionForUpdateAddsExtensionToUpdateQueueAndChecksDependencies()
Definition: ExtensionManagementServiceTest.php:187
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\installExtensionReturnsFalseIfDependenciesCannotBeResolved
‪installExtensionReturnsFalseIfDependenciesCannotBeResolved()
Definition: ExtensionManagementServiceTest.php:96
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service
Definition: ExtensionManagementServiceTest.php:18
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Service\ExtensionManagementServiceTest\markExtensionForDownloadAddsExtensionToDownloadQueueAndChecksDependencies
‪markExtensionForDownloadAddsExtensionToDownloadQueueAndChecksDependencies()
Definition: ExtensionManagementServiceTest.php:171
‪TYPO3\CMS\Extensionmanager\Remote\RemoteRegistry
Definition: RemoteRegistry.php:26