1--TEST-- 2Test dirname() function : usage variations 3--FILE-- 4<?php 5class temp 6{ 7 function __toString() { 8 return "Object"; 9 } 10} 11 12$file_path_variations = array ( 13 /* home dir shortcut char */ 14 "~/home/user/bar", 15 "~/home/user/bar/", 16 "~/home/user/bar.tar", 17 "~/home/user/bar.tar/", 18 19 /* with hotname:dir notation */ 20 "hostname:/home/user/bar.tar", 21 "hostname:/home/user/tbar.gz/", 22 "hostname:/home/user/My Pics.gz", 23 "hostname:/home/user/My Pics.gz/", 24 "hostname:/home/user/My Pics/", 25 "hostname:/home/user/My Pics", 26 27 /* path containing numeric string */ 28 "10.5", 29 "/10.5", 30 "/10.5/", 31 "10.5/", 32 "10/10.gz", 33 '0', 34 "0", 35 36 /* object */ 37 new temp, 38 39 /* path as spaces */ 40 " ", 41 ' ', 42 43 /* empty path */ 44 "", 45 '', 46 NULL, 47 null 48); 49 50function check_dirname( $paths ) { 51 $loop_counter = 0; 52 $noOfPaths = count($paths); 53 for( ; $loop_counter < $noOfPaths; $loop_counter++ ) { 54 echo "\n--Iteration "; 55 echo $loop_counter +1; 56 echo " --\n"; 57 var_dump( dirname($paths[$loop_counter]) ); 58 } 59} 60 61echo "*** Testing possible variations in path ***\n"; 62check_dirname( $file_path_variations ); 63 64echo "Done\n"; 65?> 66--EXPECTREGEX-- 67\*\*\* Testing possible variations in path \*\*\* 68 69--Iteration 1 -- 70string\(11\) "~(\\|\/)home(\\|\/)user" 71 72--Iteration 2 -- 73string\(11\) "~(\\|\/)home(\\|\/)user" 74 75--Iteration 3 -- 76string\(11\) "~(\\|\/)home(\\|\/)user" 77 78--Iteration 4 -- 79string\(11\) "~(\\|\/)home(\\|\/)user" 80 81--Iteration 5 -- 82string\(19\) "hostname:(\\|\/)home(\\|\/)user" 83 84--Iteration 6 -- 85string\(19\) "hostname:(\\|\/)home(\\|\/)user" 86 87--Iteration 7 -- 88string\(19\) "hostname:(\\|\/)home(\\|\/)user" 89 90--Iteration 8 -- 91string\(19\) "hostname:(\\|\/)home(\\|\/)user" 92 93--Iteration 9 -- 94string\(19\) "hostname:(\\|\/)home(\\|\/)user" 95 96--Iteration 10 -- 97string\(19\) "hostname:(\\|\/)home(\\|\/)user" 98 99--Iteration 11 -- 100string\(1\) "." 101 102--Iteration 12 -- 103string\(1\) "(\\|\/)" 104 105--Iteration 13 -- 106string\(1\) "(\\|\/)" 107 108--Iteration 14 -- 109string\(1\) "." 110 111--Iteration 15 -- 112string\(2\) "10" 113 114--Iteration 16 -- 115string\(1\) "." 116 117--Iteration 17 -- 118string\(1\) "." 119 120--Iteration 18 -- 121string\(1\) "." 122 123--Iteration 19 -- 124string\(1\) "." 125 126--Iteration 20 -- 127string\(1\) "." 128 129--Iteration 21 -- 130string\(0\) "" 131 132--Iteration 22 -- 133string\(0\) "" 134 135--Iteration 23 -- 136string\(0\) "" 137 138--Iteration 24 -- 139string\(0\) "" 140Done 141