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

1.1       misho       1: --TEST--
                      2: Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link name stored in an array/object
                      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 1 : Creating links across directories where linkname is stored as an object and array member */
                     25: 
                     26: // creating temp directory which will contain temp file and links created 
                     27: $file_path = dirname(__FILE__);
                     28: $dirname = "$file_path/symlink_link_linkinfo_is_link_variation1/test/home";
                     29: mkdir($dirname, 0777, true);
                     30: 
                     31: // creating temp file; links are created to this file later on
                     32: $filename = "$file_path/symlink_link_linkinfo_is_link_variation1/symlink_link_linkinfo_is_link_variation1.tmp";
                     33: $fp = fopen($filename, "w");
                     34: fclose($fp);
                     35: 
                     36: echo "*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object ***\n";
                     37: class object_temp {
                     38:   var $linkname;
                     39:   function object_temp($link) {
                     40:     $this->linkname = $link;
                     41:   }
                     42: }
                     43: 
                     44: $obj = new object_temp("$dirname/symlink_link_linkinfo_is_link_link.tmp");
                     45: /* Testing on soft links */
                     46: echo "\n-- Working with soft links --\n";
                     47: // creating soft link
                     48: var_dump( symlink($filename, $obj->linkname) );
                     49: // check if the link exists
                     50: var_dump( linkinfo($obj->linkname) );
                     51: // check if link is soft link
                     52: var_dump( is_link($obj->linkname) );
                     53: // delete the link created
                     54: unlink($obj->linkname);
                     55: // clear the cache
                     56: clearstatcache();
                     57: 
                     58: /* Testing on hard links */
                     59: echo "\n-- Working with hard links --\n";
                     60: // creating hard link
                     61: var_dump( link($filename, $obj->linkname) ); 
                     62: // check if the link exists
                     63: var_dump( linkinfo($obj->linkname) );
                     64: // check if link is soft link; expected: false as the link is a hardlink
                     65: var_dump( is_link($obj->linkname) ); 
                     66: // delete the link created
                     67: unlink($obj->linkname);
                     68: // clear the cache
                     69: clearstatcache();
                     70: 
                     71: echo "\n*** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***\n";
                     72: 
                     73: $link_arr = array("$dirname/symlink_link_linkinfo_is_link_link.tmp");
                     74: 
                     75: /* Testing on soft links */
                     76: echo "\n-- Working with soft links --\n";
                     77: // creating soft link
                     78: var_dump( symlink($filename, $link_arr[0]) );
                     79: // check if the link exist
                     80: var_dump( linkinfo($link_arr[0]) );
                     81: // check if link is soft link
                     82: var_dump( is_link($link_arr[0]) );
                     83: // delete the link created
                     84: unlink($link_arr[0]);
                     85: // clear the cache
                     86: clearstatcache();
                     87: 
                     88: /* Testing on hard links */
                     89: echo "\n-- Working with hard links --\n";
                     90: // creating hard link
                     91: var_dump( link($filename, $link_arr[0]) );
                     92: // check if the link exist
                     93: var_dump( linkinfo($link_arr[0]) );
                     94: // check if link is soft link; expected: false as this is a hardlink
                     95: var_dump( is_link($link_arr[0]) );
                     96: // delete the links created
                     97: unlink($link_arr[0]);
                     98: // clear the cache
                     99: clearstatcache();
                    100: 
                    101: echo "Done\n";
                    102: ?>
                    103: --CLEAN--
                    104: <?php
                    105: $file_path = dirname(__FILE__);
                    106: $dirname = "$file_path/symlink_link_linkinfo_is_link_variation1";
                    107: unlink("$dirname/symlink_link_linkinfo_is_link_variation1.tmp");
                    108: rmdir("$dirname/test/home");
                    109: rmdir("$dirname/test");
                    110: rmdir($dirname);
                    111: ?>
                    112: --EXPECTF--
                    113: *** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members in an object ***
                    114: 
                    115: -- Working with soft links --
                    116: bool(true)
                    117: int(%d)
                    118: bool(true)
                    119: 
                    120: -- Working with hard links --
                    121: bool(true)
                    122: int(%d)
                    123: bool(false)
                    124: 
                    125: *** Testing symlink(), link(), linkinfo() and is_link() with linknames stored as members of an array ***
                    126: 
                    127: -- Working with soft links --
                    128: bool(true)
                    129: int(%d)
                    130: bool(true)
                    131: 
                    132: -- Working with hard links --
                    133: bool(true)
                    134: int(%d)
                    135: bool(false)
                    136: Done

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