[BUGFIX] Preview images not rendered in Web > Page view on Windows systems
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Tests / Unit / Utility / PathUtilityTest.php
1 <?php
2 namespace TYPO3\CMS\Core\Tests\Unit\Utility;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Oliver Hader <oliver.hader@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 * 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 /**
31 * Testcase for class \TYPO3\CMS\Core\Utility\PathUtility
32 *
33 * @author Oliver Hader <oliver.hader@typo3.org>
34 * @package TYPO3
35 * @subpackage t3lib
36 */
37 class PathUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
38
39 /**
40 * @param array $paths
41 * @param string $expected
42 * @dataProvider isCommonPrefixResolvedCorrectlyDataProvider
43 * @test
44 */
45 public function isCommonPrefixResolvedCorrectly(array $paths, $expected) {
46 $commonPrefix = \TYPO3\CMS\Core\Utility\PathUtility::getCommonPrefix($paths);
47 $this->assertEquals($expected, $commonPrefix);
48 }
49
50 /**
51 * @return array
52 */
53 public function isCommonPrefixResolvedCorrectlyDataProvider() {
54 return array(
55 array(
56 array(
57 '/var/www/myhost.com/t3lib/'
58 ),
59 '/var/www/myhost.com/t3lib/'
60 ),
61 array(
62 array(
63 '/var/www/myhost.com/t3lib/',
64 '/var/www/myhost.com/t3lib/'
65 ),
66 '/var/www/myhost.com/t3lib/'
67 ),
68 array(
69 array(
70 '/var/www/myhost.com/typo3/',
71 '/var/www/myhost.com/t3lib/'
72 ),
73 '/var/www/myhost.com/'
74 ),
75 array(
76 array(
77 '/var/www/myhost.com/uploads/',
78 '/var/www/myhost.com/typo3/',
79 '/var/www/myhost.com/t3lib/'
80 ),
81 '/var/www/myhost.com/'
82 ),
83 array(
84 array(
85 '/var/www/myhost.com/uploads/directory/',
86 '/var/www/myhost.com/typo3/sysext/',
87 '/var/www/myhost.com/typo3/contrib/',
88 '/var/www/myhost.com/t3lib/utility/'
89 ),
90 '/var/www/myhost.com/'
91 ),
92 array(
93 array(
94 'C:\\www\\myhost.com\\t3lib\\'
95 ),
96 'C:/www/myhost.com/t3lib/'
97 ),
98 array(
99 array(
100 'C:\\www\\myhost.com\\t3lib\\',
101 'C:\\www\\myhost.com\\t3lib\\'
102 ),
103 'C:/www/myhost.com/t3lib/'
104 ),
105 array(
106 array(
107 'C:\\www\\myhost.com\\typo3\\',
108 'C:\\www\\myhost.com\\t3lib\\'
109 ),
110 'C:/www/myhost.com/'
111 ),
112 array(
113 array(
114 'C:\\www\\myhost.com\\uploads\\',
115 'C:\\www\\myhost.com\\typo3\\',
116 'C:\\www\\myhost.com\\t3lib\\'
117 ),
118 'C:/www/myhost.com/'
119 ),
120 array(
121 array(
122 'C:\\www\\myhost.com\\uploads\\directory\\',
123 'C:\\www\\myhost.com\\typo3\\sysext\\',
124 'C:\\www\\myhost.com\\typo3\\contrib\\',
125 'C:\\www\\myhost.com\\t3lib\\utility\\'
126 ),
127 'C:/www/myhost.com/'
128 )
129 );
130 }
131
132 /**
133 * @param string $source
134 * @param string $target
135 * @param string $expected
136 * @dataProvider isRelativePathResolvedCorrectlyDataProvider
137 * @test
138 */
139 public function isRelativePathResolvedCorrectly($source, $target, $expected) {
140 $relativePath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath($source, $target);
141 $this->assertEquals($expected, $relativePath);
142 }
143
144 /**
145 * @return array
146 */
147 public function isRelativePathResolvedCorrectlyDataProvider() {
148 return array(
149 array(
150 '/',
151 PATH_site . 'directory',
152 NULL
153 ),
154 array(
155 PATH_site . 't3lib/',
156 PATH_site . 't3lib/',
157 ''
158 ),
159 array(
160 PATH_site . 'typo3/',
161 PATH_site . 't3lib/',
162 '../t3lib/'
163 ),
164 array(
165 PATH_site,
166 PATH_site . 't3lib/',
167 't3lib/'
168 ),
169 array(
170 PATH_site . 't3lib/',
171 PATH_site . 't3lib/stddb/',
172 'stddb/'
173 ),
174 array(
175 PATH_site . 'typo3/sysext/cms/',
176 PATH_site . 't3lib/utility/',
177 '../../../t3lib/utility/'
178 ),
179 );
180 }
181
182 /**
183 * @param string $path
184 * @param string $separator
185 * @param string $expected
186 * @dataProvider isTrailingSeparatorSanitizedCorrectlyDataProvider
187 * @test
188 */
189 public function isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected) {
190 $sanitizedPath = \TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path, $separator);
191 $this->assertEquals($expected, $sanitizedPath);
192 }
193
194 /**
195 * @return array
196 */
197 public function isTrailingSeparatorSanitizedCorrectlyDataProvider() {
198 return array(
199 array('/var/www//', '/', '/var/www/'),
200 array('/var/www/', '/', '/var/www/'),
201 array('/var/www', '/', '/var/www/')
202 );
203 }
204
205 }
206
207 ?>