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