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