Return to symlink_link_linkinfo_is_link_basic1.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / file |
1.1 misho 1: --TEST-- 2: Test symlink(), linkinfo(), link() and is_link() functions: basic functionality - link to files 3: --SKIPIF-- 4: <?php 5: if (substr(PHP_OS, 0, 3) == 'WIN') { 6: die('skip no symlinks on Windows'); 7: } 8: ?> 9: --FILE-- 10: <?php 11: /* Prototype: bool symlink ( string $target, string $link ); 12: Description: creates a symbolic link to the existing target with the specified name link 13: 14: Prototype: bool is_link ( string $filename ); 15: Description: Tells whether the given file is a symbolic link. 16: 17: Prototype: bool link ( string $target, string $link ); 18: Description: Create a hard link 19: 20: Prototype: int linkinfo ( string $path ); 21: Description: Gets information about a link 22: */ 23: 24: $file_path = dirname(__FILE__); 25: 26: // temp dir created in present working directory 27: $dirname = "symlink_link_linkinfo_is_link_basic1"; 28: mkdir("$file_path/$dirname"); // creating temp dir 29: 30: /* Creating soft/hard link to $filename created in temp directory $dirname 31: and checking linkinfo() and is_link() on the link created */ 32: 33: echo "*** Testing symlink(), linkinfo(), link() and is_link() : basic functionality ***\n"; 34: 35: // creating file in $dirname, links are created to the this file 36: $filename = "$file_path/$dirname/symlink_link_linkinfo_is_link_basic1.tmp"; 37: $filename = fopen($filename, "w"); 38: fclose($filename); 39: 40: // name of the soft link created to $filename 41: $sym_linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_softlink_basic1.tmp"; 42: 43: // name of the hard link created to $filename 44: $linkname = "$file_path/$dirname/symlink_link_linkinfo_is_link_hardlink_basic1.tmp"; 45: 46: // filename stored in array with single and double slash notation in its path 47: $files = array ( 48: "$file_path/$dirname/symlink_link_linkinfo_is_link_basic1.tmp", 49: "$file_path//$dirname//symlink_link_linkinfo_is_link_basic1.tmp" 50: ); 51: 52: $counter = 1; 53: /* create soft/hard link to the file 54: and check linkinfo() and is_link() on the link created */ 55: foreach($files as $file) { 56: echo "\n-- Iteration $counter --\n"; 57: echo "-- Testing on soft links --\n"; 58: // create soft link 59: var_dump( symlink($file, $sym_linkname) ); 60: // checking information of link with linkinfo() 61: var_dump( linkinfo($sym_linkname) ); 62: // checking if given file is soft link 63: var_dump( is_link($sym_linkname) ); 64: // clear the cache 65: clearstatcache(); 66: 67: // testing on hard link 68: echo "-- Testing on hard links --\n"; 69: // creating hard link 70: var_dump( link($file, $linkname) ); 71: // checking information of link with linkinfo() 72: var_dump( linkinfo($linkname) ); 73: // checking if given link is soft link; expected: false 74: var_dump( is_link($linkname) ); 75: // clear the cache 76: clearstatcache(); 77: 78: // deleting the links 79: unlink($sym_linkname); 80: unlink($linkname); 81: $counter++; 82: } 83: 84: echo "Done\n"; 85: ?> 86: --CLEAN-- 87: <?php 88: $dirname = dirname(__FILE__)."/symlink_link_linkinfo_is_link_basic1"; 89: unlink("$dirname/symlink_link_linkinfo_is_link_basic1.tmp"); 90: rmdir($dirname); 91: ?> 92: --EXPECTF-- 93: *** Testing symlink(), linkinfo(), link() and is_link() : basic functionality *** 94: 95: -- Iteration 1 -- 96: -- Testing on soft links -- 97: bool(true) 98: int(%d) 99: bool(true) 100: -- Testing on hard links -- 101: bool(true) 102: int(%d) 103: bool(false) 104: 105: -- Iteration 2 -- 106: -- Testing on soft links -- 107: bool(true) 108: int(%d) 109: bool(true) 110: -- Testing on hard links -- 111: bool(true) 112: int(%d) 113: bool(false) 114: Done