eb3174f38dfe234b2b43e11cf4cbf3cc55923c3f
[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 /**
18 * Update from TER controller test
19 */
20 class UploadExtensionFileControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
22 /**
23 * @return array The test data for getExtensionFromZipFileExtractsExtensionKey
24 */
25 public function getExtensionFromZipFileExtractsExtensionKeyDataProvider()
26 {
27 return [
28 'simple' => [
29 'extension_0.0.0.zip',
30 'extension'
31 ],
32 'underscore in extension name' => [
33 'extension_key_10.100.356.zip',
34 'extension_key'
35 ],
36 'camel case file name' => [
37 'extensionName_1.1.1.zip',
38 'extensionname'
39 ],
40 'version with dashes' => [
41 'extension_1-2-3.zip',
42 'extension'
43 ],
44 'characters after version' => [
45 'extension_1-2-3(1).zip',
46 'extension'
47 ],
48 'characters after version with extra space' => [
49 'extension_1-2-3 (1).zip',
50 'extension'
51 ],
52 'no version' => [
53 'extension.zip',
54 'extension'
55 ]
56 ];
57 }
58 /**
59 * @test
60 * @dataProvider getExtensionFromZipFileExtractsExtensionKeyDataProvider
61 * @param string $filename The file name to test
62 * @param string $expectedKey The expected extension key
63 */
64 public function getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey)
65 {
66 $fixture = $this->getAccessibleMock(\TYPO3\CMS\Extensionmanager\Controller\UploadExtensionFileController::class, ['dummy']);
67 $managementServiceMock = $this->getMockBuilder(\TYPO3\CMS\Extensionmanager\Service\ExtensionManagementService::class)
68 ->setMethods(['isAvailable'])
69 ->disableOriginalConstructor()
70 ->getMock();
71 $managementServiceMock->expects($this->once())
72 ->method('isAvailable')
73 ->with($expectedKey)
74 ->will($this->returnValue(false));
75 $fixture->_set('managementService', $managementServiceMock);
76 $fileHandlingUtilityMock = $this->createMock(\TYPO3\CMS\Extensionmanager\Utility\FileHandlingUtility::class);
77 $fileHandlingUtilityMock->expects($this->once())->method('unzipExtensionFromFile');
78 $fixture->_set('fileHandlingUtility', $fileHandlingUtilityMock);
79
80 $extensionDetails = $fixture->_call('getExtensionFromZipFile', '', $filename);
81 $this->assertEquals($expectedKey, $extensionDetails['extKey']);
82 }
83 }