8695e19e36bdd9313840a1255b5266b76be3bcfd
[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 * Copyright notice
6 *
7 * (c) 2013 Philipp Gampe <philipp.gampe@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26
27 /**
28 * Update from TER controller test
29 *
30 */
31 class UploadExtensionFileControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
32
33 /**
34 * @return array The test data for getExtensionFromZipFileExtractsExtensionKey
35 */
36 public function getExtensionFromZipFileExtractsExtensionKeyDataProvider() {
37 return array(
38 'simple' => array(
39 'extension_0.0.0.zip',
40 'extension'
41 ),
42 'underscore in extension name' => array(
43 'extension_key_10.100.356.zip',
44 'extension_key'
45 ),
46 'camel case file name' => array(
47 'extensionName_1.1.1.zip',
48 'extensionname'
49 ),
50 'version with dashes' => array(
51 'extension_1-2-3.zip',
52 'extension'
53 ),
54 'characters after version' => array(
55 'extension_1-2-3(1).zip',
56 'extension'
57 ),
58 'characters after version with extra space' => array(
59 'extension_1-2-3 (1).zip',
60 'extension'
61 ),
62 'no version' => array(
63 'extension.zip',
64 'extension'
65 )
66 );
67 }
68 /**
69 * @test
70 * @dataProvider getExtensionFromZipFileExtractsExtensionKeyDataProvider
71 * @param string $filename The file name to test
72 * @param string $expectedKey The expected extension key
73 * @return void
74 */
75 public function getExtensionFromZipFileExtractsExtensionKey($filename, $expectedKey) {
76 $fixture = $this->getAccessibleMock('TYPO3\\CMS\\Extensionmanager\\Controller\\UploadExtensionFileController', array('dummy'));
77 $installUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\InstallUtility', array(), array(), '', FALSE);
78 $installUtilityMock->expects($this->once())
79 ->method('isAvailable')
80 ->with($expectedKey)
81 ->will($this->returnValue(FALSE));
82 $fixture->_set('installUtility', $installUtilityMock);
83 $fileHandlingUtilityMock = $this->getMock('TYPO3\\CMS\\Extensionmanager\\Utility\\FileHandlingUtility');
84 $fileHandlingUtilityMock->expects($this->once())->method('unzipExtensionFromFile');
85 $fixture->_set('fileHandlingUtility', $fileHandlingUtilityMock);
86
87 $extensionDetails = $fixture->_call('getExtensionFromZipFile', '', $filename);
88 $this->assertEquals($expectedKey, $extensionDetails['extKey']);
89 }
90
91 }