[TASK] Fix CGL violations against ClassDocComment
[Packages/TYPO3.CMS.git] / tests / Unit / t3lib / utility / class.t3lib_utility_pathTest.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2012 Oliver Hader <oliver.hader@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Testcase for class t3lib_utility_Path
30 *
31 * @author Oliver Hader <oliver.hader@typo3.org>
32 *
33 * @package TYPO3
34 * @subpackage t3lib
35 */
36 class t3lib_utility_PathTest extends tx_phpunit_testcase {
37 /**
38 * @param array $paths
39 * @param string $expected
40 * @dataProvider isCommonPrefixResolvedCorrectlyDataProvider
41 * @test
42 */
43 public function isCommonPrefixResolvedCorrectly(array $paths, $expected) {
44 $commonPrefix = t3lib_utility_Path::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 );
91 }
92
93 /**
94 * @param string $source
95 * @param string $target
96 * @param string $expected
97 * @dataProvider isRelativePathResolvedCorrectlyDataProvider
98 * @test
99 */
100 public function isRelativePathResolvedCorrectly($source, $target, $expected) {
101 $relativePath = t3lib_utility_Path::getRelativePath($source, $target);
102 $this->assertEquals($expected, $relativePath);
103 }
104
105 /**
106 * @return array
107 */
108 public function isRelativePathResolvedCorrectlyDataProvider() {
109 return array(
110 array(
111 '/',
112 PATH_site . 'directory',
113 NULL
114 ),
115 array(
116 PATH_site . 't3lib/',
117 PATH_site . 't3lib/',
118 ''
119 ),
120 array(
121 PATH_site . 'typo3/',
122 PATH_site . 't3lib/',
123 '../t3lib/'
124 ),
125 array(
126 PATH_site,
127 PATH_site . 't3lib/',
128 't3lib/'
129 ),
130 array(
131 PATH_site.'t3lib/',
132 PATH_site . 't3lib/stddb/',
133 'stddb/'
134 ),
135 array(
136 PATH_site . 'typo3/sysext/cms/',
137 PATH_site . 't3lib/utility/',
138 '../../../t3lib/utility/'
139 ),
140 );
141 }
142
143 /**
144 * @param string $path
145 * @param string $separator
146 * @param string $expected
147 * @dataProvider isTrailingSeparatorSanitizedCorrectlyDataProvider
148 * @test
149 */
150 public function isTrailingSeparatorSanitizedCorrectly($path, $separator, $expected) {
151 $sanitizedPath = t3lib_utility_Path::sanitizeTrailingSeparator($path, $separator);
152 $this->assertEquals($expected, $sanitizedPath);
153 }
154
155 /**
156 * @return array
157 */
158 public function isTrailingSeparatorSanitizedCorrectlyDataProvider() {
159 return array(
160 array('/var/www//', '/', '/var/www/'),
161 array('/var/www/', '/', '/var/www/'),
162 array('/var/www', '/', '/var/www/'),
163 );
164 }
165 }
166
167 ?>