‪TYPO3CMS  10.4
ExtensionStatusTest.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;
33 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
34 
38 class ‪ExtensionStatusTest extends UnitTestCase
39 {
43  protected ‪$mockObjectManager;
44 
49 
53  protected ‪$mockLanguageService;
54 
58  protected function ‪setUp(): void
59  {
60  parent::setUp();
61  $this->mockObjectManager = $this->getMockBuilder(ObjectManager::class)->disableOriginalConstructor()->getMock();
63  $this->mockRepositoryRepository = $this->getMockBuilder(RepositoryRepository::class)
64  ->setConstructorArgs([$this->mockObjectManager])
65  ->getMock();
66  $this->mockLanguageService = $this->createMock(LanguageService::class);
67  $this->resetSingletonInstances = true;
68  }
69 
74  {
75  $reportMock = $this->createMock(ExtensionStatus::class);
76  self::assertInstanceOf(StatusProviderInterface::class, $reportMock);
77  }
78 
82  public function ‪getStatusReturnsArray(): void
83  {
84  $report = $this->getMockBuilder(ExtensionStatus::class)
85  ->onlyMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
86  ->disableOriginalConstructor()
87  ->getMock();
88  self::assertIsArray($report->getStatus());
89  }
90 
94  public function ‪getStatusReturnArrayContainsFiveEntries(): void
95  {
96  $report = $this->getMockBuilder(ExtensionStatus::class)
97  ->onlyMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
98  ->disableOriginalConstructor()
99  ->getMock();
100  self::assertCount(5, $report->getStatus());
101  }
102 
107  {
108  $statusObject = $this->getMockBuilder(Status::class)
109  ->setConstructorArgs(['title', 'value'])
110  ->getMock();
111  $report = $this->getMockBuilder(ExtensionStatus::class)
112  ->onlyMethods(['getSecurityStatusOfExtensions', 'getMainRepositoryStatus'])
113  ->disableOriginalConstructor()
114  ->getMock();
115  $report->method('getMainRepositoryStatus')->willReturn($statusObject);
116 
117  foreach ($report->getStatus() as $status) {
118  if ($status) {
119  self::assertInstanceOf(Status::class, $status);
120  }
121  }
122  }
123 
128  {
129  [$repositoryRepositoryProphecy] = $this->‪setUpRepositoryStatusTests();
130  $extensionStatus = new ‪ExtensionStatus();
131  $extensionStatus->getStatus();
132 
133  $repositoryRepositoryProphecy->findOneTypo3OrgRepository()->shouldHaveBeenCalled();
134  }
135 
140  {
141  [$repositoryRepositoryProphecy, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(0, true, false);
142 
143  $repositoryRepositoryProphecy->findOneTypo3OrgRepository()->willReturn(null);
144 
145  $extensionStatus = new ‪ExtensionStatus();
146  $extensionStatus->getStatus();
147 
148  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::ERROR)->shouldHaveBeenCalled();
149  }
150 
155  {
156  [$repositoryRepositoryProphecy, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(0, true, false);
157 
158  $repository = new ‪Repository();
159  $repository->setLastUpdate(new \DateTime('-14days'));
160  $repositoryRepositoryProphecy->findOneTypo3OrgRepository()->willReturn($repository);
161 
162  $extensionStatus = new ‪ExtensionStatus();
163  $extensionStatus->getStatus();
164 
165  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::NOTICE)->shouldHaveBeenCalled();
166  }
167 
172  {
173  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests();
174 
175  $extensionStatus = new ‪ExtensionStatus();
176  $extensionStatus->getStatus();
177 
178  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::OK)->shouldHaveBeenCalled();
179  }
180 
185  {
186  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests();
187 
188  $extensionStatus = new ‪ExtensionStatus();
189  $extensionStatus->getStatus();
190 
191  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::OK)->shouldHaveBeenCalled();
192  }
193 
198  {
199  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(-1);
200 
201  $extensionStatus = new ‪ExtensionStatus();
202  $extensionStatus->getStatus();
203 
204  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::ERROR)->shouldHaveBeenCalled();
205  }
206 
211  {
212  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(0, false);
213 
214  $extensionStatus = new ‪ExtensionStatus();
215  $extensionStatus->getStatus();
216 
217  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::OK)->shouldHaveBeenCalled();
218  }
219 
224  {
225  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(-1, false);
226 
227  $extensionStatus = new ‪ExtensionStatus();
228  $extensionStatus->getStatus();
229 
230  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::WARNING)->shouldHaveBeenCalled();
231  }
232 
237  {
238  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(-2, true);
239 
240  $extensionStatus = new ‪ExtensionStatus();
241  $extensionStatus->getStatus();
242 
243  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::WARNING)->shouldHaveBeenCalled();
244  }
245 
250  {
251  [, $objectManagerProphecy] = $this->‪setUpRepositoryStatusTests(-2, false);
252 
253  $extensionStatus = new ‪ExtensionStatus();
254  $extensionStatus->getStatus();
255 
256  $objectManagerProphecy->get(Status::class, Argument::any(), Argument::any(), Argument::any(), ‪Status::WARNING)->shouldHaveBeenCalled();
257  }
258 
266  protected function ‪setUpRepositoryStatusTests(int $reviewState = 0, bool $installed = true, bool $setupRepositoryStatusOk = true): array
267  {
268  $mockTerObject = new ‪Extension();
269  $mockTerObject->setVersion('1.0.6');
270  $mockTerObject->setReviewState($reviewState);
271 
272  $mockExtensionList = [
273  'enetcache' => [
274  'installed' => $installed,
275  'terObject' => $mockTerObject,
276  ],
277  ];
278  $eventDispatcher = $this->prophesize(EventDispatcherInterface::class)->reveal();
280  $mockListUtility = $this->getMockBuilder(ListUtility::class)->getMock();
281  $mockListUtility->injectEventDispatcher($eventDispatcher);
282  $mockListUtility
283  ->expects(self::once())
284  ->method('getAvailableAndInstalledExtensionsWithAdditionalInformation')
285  ->willReturn($mockExtensionList);
286 
287  $repositoryRepositoryProphecy = $this->prophesize(RepositoryRepository::class);
288  $objectManagerProphecy = $this->prophesize(ObjectManager::class);
289  $objectManagerProphecy->get(RepositoryRepository::class)->willReturn($repositoryRepositoryProphecy->reveal());
290  $objectManagerProphecy->get(ListUtility::class)->willReturn($mockListUtility);
291  $objectManagerProphecy->get(LanguageService::class)->willReturn($this->mockLanguageService);
292  $objectManagerProphecy->get(Status::class, Argument::cetera())->willReturn(new ‪Status('test status', 'test status value'));
293  GeneralUtility::setSingletonInstance(ObjectManager::class, $objectManagerProphecy->reveal());
294  if ($setupRepositoryStatusOk) {
295  $repository = new ‪Repository();
296  $repository->setLastUpdate(new \DateTime('-4days'));
297  $repositoryRepositoryProphecy->findOneTypo3OrgRepository()->willReturn($repository);
298  }
299  return [$repositoryRepositoryProphecy, $objectManagerProphecy];
300  }
301 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo
‪getStatusReturnsNoticeIfRepositoryUpdateIsLongerThanSevenDaysAgo()
Definition: ExtensionStatusTest.php:151
‪TYPO3\CMS\Reports\StatusProviderInterface
Definition: StatusProviderInterface.php:22
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnArrayContainsInstancesOfReportsStatusStatus
‪getStatusReturnArrayContainsInstancesOfReportsStatusStatus()
Definition: ExtensionStatusTest.php:103
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnArrayContainsFiveEntries
‪getStatusReturnArrayContainsFiveEntries()
Definition: ExtensionStatusTest.php:91
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsWarningForLoadedExtensionIfOutdatedExtensionIsLoaded
‪getStatusReturnsWarningForLoadedExtensionIfOutdatedExtensionIsLoaded()
Definition: ExtensionStatusTest.php:233
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\extensionStatusImplementsStatusProviderInterface
‪extensionStatusImplementsStatusProviderInterface()
Definition: ExtensionStatusTest.php:70
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:29
‪TYPO3\CMS\Reports\Status\NOTICE
‪const NOTICE
Definition: Status.php:25
‪TYPO3\CMS\Reports\Status\ERROR
‪const ERROR
Definition: Status.php:29
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\$mockRepositoryRepository
‪RepositoryRepository $mockRepositoryRepository
Definition: ExtensionStatusTest.php:46
‪TYPO3\CMS\Extensionmanager\Domain\Repository\RepositoryRepository
Definition: RepositoryRepository.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report
Definition: ExtensionStatusTest.php:18
‪TYPO3\CMS\Extensionmanager\Utility\ListUtility
Definition: ListUtility.php:41
‪TYPO3\CMS\Extbase\Object\ObjectManagerInterface
Definition: ObjectManagerInterface.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsArray
‪getStatusReturnsArray()
Definition: ExtensionStatusTest.php:79
‪TYPO3\CMS\Reports\Status\OK
‪const OK
Definition: Status.php:27
‪TYPO3\CMS\Reports\Status
Definition: Status.php:24
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded
‪getStatusReturnsOkForLoadedExtensionIfNoInsecureExtensionIsLoaded()
Definition: ExtensionStatusTest.php:181
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsOkForExistingExtensionIfNoInsecureExtensionExists
‪getStatusReturnsOkForExistingExtensionIfNoInsecureExtensionExists()
Definition: ExtensionStatusTest.php:207
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest
Definition: ExtensionStatusTest.php:39
‪TYPO3\CMS\Extensionmanager\Domain\Model\Repository
Definition: Repository.php:26
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsErrorForExistingExtensionIfOutdatedExtensionExists
‪getStatusReturnsErrorForExistingExtensionIfOutdatedExtensionExists()
Definition: ExtensionStatusTest.php:246
‪TYPO3\CMS\Reports\Status\WARNING
‪const WARNING
Definition: Status.php:28
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsOkIfUpdatedLessThanSevenDaysAgo
‪getStatusReturnsOkIfUpdatedLessThanSevenDaysAgo()
Definition: ExtensionStatusTest.php:168
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsErrorStatusIfRepositoryIsNotFound
‪getStatusReturnsErrorStatusIfRepositoryIsNotFound()
Definition: ExtensionStatusTest.php:136
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\$mockLanguageService
‪LanguageService $mockLanguageService
Definition: ExtensionStatusTest.php:50
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusCallsMainRepositoryForMainRepositoryStatusResult
‪getStatusCallsMainRepositoryForMainRepositoryStatusResult()
Definition: ExtensionStatusTest.php:124
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\setUp
‪setUp()
Definition: ExtensionStatusTest.php:55
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsWarningForExistingExtensionIfInsecureExtensionExistsButIsNotLoaded
‪getStatusReturnsWarningForExistingExtensionIfInsecureExtensionExistsButIsNotLoaded()
Definition: ExtensionStatusTest.php:220
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\$mockObjectManager
‪ObjectManagerInterface $mockObjectManager
Definition: ExtensionStatusTest.php:42
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\getStatusReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded
‪getStatusReturnsErrorForLoadedExtensionIfInsecureExtensionIsLoaded()
Definition: ExtensionStatusTest.php:194
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Extensionmanager\Report\ExtensionStatus
Definition: ExtensionStatus.php:32
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Report\ExtensionStatusTest\setUpRepositoryStatusTests
‪array setUpRepositoryStatusTests(int $reviewState=0, bool $installed=true, bool $setupRepositoryStatusOk=true)
Definition: ExtensionStatusTest.php:263