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

1.1     ! misho       1: --TEST--
        !             2: Test tempnam() function: usage variations - invalid/non-existing dir
        !             3: --SKIPIF--
        !             4: <?php
        !             5: if(substr(PHP_OS, 0, 3) == "WIN")
        !             6:   die("skip Do not run on Windows");
        !             7: ?>
        !             8: --FILE--
        !             9: <?php
        !            10: /* Prototype:  string tempnam ( string $dir, string $prefix );
        !            11:    Description: Create file with unique file name.
        !            12: */
        !            13: 
        !            14: /* Passing invalid/non-existing args for $dir, 
        !            15:      hence the unique files will be created in temporary dir */
        !            16: 
        !            17: echo "*** Testing tempnam() with invalid/non-existing directory names ***\n";
        !            18: /* An array of names, which will be passed as a dir name */ 
        !            19: $names_arr = array(
        !            20:   /* Invalid args */ 
        !            21:   -1,
        !            22:   TRUE,
        !            23:   FALSE,
        !            24:   NULL,
        !            25:   "",
        !            26:   " ",
        !            27:   "\0",
        !            28:   array(),
        !            29: 
        !            30:   /* Non-existing dirs */
        !            31:   "/no/such/file/dir", 
        !            32:   "php"
        !            33: 
        !            34: );
        !            35: 
        !            36: for( $i=0; $i<count($names_arr); $i++ ) {
        !            37:   echo "-- Iteration $i --\n";
        !            38:   $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
        !            39: 
        !            40:   if( file_exists($file_name) ){
        !            41: 
        !            42:     echo "File name is => ";
        !            43:     print($file_name);
        !            44:     echo "\n";
        !            45: 
        !            46:     echo "File permissions are => ";
        !            47:     printf("%o", fileperms($file_name) );
        !            48:     echo "\n";
        !            49:     
        !            50:     echo "File created in => ";
        !            51:     $file_dir = dirname($file_name);
        !            52:         
        !            53:     if (realpath($file_dir) == realpath(sys_get_temp_dir())) {
        !            54:        echo "temp dir\n";
        !            55:     }
        !            56:     else {
        !            57:        echo "unknown location\n";
        !            58:     }    
        !            59:     
        !            60:   }
        !            61:   else { 
        !            62:     echo "-- File is not created --\n";
        !            63:   }
        !            64:  
        !            65:   unlink($file_name);
        !            66: }
        !            67: 
        !            68: echo "\n*** Done ***\n";
        !            69: ?>
        !            70: --EXPECTF--
        !            71: *** Testing tempnam() with invalid/non-existing directory names ***
        !            72: -- Iteration 0 --
        !            73: File name is => %s%etempnam_variation3.tmp%s
        !            74: File permissions are => 100600
        !            75: File created in => temp dir
        !            76: -- Iteration 1 --
        !            77: File name is => %s%etempnam_variation3.tmp%s
        !            78: File permissions are => 100600
        !            79: File created in => temp dir
        !            80: -- Iteration 2 --
        !            81: File name is => %s%etempnam_variation3.tmp%s
        !            82: File permissions are => 100600
        !            83: File created in => temp dir
        !            84: -- Iteration 3 --
        !            85: File name is => %s%etempnam_variation3.tmp%s
        !            86: File permissions are => 100600
        !            87: File created in => temp dir
        !            88: -- Iteration 4 --
        !            89: File name is => %s%etempnam_variation3.tmp%s
        !            90: File permissions are => 100600
        !            91: File created in => temp dir
        !            92: -- Iteration 5 --
        !            93: File name is => %s%etempnam_variation3.tmp%s
        !            94: File permissions are => 100600
        !            95: File created in => temp dir
        !            96: -- Iteration 6 --
        !            97: -- File is not created --
        !            98: 
        !            99: Warning: unlink(): %s in %s on line %d
        !           100: -- Iteration 7 --
        !           101: 
        !           102: Warning: tempnam() expects parameter 1 to be string, array given in %s on line %d
        !           103: -- File is not created --
        !           104: 
        !           105: Warning: unlink(): %s in %s on line %d
        !           106: -- Iteration 8 --
        !           107: File name is => %s%etempnam_variation3.tmp%s
        !           108: File permissions are => 100600
        !           109: File created in => temp dir
        !           110: -- Iteration 9 --
        !           111: File name is => %s%etempnam_variation3.tmp%s
        !           112: File permissions are => 100600
        !           113: File created in => temp dir
        !           114: 
        !           115: *** Done ***
        !           116: 

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