file_is_absolute_path.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. <?php
  2. /**
  3. *
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. *
  21. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22. * @version //autogentag//
  23. * @filesource
  24. * @package Base
  25. * @subpackage Tests
  26. */
  27. /**
  28. * @package Base
  29. * @subpackage Tests
  30. */
  31. class ezcBaseFileIsAbsoluteTest extends ezcTestCase
  32. {
  33. public static function testAbsoluteWindows1()
  34. {
  35. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Windows' ) );
  36. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Windows' ) );
  37. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Windows' ) );
  38. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
  39. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Windows' ) );
  40. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Windows' ) );
  41. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Windows' ) );
  42. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
  43. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Windows' ) );
  44. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Windows' ) );
  45. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Windows' ) );
  46. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
  47. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Windows' ) );
  48. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Windows' ) );
  49. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Windows' ) );
  50. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Windows' ) );
  51. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Windows' ) );
  52. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Windows' ) );
  53. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Windows' ) );
  54. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Windows' ) );
  55. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Windows' ) );
  56. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Windows' ) );
  57. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Windows' ) );
  58. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Windows' ) );
  59. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Windows' ) );
  60. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Windows' ) );
  61. }
  62. public static function testAbsoluteWindows2()
  63. {
  64. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Windows' ) );
  65. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Windows' ) );
  66. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Windows' ) );
  67. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
  68. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Windows' ) );
  69. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Windows' ) );
  70. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Windows' ) );
  71. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Windows' ) );
  72. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Windows' ) );
  73. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Windows' ) );
  74. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Windows' ) );
  75. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Windows' ) );
  76. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Windows' ) );
  77. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Windows' ) );
  78. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Windows' ) );
  79. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Windows' ) );
  80. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Windows' ) );
  81. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Windows' ) );
  82. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Windows' ) );
  83. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Windows' ) );
  84. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Windows' ) );
  85. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Windows' ) );
  86. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Windows' ) );
  87. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Windows' ) );
  88. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Windows' ) );
  89. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Windows' ) );
  90. }
  91. public static function testAbsoluteWindows3()
  92. {
  93. if ( ezcBaseFeatures::os() !== 'Windows' )
  94. {
  95. self::markTestSkipped( 'Test is for Windows only' );
  96. }
  97. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
  98. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
  99. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
  100. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
  101. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
  102. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
  103. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
  104. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
  105. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
  106. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
  107. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
  108. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
  109. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
  110. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
  111. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
  112. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
  113. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
  114. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
  115. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
  116. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
  117. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
  118. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
  119. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
  120. self::assertEquals( false, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
  121. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
  122. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
  123. }
  124. public static function testAbsoluteLinux1()
  125. {
  126. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt\\winnt.sys', 'Linux' ) );
  127. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt\winnt.sys', 'Linux' ) );
  128. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt', 'Linux' ) );
  129. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
  130. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\winnt.sys', 'Linux' ) );
  131. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\\winnt.sys', 'Linux' ) );
  132. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:\table.sys', 'Linux' ) );
  133. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
  134. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c\\winnt.sys', 'Linux' ) );
  135. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\winnt.sys', 'Linux' ) );
  136. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\winnt.sys', 'Linux' ) );
  137. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
  138. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\share\foo.sys', 'Linux' ) );
  139. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\share\foo.sys', 'Linux' ) );
  140. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\share\foo.sys', 'Linux' ) );
  141. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\share\foo.sys', 'Linux' ) );
  142. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\thare\foo.sys', 'Linux' ) );
  143. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\thare\foo.sys', 'Linux' ) );
  144. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\server\\share\foo.sys', 'Linux' ) );
  145. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\server\\share\foo.sys', 'Linux' ) );
  146. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\tequila\\share\foo.sys', 'Linux' ) );
  147. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\\\tequila\\share\foo.sys', 'Linux' ) );
  148. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\etc\init.d\apache', 'Linux' ) );
  149. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '\\etc\\init.d\\apache', 'Linux' ) );
  150. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\init.d\apache', 'Linux' ) );
  151. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc\\init.d\\apache', 'Linux' ) );
  152. }
  153. public static function testAbsoluteLinux2()
  154. {
  155. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys', 'Linux' ) );
  156. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys', 'Linux' ) );
  157. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt', 'Linux' ) );
  158. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
  159. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys', 'Linux' ) );
  160. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys', 'Linux' ) );
  161. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys', 'Linux' ) );
  162. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt', 'Linux' ) );
  163. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys', 'Linux' ) );
  164. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys', 'Linux' ) );
  165. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys', 'Linux' ) );
  166. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys', 'Linux' ) );
  167. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys', 'Linux' ) );
  168. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys', 'Linux' ) );
  169. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys', 'Linux' ) );
  170. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys', 'Linux' ) );
  171. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys', 'Linux' ) );
  172. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys', 'Linux' ) );
  173. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys', 'Linux' ) );
  174. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys', 'Linux' ) );
  175. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys', 'Linux' ) );
  176. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys', 'Linux' ) );
  177. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache', 'Linux' ) );
  178. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache', 'Linux' ) );
  179. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache', 'Linux' ) );
  180. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache', 'Linux' ) );
  181. }
  182. public static function testAbsoluteLinux3()
  183. {
  184. if ( ezcBaseFeatures::os() === 'Windows' )
  185. {
  186. self::markTestSkipped( 'Test is for unix-like systems only' );
  187. }
  188. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt//winnt.sys' ) );
  189. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt/winnt.sys' ) );
  190. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt' ) );
  191. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
  192. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/winnt.sys' ) );
  193. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c://winnt.sys' ) );
  194. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:/table.sys' ) );
  195. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c:winnt' ) );
  196. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'c//winnt.sys' ) );
  197. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//winnt.sys' ) );
  198. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/winnt.sys' ) );
  199. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'winnt.sys' ) );
  200. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server/share/foo.sys' ) );
  201. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server/share/foo.sys' ) );
  202. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/share/foo.sys' ) );
  203. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/share/foo.sys' ) );
  204. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila/thare/foo.sys' ) );
  205. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila/thare/foo.sys' ) );
  206. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//server//share/foo.sys' ) );
  207. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////server//share/foo.sys' ) );
  208. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//tequila//share/foo.sys' ) );
  209. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '////tequila//share/foo.sys' ) );
  210. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '/etc/init.d/apache' ) );
  211. self::assertEquals( true, ezcBaseFile::isAbsolutePath( '//etc//init.d//apache' ) );
  212. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc/init.d/apache' ) );
  213. self::assertEquals( false, ezcBaseFile::isAbsolutePath( 'etc//init.d//apache' ) );
  214. }
  215. public static function testAbsoluteStreamWrapper()
  216. {
  217. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'phar://test.phar/foo' ) );
  218. self::assertEquals( true, ezcBaseFile::isAbsolutePath( 'http://example.com/file' ) );
  219. }
  220. public static function suite()
  221. {
  222. return new PHPUnit_Framework_TestSuite( "ezcBaseFileIsAbsoluteTest" );
  223. }
  224. }
  225. ?>