TYPO3 CMS  TYPO3_6-2
PathUtilityTest.php
Go to the documentation of this file.
1 <?php
3 
17 
24 
31  public function isCommonPrefixResolvedCorrectly(array $paths, $expected) {
33  $this->assertEquals($expected, $commonPrefix);
34  }
35 
40  return array(
41  array(
42  array(
43  '/var/www/myhost.com/t3lib/'
44  ),
45  '/var/www/myhost.com/t3lib/'
46  ),
47  array(
48  array(
49  '/var/www/myhost.com/t3lib/',
50  '/var/www/myhost.com/t3lib/'
51  ),
52  '/var/www/myhost.com/t3lib/'
53  ),
54  array(
55  array(
56  '/var/www/myhost.com/typo3/',
57  '/var/www/myhost.com/t3lib/'
58  ),
59  '/var/www/myhost.com/'
60  ),
61  array(
62  array(
63  '/var/www/myhost.com/uploads/',
64  '/var/www/myhost.com/typo3/',
65  '/var/www/myhost.com/t3lib/'
66  ),
67  '/var/www/myhost.com/'
68  ),
69  array(
70  array(
71  '/var/www/myhost.com/uploads/directory/',
72  '/var/www/myhost.com/typo3/sysext/',
73  '/var/www/myhost.com/typo3/contrib/',
74  '/var/www/myhost.com/t3lib/utility/'
75  ),
76  '/var/www/myhost.com/'
77  ),
78  array(
79  array(
80  'C:\\www\\myhost.com\\t3lib\\'
81  ),
82  'C:/www/myhost.com/t3lib/'
83  ),
84  array(
85  array(
86  'C:\\www\\myhost.com\\t3lib\\',
87  'C:\\www\\myhost.com\\t3lib\\'
88  ),
89  'C:/www/myhost.com/t3lib/'
90  ),
91  array(
92  array(
93  'C:\\www\\myhost.com\\typo3\\',
94  'C:\\www\\myhost.com\\t3lib\\'
95  ),
96  'C:/www/myhost.com/'
97  ),
98  array(
99  array(
100  'C:\\www\\myhost.com\\uploads\\',
101  'C:\\www\\myhost.com\\typo3\\',
102  'C:\\www\\myhost.com\\t3lib\\'
103  ),
104  'C:/www/myhost.com/'
105  ),
106  array(
107  array(
108  'C:\\www\\myhost.com\\uploads\\directory\\',
109  'C:\\www\\myhost.com\\typo3\\sysext\\',
110  'C:\\www\\myhost.com\\typo3\\contrib\\',
111  'C:\\www\\myhost.com\\t3lib\\utility\\'
112  ),
113  'C:/www/myhost.com/'
114  )
115  );
116  }
117 
125  public function isRelativePathResolvedCorrectly($source, $target, $expected) {
126  $relativePath = \TYPO3\CMS\Core\Utility\PathUtility::getRelativePath($source, $target);
127  $this->assertEquals($expected, $relativePath);
128  }
129 
134  return array(
135  array(
136  '/',
137  PATH_site . 'directory',
138  NULL
139  ),
140  array(
141  PATH_site . 't3lib/',
142  PATH_site . 't3lib/',
143  ''
144  ),
145  array(
146  PATH_site . 'typo3/',
147  PATH_site . 't3lib/',
148  '../t3lib/'
149  ),
150  array(
151  PATH_site,
152  PATH_site . 't3lib/',
153  't3lib/'
154  ),
155  array(
156  PATH_site . 't3lib/',
157  PATH_site . 't3lib/stddb/',
158  'stddb/'
159  ),
160  array(
161  PATH_site . 'typo3/sysext/cms/',
162  PATH_site . 't3lib/utility/',
163  '../../../t3lib/utility/'
164  ),
165  );
166  }
167 
175  public function isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected) {
176  $sanitizedPath = \TYPO3\CMS\Core\Utility\PathUtility::sanitizeTrailingSeparator($path, $separator);
177  $this->assertEquals($expected, $sanitizedPath);
178  }
179 
184  return array(
185  array('/var/www//', '/', '/var/www/'),
186  array('/var/www/', '/', '/var/www/'),
187  array('/var/www', '/', '/var/www/')
188  );
189  }
190 
197  return array(
198  'basic' => array(
199  '/abc/def/one.txt',
200  '../two.txt',
201  '/abc/two.txt'
202  ),
203  'same folder' => array(
204  '/abc/one.txt',
205  './two.txt',
206  '/abc/two.txt'
207  ),
208  'preserve relative path if path goes above start path' => array(
209  'abc/one.txt',
210  '../../two.txt',
211  '../two.txt'
212  ),
213  'preserve absolute path even if path goes above start path' => array(
214  '/abc/one.txt',
215  '../../two.txt',
216  '/two.txt',
217  ),
218  'base folder with same folder path' => array(
219  '/abc/',
220  './two.txt',
221  '/abc/two.txt'
222  ),
223  'base folder with parent folder path' => array(
224  '/abc/bar/',
225  '../foo.txt',
226  '/abc/foo.txt'
227  ),
228  );
229  }
230 
238  public function getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly($baseFileName, $includeFileName, $expectedFileName) {
239  $resolvedFilename = \TYPO3\CMS\Core\Utility\PathUtility::getAbsolutePathOfRelativeReferencedFileOrPath($baseFileName, $includeFileName);
240  $this->assertEquals($expectedFileName, $resolvedFilename);
241  }
242 
249  return array(
250  'removes single-dot-elements' => array(
251  'abc/./def/././ghi',
252  'abc/def/ghi'
253  ),
254  'removes ./ at beginning' => array(
255  './abc/def/ghi',
256  'abc/def/ghi'
257  ),
258  'removes double-slashes' => array(
259  'abc//def/ghi',
260  'abc/def/ghi'
261  ),
262  'removes double-slashes from front, but keeps absolute path' => array(
263  '//abc/def/ghi',
264  '/abc/def/ghi'
265  ),
266  'makes double-dot-elements go one level higher, test #1' => array(
267  'abc/def/ghi/../..',
268  'abc'
269  ),
270  'makes double-dot-elements go one level higher, test #2' => array(
271  'abc/def/ghi/../123/456/..',
272  'abc/def/123'
273  ),
274  'makes double-dot-elements go one level higher, test #3' => array(
275  'abc/../../def/ghi',
276  '../def/ghi'
277  ),
278  'makes double-dot-elements go one level higher, test #4' => array(
279  'abc/def/ghi//../123/456/..',
280  'abc/def/123'
281  ),
282  'truncates slash at the end' => array(
283  'abc/def/ghi/',
284  'abc/def/ghi'
285  ),
286  'keeps slash in front of absolute paths' => array(
287  '/abc/def/ghi',
288  '/abc/def/ghi'
289  ),
290  'keeps slash in front of absolute paths even if double-dot-elements want to go higher' => array(
291  '/abc/../../def/ghi',
292  '/def/ghi'
293  ),
294  'works with EXT-syntax-paths' => array(
295  'EXT:abc/def/ghi/',
296  'EXT:abc/def/ghi'
297  ),
298  'truncates ending slash with space' => array(
299  'abc/def/ ',
300  'abc/def'
301  ),
302  'truncates ending space' => array(
303  'abc/def ',
304  'abc/def'
305  ),
306  'truncates ending dot' => array(
307  'abc/def/.',
308  'abc/def'
309  ),
310  'does not truncates ending dot if part of name' => array(
311  'abc/def.',
312  'abc/def.'
313  ),
314  'protocol is not removed' => array(
315  'vfs://def/../text.txt',
316  'vfs://text.txt'
317  ),
318  'works with filenames' => array(
319  '/def/../text.txt',
320  '/text.txt'
321  ),
322  'absolute windwos path' => array(
323  'C:\def\..\..\test.txt',
324  'C:/test.txt'
325  ),
326  'double slashaes' => array(
327  'abc//def',
328  'abc/def'
329  ),
330  'multiple slashes' => array(
331  'abc///////def',
332  'abc/def'
333  ),
334  );
335  }
336 
341  public function getCanonicalPathCorrectlyCleansPath($inputName, $expectedResult) {
342  $className = $this->getUniqueId('PathUtilityFixture');
343  $fixtureClassString = '
344  namespace ' . ltrim(__NAMESPACE__, '\\') . ';
345  class ' . $className . ' extends \\TYPO3\\CMS\\Core\\Utility\\PathUtility {
346  static public function isWindows() {
347  return TRUE;
348  }
349  }
350  ';
351  eval($fixtureClassString);
352  $fullyQualifiedClassName = __NAMESPACE__ . '\\' . $className;
353 
354  $this->assertEquals(
355  $expectedResult,
356  $fullyQualifiedClassName::getCanonicalPath($inputName)
357  );
358  }
359 
360 }
isRelativePathResolvedCorrectly($source, $target, $expected)
static getCommonPrefix(array $paths)
static getAbsolutePathOfRelativeReferencedFileOrPath($baseFilenameOrPath, $includeFileName)
isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected)
static getRelativePath($sourcePath, $targetPath)
Definition: PathUtility.php:71
getCanonicalPathCorrectlyCleansPath($inputName, $expectedResult)
getAbsolutePathOfRelativeReferencedFileOrPathResolvesFileCorrectly($baseFileName, $includeFileName, $expectedFileName)
static sanitizeTrailingSeparator($path, $separator='/')