Annotation of embedaddon/php/ext/standard/tests/file/is_writable_variation1.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test is_writable() and its alias is_writeable() function: usage variations - diff. path notations
                      3: --SKIPIF--
                      4: <?php
                      5: if (substr(PHP_OS, 0, 3) != 'WIN') {
                      6: 
                      7:   // Skip if being run by root (files are always readable, writeable and executable)
                      8:   $filename = dirname(__FILE__)."/is_writable_root_check.tmp";
                      9:   $fp = fopen($filename, 'w');
                     10:   fclose($fp);
                     11:   if(fileowner($filename) == 0) {
                     12:         unlink ($filename);
                     13:         die('skip cannot be run as root');
                     14:   }
                     15: 
                     16:   unlink($filename);
                     17: }
                     18: ?>
                     19: --FILE--
                     20: <?php
                     21: /* Prototype: bool is_writable ( string $filename );
                     22:    Description: Tells whether the filename is writable.
                     23: 
                     24:    is_writeable() is an alias of is_writable()
                     25: */
                     26: /* test is_writable() & is_writeable() with file having different filepath notation */
                     27: require dirname(__FILE__).'/file.inc';
                     28: echo "*** Testing is_writable(): usage variations ***\n";
                     29: 
                     30: $file_path = dirname(__FILE__);
                     31: mkdir("$file_path/is_writable_variation1");
                     32: 
                     33: // create a new temporary file
                     34: $fp = fopen("$file_path/is_writable_variation1/bar.tmp", "w");
                     35: fclose($fp);
                     36: 
                     37: /* array of files to be tested to check if they are writable
                     38:    using is_writable() function */
                     39: $files_arr = array(
                     40:   "$file_path/is_writable_variation1/bar.tmp",
                     41: 
                     42:   /* Testing a file trailing slash */
                     43:   "$file_path/is_writable_variation1/bar.tmp/",
                     44: 
                     45:   /* Testing file with double slashes */
                     46:   "$file_path/is_writable_variation1//bar.tmp",
                     47:   "$file_path//is_writable_variation1//bar.tmp",
                     48:   "$file_path/is_writable_variation1/*.tmp",
                     49:   "$file_path/is_writable_variation1/b*.tmp", 
                     50: 
                     51:   /* Testing Binary safe */
                     52:   "$file_path/is_writable_variation1".chr(0)."bar.tmp",
                     53:   "$file_path".chr(0)."is_writable_variation1/bar.tmp",
                     54:   "$file_path".chr(0)."is_writable_variation1/bar.tmp",
                     55:   
                     56:   /* Testing directories */
                     57:   ".",  // current directory, exp: bool(true)
                     58:   "$file_path/is_writable_variation1"  // temp directory, exp: bool(true)
                     59: );
                     60: $counter = 1;
                     61: /* loop through to test each element in the above array 
                     62:    is a writable file */
                     63: foreach($files_arr as $file) {
                     64:   echo "-- Iteration $counter --\n";
                     65:   var_dump( is_writable($file) );
                     66:   var_dump( is_writeable($file) );
                     67:   $counter++;
                     68:   clearstatcache();
                     69: }
                     70: 
                     71: echo "Done\n";
                     72: ?>
                     73: --CLEAN--
                     74: <?php
                     75: unlink(dirname(__FILE__)."/is_writable_variation1/bar.tmp");
                     76: rmdir(dirname(__FILE__)."/is_writable_variation1/");
                     77: ?>
                     78: --EXPECTF--
                     79: *** Testing is_writable(): usage variations ***
                     80: -- Iteration 1 --
                     81: bool(true)
                     82: bool(true)
                     83: -- Iteration 2 --
                     84: bool(%s)
                     85: bool(%s)
                     86: -- Iteration 3 --
                     87: bool(true)
                     88: bool(true)
                     89: -- Iteration 4 --
                     90: bool(true)
                     91: bool(true)
                     92: -- Iteration 5 --
                     93: bool(false)
                     94: bool(false)
                     95: -- Iteration 6 --
                     96: bool(false)
                     97: bool(false)
                     98: -- Iteration 7 --
1.1.1.2 ! misho      99: 
        !           100: Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           101: NULL
        !           102: 
        !           103: Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           104: NULL
1.1       misho     105: -- Iteration 8 --
1.1.1.2 ! misho     106: 
        !           107: Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           108: NULL
        !           109: 
        !           110: Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           111: NULL
1.1       misho     112: -- Iteration 9 --
1.1.1.2 ! misho     113: 
        !           114: Warning: is_writable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           115: NULL
        !           116: 
        !           117: Warning: is_writeable() expects parameter 1 to be a valid path, string given in %s on line %d
        !           118: NULL
1.1       misho     119: -- Iteration 10 --
                    120: bool(true)
                    121: bool(true)
                    122: -- Iteration 11 --
                    123: bool(true)
                    124: bool(true)
1.1.1.2 ! misho     125: Done

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