[!!!][TASK] Remove support for non namespaced classes in Extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extensionmanager / Tests / Unit / Controller / UploadExtensionFileControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Controller;
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
19 /**
20 * Update from TER controller test
21 */
22 class UploadExtensionFileControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
23 {
24 /**
25 * @return array The test data for getExtensionFromZipFileExtractsExtensionKey
26 */
27 public function getExtensionFromZipFileExtractsExtensionKeyDataProvider()
28 {
29 return [
30 'simple' => [
31 'extension_0.0.0.zip',
32 'extension'
33 ],
34 'underscore in extension name' => [
35 'extension_key_10.100.356.zip',
36 'extension_key'
37 ],
38 'camel case file name' => [
39 'extensionName_1.1.1.zip',
40 'extensionname'
41 ],
42 'version with dashes' => [
43 'extension_1-2-3.zip',
44 'extension'
45 ],
46 'characters after version' => [
47 'extension_1-2-3(1).zip',
48 'extension'
49 ],
50 'characters after version with extra space' => [
51 'extension_1-2-3 (1).zip',
52 'extension'
53 ],
54 'no version' => [
55 'extension.zip',
56 'extension'
57 ]
58 ];
59 }
60 /**
61 * @test
62 * @dataProvider getExtensionFromZipFileExtractsExtensionKeyDataProvider
63 * @param string $filename The file name to test
64 * @param string $expectedKey The expected extension key
65 */
66 public function getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey)
67 {
68 /** @var \TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService|MockObject $managementServiceMock */
69 $managementServiceMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class)
70 ->setMethods(['isAvailable'])
71 ->disableOriginalConstructor()
72 ->getMock();
73 $managementServiceMock->expects($this->once())
74 ->method('isAvailable')
75 ->with($expectedKey)
76 ->will($this->returnValue(false));
77
78 /** @var \TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility|MockObject $fileHandlingUtilityMock */
79 $fileHandlingUtilityMock = $this->createMock(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility::class);
80 $fileHandlingUtilityMock->expects($this->once())->method('unzipExtensionFromFile');
81
82 $fixture = new \TYPO3\CMS\Extensionmanager\Controller\UploadExtensionFileController();
83 $fixture->injectManagementService($managementServiceMock);
84 $fixture->injectFileHandlingUtility($fileHandlingUtilityMock);
85
86 $reflectionClass = new \ReflectionClass($fixture);
87 $reflectionMethod = $reflectionClass->getMethod('getExtensionFromZipFile');
88 $reflectionMethod->setAccessible(true);
89
90 $extensionDetails = $reflectionMethod->invokeArgs($fixture, ['', $filename]);
91
92 $this->assertEquals($expectedKey, $extensionDetails['extKey']);
93 }
94 }