Annotation of embedaddon/php/ext/standard/tests/dir/readdir_variation5.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test readdir() function : usage variations - different permissions
                      3: --SKIPIF--
                      4: <?php
                      5: if( substr(PHP_OS, 0, 3) == 'WIN') {
                      6:   die('skip Not for Windows');
                      7: }
                      8: // Skip if being run by root (files are always readable, writeable and executable)
                      9: $filename = dirname(__FILE__)."/readdir_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\n');
                     15: }
                     16: unlink($filename);
                     17: ?>
                     18: --FILE--
                     19: <?php
                     20: /* Prototype  : string readdir([resource $dir_handle])
                     21:  * Description: Read directory entry from dir_handle 
                     22:  * Source code: ext/standard/dir.c
                     23:  */
                     24: 
                     25: /*
                     26:  * Open a directory with different premissions then try to read it
                     27:  * to test behaviour of readdir()
                     28:  */
                     29: 
                     30: echo "*** Testing readdir() : usage variations ***\n";
                     31: 
                     32: // create the temporary directory
                     33: $dir_path = dirname(__FILE__) . "/readdir_variation5";
                     34: mkdir($dir_path);
                     35: 
                     36: /* different values for directory permissions */
                     37: $permission_values = array(
                     38: /*1*/  0477,  // owner has read only, other and group has rwx
                     39:        0677,  // owner has rw only, other and group has rwx
                     40: 
                     41: /*3*/  0444,  // all have read only
                     42:        0666,  // all have rw only
                     43: 
                     44: /*5*/  0400,  // owner has read only, group and others have no permission
                     45:        0600,   // owner has rw only, group and others have no permission
                     46: 
                     47: /*7*/  0470,  // owner has read only, group has rwx & others have no permission
                     48:        0407,  // owner has read only, other has rwx & group has no permission
                     49: 
                     50: /*9*/  0670,  // owner has rw only, group has rwx & others have no permission
                     51: /*10*/ 0607   // owner has rw only, group has no permission and others have rwx
                     52: );
                     53: 
                     54: // Open directory with different permission values, read and close, expected: none of them to succeed.
                     55: $iterator = 1;
                     56: foreach($permission_values as $perm) {
                     57:        echo "\n-- Iteration $iterator --\n";
                     58:        
                     59:        if (is_dir($dir_path)) {
                     60:                chmod ($dir_path, 0777); // change dir permission to allow all operation
                     61:                rmdir ($dir_path);
                     62:        }
                     63:        mkdir($dir_path);
                     64: 
                     65:        // change the dir permisson to test dir on it
                     66:        var_dump( chmod($dir_path, $perm) );
                     67:        var_dump($dh = opendir($dir_path));
                     68: 
                     69:        echo "-- Calling readdir() --\n";
                     70:        var_dump(readdir($dh));
                     71: 
                     72:        closedir($dh);
                     73:        $iterator++;
                     74: }
                     75: ?>
                     76: ===DONE===
                     77: --CLEAN--
                     78: <?php
                     79: $dir_path = dirname(__FILE__) . "/readdir_variation5";
                     80: rmdir($dir_path);
                     81: ?>
                     82: --EXPECTF--
                     83: *** Testing readdir() : usage variations ***
                     84: 
                     85: -- Iteration 1 --
                     86: bool(true)
                     87: resource(%d) of type (stream)
                     88: -- Calling readdir() --
                     89: string(%d) "%s"
                     90: 
                     91: -- Iteration 2 --
                     92: bool(true)
                     93: resource(%d) of type (stream)
                     94: -- Calling readdir() --
                     95: string(%d) "%s"
                     96: 
                     97: -- Iteration 3 --
                     98: bool(true)
                     99: resource(%d) of type (stream)
                    100: -- Calling readdir() --
                    101: string(%d) "%s"
                    102: 
                    103: -- Iteration 4 --
                    104: bool(true)
                    105: resource(%d) of type (stream)
                    106: -- Calling readdir() --
                    107: string(%d) "%s"
                    108: 
                    109: -- Iteration 5 --
                    110: bool(true)
                    111: resource(%d) of type (stream)
                    112: -- Calling readdir() --
                    113: string(%d) "%s"
                    114: 
                    115: -- Iteration 6 --
                    116: bool(true)
                    117: resource(%d) of type (stream)
                    118: -- Calling readdir() --
                    119: string(%d) "%s"
                    120: 
                    121: -- Iteration 7 --
                    122: bool(true)
                    123: resource(%d) of type (stream)
                    124: -- Calling readdir() --
                    125: string(%d) "%s"
                    126: 
                    127: -- Iteration 8 --
                    128: bool(true)
                    129: resource(%d) of type (stream)
                    130: -- Calling readdir() --
                    131: string(%d) "%s"
                    132: 
                    133: -- Iteration 9 --
                    134: bool(true)
                    135: resource(%d) of type (stream)
                    136: -- Calling readdir() --
                    137: string(%d) "%s"
                    138: 
                    139: -- Iteration 10 --
                    140: bool(true)
                    141: resource(%d) of type (stream)
                    142: -- Calling readdir() --
                    143: string(%d) "%s"
                    144: ===DONE===

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