Annotation of embedaddon/php/ext/standard/tests/file/file_put_contents_variation7-win32.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: Test file_put_contents() function : usage variation - various absolute and relative paths
        !             3: --CREDITS--
        !             4: Dave Kelsey <d_kelsey@uk.ibm.com>
        !             5: --SKIPIF--
        !             6: <?php
        !             7: if(substr(PHP_OS, 0, 3) != "WIN")
        !             8:   die("skip Only run on Windows");
        !             9: ?>
        !            10: --FILE--
        !            11: <?php
        !            12: /* Prototype  : int file_put_contents(string file, mixed data [, int flags [, resource context]])
        !            13:  * Description: Write/Create a file with contents data and return the number of bytes written 
        !            14:  * Source code: ext/standard/file.c
        !            15:  * Alias to functions: 
        !            16:  */
        !            17: 
        !            18: echo "*** Testing file_put_contents() : usage variation ***\n";
        !            19: 
        !            20: $mainDir = "filePutContentsVar7.dir";
        !            21: $subDir = "filePutContentsVar7Sub";
        !            22: $absMainDir = dirname(__FILE__)."/".$mainDir;
        !            23: mkdir($absMainDir);
        !            24: $absSubDir = $absMainDir."\\".$subDir;
        !            25: mkdir($absSubDir);
        !            26: 
        !            27: $old_dir_path = getcwd();
        !            28: chdir(dirname(__FILE__));
        !            29: $unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
        !            30: 
        !            31: 
        !            32: // Note invalid dirs in p8 result in (The system cannot find the path specified.)
        !            33: // rather than No Such File or Directory in php.net
        !            34: $allDirs = array(
        !            35:   // absolute paths
        !            36:   "$absSubDir\\",
        !            37:   "$absSubDir\\..\\".$subDir,
        !            38:   "$absSubDir\\\\..\\.\\".$subDir,
        !            39:   "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
        !            40:   "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
        !            41:   "$absSubDir\\BADDIR",
        !            42:   
        !            43:   // relative paths
        !            44:   $mainDir."\\".$subDir,
        !            45:   $mainDir."\\\\".$subDir, 
        !            46:    $mainDir."\\\\\\".$subDir, 
        !            47:   ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
        !            48:   "BADDIR",  
        !            49:   
        !            50:   // unixifed path
        !            51:   $unixifiedDir,
        !            52: );
        !            53: 
        !            54: $filename = 'FileGetContentsVar7.tmp';
        !            55: $absFile = $absSubDir.'/'.$filename;
        !            56: $data = "This was the written data";
        !            57: 
        !            58: for($i = 0; $i<count($allDirs); $i++) {
        !            59:   $j = $i+1;
        !            60:   $dir = $allDirs[$i];
        !            61:   echo "\n-- Iteration $j --\n";
        !            62:   $res = file_put_contents($dir."\\".$filename, ($data + $i));
        !            63:   if ($res !== false) {
        !            64:       $in = file_get_contents($absFile);
        !            65:       if ($in == ($data + $i)) {
        !            66:          echo "Data written correctly\n";
        !            67:       }
        !            68:       else {
        !            69:          echo "Data not written correctly or to correct place\n";
        !            70:       }
        !            71:       unlink($dir."/".$filename);
        !            72:   }
        !            73:   else {
        !            74:      echo "No data written\n";
        !            75:   }
        !            76:       
        !            77: }
        !            78: 
        !            79: chdir($old_dir_path);
        !            80: rmdir($absSubDir);
        !            81: rmdir($absMainDir);
        !            82: 
        !            83: echo "\n*** Done ***\n";
        !            84: ?>
        !            85: --EXPECTF--
        !            86: *** Testing file_put_contents() : usage variation ***
        !            87: 
        !            88: -- Iteration 1 --
        !            89: Data written correctly
        !            90: 
        !            91: -- Iteration 2 --
        !            92: Data written correctly
        !            93: 
        !            94: -- Iteration 3 --
        !            95: Data written correctly
        !            96: 
        !            97: -- Iteration 4 --
        !            98: Data written correctly
        !            99: 
        !           100: -- Iteration 5 --
        !           101: 
        !           102: Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\..\\\filePutContentsVar7Sub\\..\\..\filePutContentsVar7Sub\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
        !           103: No data written
        !           104: 
        !           105: -- Iteration 6 --
        !           106: 
        !           107: Warning: file_put_contents(%sfilePutContentsVar7.dir\filePutContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
        !           108: No data written
        !           109: 
        !           110: -- Iteration 7 --
        !           111: Data written correctly
        !           112: 
        !           113: -- Iteration 8 --
        !           114: Data written correctly
        !           115: 
        !           116: -- Iteration 9 --
        !           117: Data written correctly
        !           118: 
        !           119: -- Iteration 10 --
        !           120: Data written correctly
        !           121: 
        !           122: -- Iteration 11 --
        !           123: 
        !           124: Warning: file_put_contents(BADDIR\FileGetContentsVar7.tmp): failed to open stream: %s in %s on line %d
        !           125: No data written
        !           126: 
        !           127: -- Iteration 12 --
        !           128: Data written correctly
        !           129: 
        !           130: *** Done ***

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