[BUGFIX] LocalDriver can be instantiated without basePath
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Resource / Driver / AbstractDriverTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Resource\Driver;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2011-2012 Andreas Wolf <andreas.wolf@ikt-werk.de>
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 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 require_once dirname(__FILE__) . '/../BaseTestCase.php';
31
32 /**
33 * Test case for the abstract driver.
34 *
35 * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
36 * @package TYPO3
37 * @subpackage t3lib
38 */
39 class AbstractDriverTest extends \TYPO3\CMS\Core\Tests\Unit\Resource\BaseTestCase {
40
41 /**
42 * @var \TYPO3\CMS\Core\Resource\Driver\AbstractDriver
43 */
44 protected $fixture;
45
46 /**
47 * @return \TYPO3\CMS\Core\Resource\Driver\AbstractDriver
48 */
49 protected function createDriverFixture() {
50 return $this->getMockForAbstractClass('TYPO3\\CMS\\Core\\Resource\\Driver\\AbstractDriver', array(), '', FALSE);
51 }
52
53 public function filenameValidationDataProvider() {
54 return array(
55 'all-lowercase filename with extension' => array(
56 'testfile.txt',
57 TRUE
58 ),
59 'regular filename with mixed case and extension' => array(
60 'someFilename.jpg',
61 TRUE
62 ),
63 'filename with german umlauts' => array(
64 'anÜmläütTestfile.jpg',
65 TRUE
66 ),
67 'filename with double extension' => array(
68 'someCompressedFile.tar.gz',
69 TRUE
70 ),
71 'filename with dash' => array(
72 'foo-bar',
73 TRUE
74 ),
75 'filename with number' => array(
76 'some23Number',
77 TRUE
78 ),
79 'filename with whitespace' => array(
80 'some whitespace',
81 TRUE
82 ),
83 'filename with tab' => array(
84 'some' . TAB . 'tag',
85 TRUE
86 ),
87 'filename with carriage return' => array(
88 'some' . CR . 'CarriageReturn',
89 FALSE
90 ),
91 'filename with linefeed' => array(
92 'some' . LF . 'Linefeed',
93 FALSE
94 ),
95 'filename with leading slash' => array(
96 '/invalidAsFilename',
97 FALSE
98 ),
99 'filename with null character' => array(
100 'someFile' . chr(0) . 'name',
101 FALSE
102 )
103 );
104 }
105
106 /**
107 * @test
108 * @dataProvider filenameValidationDataProvider
109 */
110 public function filenamesAreCorrectlyValidated($filename, $expectedResult) {
111 $fixture = $this->createDriverFixture(array());
112 $result = $fixture->isValidFilename($filename);
113 $this->assertEquals($expectedResult, $result);
114 }
115
116 /**
117 * @test
118 */
119 public function getFolderCorrectlySetsFolderName() {
120 $identifier = '/someFolder/someSubfolder/';
121 $fixture = $this->createDriverFixture(array());
122 $fixture->setStorage($this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceStorage', array(), array(), '', FALSE));
123 $mockedFactory = $this->getMock('TYPO3\\CMS\\Core\\Resource\\ResourceFactory');
124 $mockedFactory->expects($this->once())->method('createFolderObject')->with($this->anything(), $this->anything(), 'someSubfolder');
125 \TYPO3\CMS\Core\Utility\GeneralUtility::setSingletonInstance('TYPO3\\CMS\\Core\\Resource\\ResourceFactory', $mockedFactory);
126 $fixture->getFolder($identifier);
127 }
128
129 }
130
131 ?>