‪TYPO3CMS  10.4
UploadExtensionFileControllerTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use PHPUnit\Framework\MockObject\MockObject;
22 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
23 
27 class ‪UploadExtensionFileControllerTest extends UnitTestCase
28 {
33  {
34  return [
35  'simple' => [
36  'extension_0.0.0.zip',
37  'extension'
38  ],
39  'underscore in extension name' => [
40  'extension_key_10.100.356.zip',
41  'extension_key'
42  ],
43  'camel case file name' => [
44  'extensionName_1.1.1.zip',
45  'extensionname'
46  ],
47  'version with dashes' => [
48  'extension_1-2-3.zip',
49  'extension'
50  ],
51  'characters after version' => [
52  'extension_1-2-3(1).zip',
53  'extension'
54  ],
55  'characters after version with extra space' => [
56  'extension_1-2-3 (1).zip',
57  'extension'
58  ],
59  'no version' => [
60  'extension.zip',
61  'extension'
62  ]
63  ];
64  }
71  public function ‪getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey)
72  {
74  $managementServiceMock = $this->getMockBuilder(ExtensionManagementService::class)
75  ->setMethods(['isAvailable'])
76  ->disableOriginalConstructor()
77  ->getMock();
78  $managementServiceMock->expects(self::once())
79  ->method('isAvailable')
80  ->with($expectedKey)
81  ->willReturn(false);
82 
84  $fileHandlingUtilityMock = $this->createMock(FileHandlingUtility::class);
85  $fileHandlingUtilityMock->expects(self::once())->method('unzipExtensionFromFile');
86 
87  $fixture = new ‪UploadExtensionFileController();
88  $fixture->injectManagementService($managementServiceMock);
89  $fixture->injectFileHandlingUtility($fileHandlingUtilityMock);
90 
91  $reflectionClass = new \ReflectionClass($fixture);
92  $reflectionMethod = $reflectionClass->getMethod('getExtensionFromZipFile');
93  $reflectionMethod->setAccessible(true);
94 
95  $extensionDetails = $reflectionMethod->invokeArgs($fixture, ['', $filename]);
96 
97  self::assertEquals($expectedKey, $extensionDetails['extKey']);
98  }
99 }
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller\UploadExtensionFileControllerTest\getExtensionFromZipFileExtractsExtensionKeyDataProvider
‪array getExtensionFromZipFileExtractsExtensionKeyDataProvider()
Definition: UploadExtensionFileControllerTest.php:32
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller\UploadExtensionFileControllerTest
Definition: UploadExtensionFileControllerTest.php:28
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller
Definition: DownloadControllerTest.php:16
‪TYPO3\CMS\Extensionmanager\Controller\UploadExtensionFileController
Definition: UploadExtensionFileController.php:38
‪TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility
Definition: FileHandlingUtility.php:35
‪TYPO3\CMS\Extensionmanager\Tests\Unit\Controller\UploadExtensionFileControllerTest\getExtensionFromZipFileExtractsExtensionKey
‪getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey)
Definition: UploadExtensionFileControllerTest.php:71
‪TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService
Definition: ExtensionManagementService.php:33