‪TYPO3CMS  ‪main
DownloadControllerTest.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 PHPUnit\Framework\Attributes\Test;
22 use TYPO3\CMS\Extensionmanager\Controller\DownloadController;
26 use TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService;
27 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
28 
29 final class ‪DownloadControllerTest extends UnitTestCase
30 {
31  #[Test]
33  {
34  $dummyExceptionMessage = 'exception message';
35  $dummyException = new ‪ExtensionManagerException($dummyExceptionMessage, 1476108614);
36 
37  $dummyExtensionName = 'dummy_extension';
38  $dummyExtension = new ‪Extension();
39  $dummyExtension->setExtensionKey($dummyExtensionName);
40 
41  $extensionManagementServiceMock = $this->getMockBuilder(ExtensionManagementService::class)->disableOriginalConstructor()->getMock();
42  $extensionManagementServiceMock->method('installExtension')->willThrowException($dummyException);
43 
44  $subject = new DownloadController(
45  $this->createMock(ExtensionRepository::class),
46  $extensionManagementServiceMock,
47  $this->createMock(ExtensionConfiguration::class)
48  );
49 
50  $reflectionClass = new \ReflectionClass($subject);
51  $reflectionMethod = $reflectionClass->getMethod('installFromTer');
52 
53  $result = $reflectionMethod->invokeArgs($subject, [$dummyExtension]);
54 
55  $expectedResult = [
56  false,
57  [
58  $dummyExtensionName => [
59  [
60  'code' => 1476108614,
61  'message' => $dummyExceptionMessage,
62  ],
63  ],
64  ],
65  ];
66 
67  self::assertSame($expectedResult, $result);
68  }
69 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller
Definition: ActionControllerTest.php:18
‪TYPO3\CMS\Extensionmanager\Domain\Model\Extension
Definition: Extension.php:30
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller\DownloadControllerTest\installFromTerReturnsArrayWithBooleanResultAndErrorArrayWhenExtensionManagerExceptionIsThrown
‪installFromTerReturnsArrayWithBooleanResultAndErrorArrayWhenExtensionManagerExceptionIsThrown()
Definition: DownloadControllerTest.php:32
‪TYPO3\CMS\Core\Configuration\ExtensionConfiguration
Definition: ExtensionConfiguration.php:47
‪TYPO3\CMS\Extensionmanager\Domain\Repository\ExtensionRepository
Definition: ExtensionRepository.php:37
‪TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException
Definition: ExtensionManagerException.php:25
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller\DownloadControllerTest
Definition: DownloadControllerTest.php:30