Annotation of embedaddon/php/ext/standard/tests/dir/opendir_variation7.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test opendir() function : usage variations - different directory 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__) . "/opendir_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  : mixed opendir(string $path[, resource $context])
        !            21:  * Description: Open a directory and return a dir_handle 
        !            22:  * Source code: ext/standard/dir.c
        !            23:  */
        !            24: 
        !            25: /*
        !            26:  * Open a directory using opendir() with different directory permissions
        !            27:  */
        !            28: 
        !            29: echo "*** Testing opendir() : usage variations ***\n";
        !            30: 
        !            31: // create the temporary directory
        !            32: $file_path = dirname(__FILE__);
        !            33: $dir_path = $file_path . "/opendir_variation7";
        !            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: 
        !            56: $iterator = 1;
        !            57: foreach ($permission_values as $perm) {
        !            58: 
        !            59:        echo "\n-- Iteration $iterator --\n";
        !            60:        // try to remove the dir if exists  & create
        !            61:        if (is_dir($dir_path)){
        !            62:                chmod ($dir_path, 0777); // change dir permission to allow all operation
        !            63:                rmdir ($dir_path);
        !            64:        }
        !            65:        mkdir($dir_path);
        !            66: 
        !            67:        // change the dir permisson to test dir on it
        !            68:        var_dump( chmod($dir_path, $perm) );
        !            69: 
        !            70:        var_dump($dh = opendir($dir_path));
        !            71:        
        !            72:        if (is_resource($dh)) {
        !            73:                closedir($dh);
        !            74:        }
        !            75:        $iterator++;
        !            76: }
        !            77: ?>
        !            78: ===DONE===
        !            79: --CLEAN--
        !            80: <?php
        !            81: // deleting temporary directory
        !            82: $dir_path = dirname(__FILE__) . "/opendir_variation7";
        !            83: rmdir($dir_path);
        !            84: ?>
        !            85: --EXPECTF--
        !            86: *** Testing opendir() : usage variations ***
        !            87: 
        !            88: -- Iteration 1 --
        !            89: bool(true)
        !            90: resource(%d) of type (stream)
        !            91: 
        !            92: -- Iteration 2 --
        !            93: bool(true)
        !            94: resource(%d) of type (stream)
        !            95: 
        !            96: -- Iteration 3 --
        !            97: bool(true)
        !            98: resource(%d) of type (stream)
        !            99: 
        !           100: -- Iteration 4 --
        !           101: bool(true)
        !           102: resource(%d) of type (stream)
        !           103: 
        !           104: -- Iteration 5 --
        !           105: bool(true)
        !           106: resource(%d) of type (stream)
        !           107: 
        !           108: -- Iteration 6 --
        !           109: bool(true)
        !           110: resource(%d) of type (stream)
        !           111: 
        !           112: -- Iteration 7 --
        !           113: bool(true)
        !           114: resource(%d) of type (stream)
        !           115: 
        !           116: -- Iteration 8 --
        !           117: bool(true)
        !           118: resource(%d) of type (stream)
        !           119: 
        !           120: -- Iteration 9 --
        !           121: bool(true)
        !           122: resource(%d) of type (stream)
        !           123: 
        !           124: -- Iteration 10 --
        !           125: bool(true)
        !           126: resource(%d) of type (stream)
        !           127: ===DONE===

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