TYPO3 CMS  TYPO3_8-7
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 
20 class UploadExtensionFileControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
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  }
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 }