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

1.1       misho       1: --TEST--
                      2: Test symlink(), linkinfo(), link() and is_link() functions : usage variations - link & dir perms.
                      3: --SKIPIF--
                      4: <?php
                      5: if ( substr(PHP_OS, 0, 3) == 'WIN' ) {
                      6:     die('skip no symlinks on Windows');
                      7: }
                      8: if ( substr(PHP_OS, 0, 3) == 'MAC' ) {
                      9:     die('skip Not valid for MacOS');
                     10: }
                     11: if (PHP_INT_SIZE != 4) {
                     12:   die("skip this test is for 32bit platform only");
                     13: }
                     14: 
                     15: // Skip if being run by root (files are always readable, writeable and executable)
                     16: $filename = dirname(__FILE__)."/symlink_link_linkinfo_is_link6_check_root.tmp";
                     17: $fp = fopen($filename, 'w');
                     18: fclose($fp);
                     19: if(fileowner($filename) == 0) {
                     20:         unlink ($filename);
                     21:         die('skip cannot be run as root');
                     22: }
                     23: 
                     24: unlink($filename);
                     25: ?>
                     26: --FILE--
                     27: <?php
                     28: /* Prototype: bool symlink ( string $target, string $link );
                     29:    Description: creates a symbolic link to the existing target with the specified name link
                     30: 
                     31:    Prototype: bool is_link ( string $filename );
                     32:    Description: Tells whether the given file is a symbolic link.
                     33: 
                     34:    Prototype: bool link ( string $target, string $link );
                     35:    Description: Create a hard link
                     36: 
                     37:    Prototype: int linkinfo ( string $path );
                     38:    Description: Gets information about a link
                     39: */
                     40: 
                     41: /* Variation 6 : Change permission of directory and try creating links inside that directory */
                     42: $file_path = dirname(__FILE__);
                     43: 
                     44: echo "*** Creating links in a directory without permission to allow the operation ***\n";
                     45: // temp file used
                     46: $dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
                     47: mkdir($dirname);
                     48: $filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
                     49: 
                     50: // remove all permissions from dir
                     51: var_dump( chmod($dirname, 0000) );
                     52: 
                     53: echo "\n-- Working with soft links --\n";
                     54: $linkname = "$dirname/non_existent_link_variation5.tmp";
                     55: 
                     56: // expected: false
                     57: var_dump( symlink($filename, $linkname) ); // this link won't get created 
                     58: var_dump( linkinfo($linkname) );
                     59: var_dump( is_link($linkname) );
                     60: // clear the cache
                     61: clearstatcache();
                     62: 
                     63: echo "\n-- Working with hard links --\n";
                     64: // expected: false
                     65: var_dump( link($filename, $linkname) );
                     66: var_dump( linkinfo($linkname) );
                     67: var_dump( is_link($linkname) );
                     68: // clear the cache
                     69: clearstatcache();
                     70: 
                     71: chmod($dirname, 0777);  // to enable dir deletion
                     72: echo "Done\n";
                     73: ?>
                     74: --CLEAN--
                     75: <?php
                     76: $file_path = dirname(__FILE__);
                     77: $dirname = "$file_path/symlink_link_linkinfo_is_link_variation6";
                     78: $filename = "$dirname/symlink_link_linkinfo_is_link_variation6.tmp";
                     79: if(file_exists($filename)) {
                     80: unlink($filename);
                     81: }
                     82: if(file_exists($dirname)) {
                     83: rmdir($dirname);
                     84: }
                     85: ?>
                     86: --EXPECTF--
                     87: *** Creating links in a directory without permission to allow the operation ***
                     88: bool(true)
                     89: 
                     90: -- Working with soft links --
                     91: 
                     92: Warning: symlink(): Permission denied in %s on line %d
                     93: bool(false)
                     94: 
                     95: Warning: linkinfo(): Permission denied in %s on line %d
                     96: int(-1)
                     97: bool(false)
                     98: 
                     99: -- Working with hard links --
                    100: 
                    101: Warning: link(): Permission denied in %s on line %d
                    102: bool(false)
                    103: 
                    104: Warning: linkinfo(): Permission denied in %s on line %d
                    105: int(-1)
                    106: bool(false)
                    107: Done

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