Annotation of embedaddon/php/ext/standard/tests/file/symlink_link_linkinfo_is_link_variation8.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test symlink(), linkinfo(), link() and is_link() functions : usage variations - try link with same name in diff. dir
                      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: /* Variation 8 : Create soft/hard link to different directory */
                     25: 
                     26: /* creating link to a file in different dir with the same name as the file */
                     27: echo "\n*** Create hard link in different directory with same filename ***\n";
                     28: // temp file used
                     29: $file_path = dirname(__FILE__);
                     30: $filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
                     31: // temp link name used
                     32: $dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
                     33: mkdir($dirname);
                     34: $linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
                     35: // create temp file
                     36: $fp = fopen($filename, "w");
                     37: fclose($fp);
                     38: 
                     39: var_dump( link($filename, $dirname."/") ); // this fails indicating file exists
                     40: // ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
                     41: var_dump( link($filename, $dirname."/".$linkname) );  // this works fine
                     42: // delete link
                     43: unlink($dirname."/".$linkname);
                     44: // delete temp file
                     45: unlink($filename);
                     46: // delete temp dir
                     47: rmdir($dirname);
                     48: 
                     49: echo "\n*** Create soft link in different directory with same filename ***\n";
                     50: $filename = "$file_path/symlink_link_linkinfo_is_link_variation8.tmp";
                     51: // temp link name used
                     52: $dirname = "$file_path/symlink_link_linkinfo_is_link1_variation8";
                     53: mkdir($dirname);
                     54: $linkname = "symlink_link_linkinfo_is_link_variation8.tmp";
                     55: // create temp file
                     56: $fp = fopen($filename, "w");
                     57: fclose($fp);
                     58: 
                     59: var_dump( symlink($filename, $dirname."/") ); // this fails indicating file exists
                     60: // ok, creates "$file_path/symlink_link_linkinfo_is_link1_variation8/symlink_link_linkinfo_is_link_variation8.tmp" link
                     61: var_dump( symlink($filename, $dirname."/".$linkname) );  // this works fine
                     62: // delete link
                     63: unlink($dirname."/".$linkname);
                     64: // delete temp file
                     65: unlink($filename);
                     66: // delete temp dir
                     67: rmdir($dirname);
                     68: 
                     69: echo "Done\n";
                     70: ?>
                     71: --EXPECTF--
                     72: *** Create hard link in different directory with same filename ***
                     73: 
                     74: Warning: link(): File exists in %s on line %d
                     75: bool(false)
                     76: bool(true)
                     77: 
                     78: *** Create soft link in different directory with same filename ***
                     79: 
                     80: Warning: symlink(): File exists in %s on line %d
                     81: bool(false)
                     82: bool(true)
                     83: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>