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

1.1       misho       1: --TEST--
                      2: Test copy() function: usage variations - destination file access perms 
                      3: --SKIPIF--
                      4: <?php
                      5: if(substr(PHP_OS, 0, 3) == 'WIN')
                      6:   die("skip do not run on Windows");
                      7: 
                      8: // Skip if being run by root (files are always readable, writeable and executable)
                      9: $filename = dirname(__FILE__)."/copy_variation9_root_check.tmp";
                     10: $fp = fopen($filename, 'w');
                     11: fclose($fp);
                     12: if(fileowner($filename) == 0) {
                     13:         unlink ($filename);
                     14:         die('skip cannot be run as root');
                     15: }
                     16: unlink($filename);
                     17: ?>
                     18: --FILE--
                     19: <?php
                     20: /* Prototype: bool copy ( string $source, string $dest );
                     21:    Description: Makes a copy of the file source to dest.
                     22:      Returns TRUE on success or FALSE on failure.
                     23: */
                     24: 
                     25: /* Test copy(): Trying to copy source file to destination file with and without write permissions */
                     26: 
                     27: $file_path = dirname(__FILE__);
                     28: 
                     29: echo "*** Test copy() function: destination with/without write permissions ***\n";
                     30: $src_file_name = $file_path."/copy_variation9.tmp";
                     31: $file_handle =  fopen($src_file_name, "w");
                     32: fwrite($file_handle, str_repeat(b"Hello2world...\n", 100));
                     33: fclose($file_handle);
                     34: 
                     35: $dest_file_name =  $file_path."/copy_copy_variation9.tmp";
                     36: 
                     37: 
                     38: echo "\n-- With write permissions --\n";
                     39: var_dump( file_exists($src_file_name) );
                     40: var_dump( copy($src_file_name, $dest_file_name) );
                     41: var_dump( file_exists($dest_file_name) );
                     42: var_dump( filesize($dest_file_name) );
                     43: 
                     44: echo "\n-- Without write permissions --\n";
                     45: chmod($file_path."/copy_copy_variation9.tmp", 0555);  //No write permissions
                     46: var_dump( file_exists($src_file_name) );
                     47: var_dump( copy($src_file_name, $dest_file_name) );
                     48: var_dump( file_exists($dest_file_name) );
                     49: var_dump( filesize($dest_file_name) );
                     50: 
                     51: echo "*** Done ***\n";
                     52: ?>
                     53: 
                     54: --CLEAN--
                     55: <?php
                     56: unlink(dirname(__FILE__)."/copy_copy_variation9.tmp");
                     57: unlink(dirname(__FILE__)."/copy_variation9.tmp");
                     58: ?>
                     59: --EXPECTF--
                     60: *** Test copy() function: destination with/without write permissions ***
                     61: 
                     62: -- With write permissions --
                     63: bool(true)
                     64: bool(true)
                     65: bool(true)
                     66: int(1500)
                     67: 
                     68: -- Without write permissions --
                     69: bool(true)
                     70: 
                     71: Warning: %s
                     72: bool(false)
                     73: bool(true)
                     74: int(1500)
                     75: *** Done ***

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