Annotation of embedaddon/php/ext/standard/tests/file/fopen_variation8.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test fopen() function : variation: use include path and stream context (relative directories in path)
        !             3: --CREDITS--
        !             4: Dave Kelsey <d_kelsey@uk.ibm.com>
        !             5: --FILE--
        !             6: <?php
        !             7: /* Prototype  : resource fopen(string filename, string mode [, bool use_include_path [, resource context]])
        !             8:  * Description: Open a file or a URL and return a file pointer 
        !             9:  * Source code: ext/standard/file.c
        !            10:  * Alias to functions: 
        !            11:  */
        !            12: 
        !            13: 
        !            14: 
        !            15: $thisTestDir =  basename(__FILE__, ".php") . ".dir";
        !            16: mkdir($thisTestDir);
        !            17: chdir($thisTestDir);
        !            18: 
        !            19: //create the include directory structure
        !            20: $workingDir = "workdir";
        !            21: $filename =  basename(__FILE__, ".php") . ".tmp";
        !            22: $scriptDir = dirname(__FILE__);
        !            23: $baseDir = getcwd();
        !            24: $secondFile = $baseDir."/dir2/".$filename;
        !            25: $firstFile = "../dir1/".$filename;
        !            26: $scriptFile = $scriptDir.'/'.$filename;
        !            27: 
        !            28: $newdirs = array("dir1", "dir2", "dir3");
        !            29: $pathSep = ":";
        !            30: $newIncludePath = "";
        !            31: if(substr(PHP_OS, 0, 3) == 'WIN' ) {
        !            32:    $pathSep = ";";
        !            33: }
        !            34: foreach($newdirs as $newdir) {
        !            35:    mkdir($newdir);
        !            36:    $newIncludePath .= '../'.$newdir.$pathSep;
        !            37: }
        !            38: mkdir($workingDir);
        !            39: chdir($workingDir);
        !            40: 
        !            41: //define the files to go into these directories, create one in dir2
        !            42: echo "\n--- testing include path ---\n";
        !            43: set_include_path($newIncludePath);   
        !            44: $modes = array("r", "r+", "rt");
        !            45: foreach($modes as $mode) {
        !            46:     test_fopen($mode);
        !            47: }
        !            48: restore_include_path();
        !            49: 
        !            50: // remove the directory structure
        !            51: chdir($baseDir);
        !            52: rmdir($workingDir);
        !            53: foreach($newdirs as $newdir) {
        !            54:    rmdir($newdir);
        !            55: }
        !            56: 
        !            57: chdir("..");
        !            58: rmdir($thisTestDir);
        !            59: 
        !            60: function test_fopen($mode) {
        !            61:    global $scriptFile, $secondFile, $firstFile, $filename;
        !            62:    
        !            63:    // create a file in the middle directory
        !            64:    $h = fopen($secondFile, "w");
        !            65:    fwrite($h, (binary) "in dir2");
        !            66:    fclose($h);
        !            67: 
        !            68:    echo "\n** testing with mode=$mode **\n";
        !            69:    // should read dir2 file
        !            70:    $h = fopen($filename, $mode, true);
        !            71:    fpassthru($h);
        !            72:    fclose($h);
        !            73:    echo "\n";
        !            74: 
        !            75:    //create a file in dir1
        !            76:    $h = fopen($firstFile, "w");
        !            77:    fwrite($h, (binary) "in dir1");
        !            78:    fclose($h);
        !            79:    
        !            80:    //should now read dir1 file
        !            81:    $h = fopen($filename, $mode, true);
        !            82:    fpassthru($h);
        !            83:    fclose($h);
        !            84:    echo "\n";
        !            85:    
        !            86:    // create a file in working directory
        !            87:    $h = fopen($filename, "w");
        !            88:    fwrite($h, (binary) "in working dir");
        !            89:    fclose($h);
        !            90:    
        !            91:    //should read the dir1 file
        !            92:    $h = fopen($filename, $mode, true);
        !            93:    fpassthru($h);
        !            94:    fclose($h);
        !            95:    echo "\n";
        !            96:    
        !            97:    unlink($firstFile);
        !            98:    unlink($secondFile);
        !            99:    
        !           100:    //should read the working dir file
        !           101:    $h = fopen($filename, $mode, true);
        !           102:    fpassthru($h);
        !           103:    fclose($h);
        !           104:    echo "\n";
        !           105:    
        !           106:    // create a file in the script directory
        !           107:    $h = fopen($scriptFile, "w");
        !           108:    fwrite($h, (binary) "in script dir");
        !           109:    fclose($h);
        !           110:    
        !           111:    //should read the file in script dir
        !           112:    $h = fopen($filename, $mode, true);
        !           113:    fpassthru($h);
        !           114:    fclose($h);
        !           115:    echo "\n";
        !           116:      
        !           117:    //cleanup
        !           118:    unlink($filename);
        !           119:    unlink($scriptFile);
        !           120: 
        !           121: }
        !           122: 
        !           123: ?>
        !           124: ===DONE===
        !           125: --EXPECTF--
        !           126: 
        !           127: --- testing include path ---
        !           128: 
        !           129: ** testing with mode=r **
        !           130: in dir2
        !           131: in dir1
        !           132: in dir1
        !           133: in working dir
        !           134: in script dir
        !           135: 
        !           136: ** testing with mode=r+ **
        !           137: in dir2
        !           138: in dir1
        !           139: in dir1
        !           140: in working dir
        !           141: in script dir
        !           142: 
        !           143: ** testing with mode=rt **
        !           144: in dir2
        !           145: in dir1
        !           146: in dir1
        !           147: in working dir
        !           148: in script dir
        !           149: ===DONE===
        !           150: 

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