Annotation of embedaddon/php/ext/standard/tests/file/fgetss_variation5-win32.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test fgetss() function : usage variations - read/write modes, file pointer at EOF 
                      3: --SKIPIF--
                      4: <?php
                      5: if (substr(PHP_OS, 0, 3) != 'WIN') {
                      6:     die('skip.. only valid for Windows');
                      7: }
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11: /*
                     12:  Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
                     13:  Description: Gets line from file pointer and strip HTML tags
                     14: */
                     15: 
                     16: /* try fgetss on files which are opened in read/write modes
                     17:     w+, w+b, w+t,
                     18:     a+, a+b, a+t,
                     19:     x+, x+b, x+t
                     20: */
                     21: 
                     22: 
                     23: echo "*** Testing fgetss() : usage variations ***\n";
                     24: 
                     25: /* string with html and php tags */
                     26: $string_with_tags = <<<EOT
                     27: <test>Testing fgetss() functions</test>
                     28: <?php echo "this string is within php tag"; ?> {;}<{> this
                     29: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
                     30: <html> html </html> <?php echo "php"; ?>
                     31: this line is without any html and php tags
                     32: this is a line with more than eighty character,want to check line splitting correctly after 80 characters
                     33: this text contains some html tags <body> body </body> <br> br </br>
                     34: this is the line with \n character. 
                     35: EOT;
                     36: if(substr(PHP_OS, 0, 3) == "WIN")  {
                     37:        $string_with_tags = str_replace("\r",'', $string_with_tags);
                     38: }
                     39: 
                     40: $filename = dirname(__FILE__)."/fgetss_variation5.tmp"; 
                     41: 
                     42: /* try reading the file opened in different modes of reading */
                     43: $file_modes = array("w+","w+b", "w+t","a+", "a+b", "a+t","x+","x+b","x+t");
                     44: 
                     45: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     46:   echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
                     47: 
                     48:   /* create an empty file and write the strings with tags */
                     49:   $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     50:   fwrite($file_handle,$string_with_tags); //writing data to the file
                     51:   if(!$file_handle) {
                     52:     echo "Error: failed to open file $filename!\n";
                     53:     exit();
                     54:   }
1.1.1.2 ! misho      55:   // rewind the file pointer to beginning of the file
1.1       misho      56:   var_dump( filesize($filename) );
                     57:   var_dump( rewind($file_handle) );
                     58:   var_dump( ftell($file_handle) );
                     59:   var_dump( feof($file_handle) );
                     60: 
                     61:   echo "-- Reading when file pointer points to EOF --\n";
                     62:   var_dump( fseek($file_handle,0,SEEK_END) ); // now file pointer at end
                     63:   var_dump( ftell($file_handle) ); //ensure file pointer at end
                     64:   var_dump( fgetss($file_handle) ); // try to read
                     65:   var_dump( ftell($file_handle) ); // find out file position
                     66:   var_dump( feof($file_handle) );  // ensure that file pointer is at eof
                     67: 
                     68:   // now file is at the end try reading with length and allowable tags,expecting false
                     69:   var_dump( fgetss($file_handle, 80, "<test>, <html>, <?>") );
                     70:   var_dump( ftell($file_handle) );  // find out file position
                     71:   var_dump( feof($file_handle) );   // ensure that file pointer is at eof
                     72: 
                     73:  
                     74:   // close the file 
                     75:   fclose($file_handle);
                     76:    
                     77:   // delete the file 
                     78:   unlink($filename);
                     79: } // end of for - mode_counter
                     80: 
                     81: echo "Done\n";
                     82: ?>
                     83: --EXPECT--
                     84: *** Testing fgetss() : usage variations ***
                     85: 
                     86: -- Testing fgetss() with file opened using w+ mode --
                     87: int(445)
                     88: bool(true)
                     89: int(0)
                     90: bool(false)
                     91: -- Reading when file pointer points to EOF --
                     92: int(0)
                     93: int(445)
                     94: bool(false)
                     95: int(445)
                     96: bool(true)
                     97: bool(false)
                     98: int(445)
                     99: bool(true)
                    100: 
                    101: -- Testing fgetss() with file opened using w+b mode --
                    102: int(445)
                    103: bool(true)
                    104: int(0)
                    105: bool(false)
                    106: -- Reading when file pointer points to EOF --
                    107: int(0)
                    108: int(445)
                    109: bool(false)
                    110: int(445)
                    111: bool(true)
                    112: bool(false)
                    113: int(445)
                    114: bool(true)
                    115: 
                    116: -- Testing fgetss() with file opened using w+t mode --
                    117: int(453)
                    118: bool(true)
                    119: int(0)
                    120: bool(false)
                    121: -- Reading when file pointer points to EOF --
                    122: int(0)
                    123: int(453)
                    124: bool(false)
                    125: int(453)
                    126: bool(true)
                    127: bool(false)
                    128: int(453)
                    129: bool(true)
                    130: 
                    131: -- Testing fgetss() with file opened using a+ mode --
                    132: int(445)
                    133: bool(true)
                    134: int(0)
                    135: bool(false)
                    136: -- Reading when file pointer points to EOF --
                    137: int(0)
                    138: int(445)
                    139: bool(false)
                    140: int(445)
                    141: bool(true)
                    142: bool(false)
                    143: int(445)
                    144: bool(true)
                    145: 
                    146: -- Testing fgetss() with file opened using a+b mode --
                    147: int(445)
                    148: bool(true)
                    149: int(0)
                    150: bool(false)
                    151: -- Reading when file pointer points to EOF --
                    152: int(0)
                    153: int(445)
                    154: bool(false)
                    155: int(445)
                    156: bool(true)
                    157: bool(false)
                    158: int(445)
                    159: bool(true)
                    160: 
                    161: -- Testing fgetss() with file opened using a+t mode --
                    162: int(453)
                    163: bool(true)
                    164: int(0)
                    165: bool(false)
                    166: -- Reading when file pointer points to EOF --
                    167: int(0)
                    168: int(453)
                    169: bool(false)
                    170: int(453)
                    171: bool(true)
                    172: bool(false)
                    173: int(453)
                    174: bool(true)
                    175: 
                    176: -- Testing fgetss() with file opened using x+ mode --
                    177: int(445)
                    178: bool(true)
                    179: int(0)
                    180: bool(false)
                    181: -- Reading when file pointer points to EOF --
                    182: int(0)
                    183: int(445)
                    184: bool(false)
                    185: int(445)
                    186: bool(true)
                    187: bool(false)
                    188: int(445)
                    189: bool(true)
                    190: 
                    191: -- Testing fgetss() with file opened using x+b mode --
                    192: int(445)
                    193: bool(true)
                    194: int(0)
                    195: bool(false)
                    196: -- Reading when file pointer points to EOF --
                    197: int(0)
                    198: int(445)
                    199: bool(false)
                    200: int(445)
                    201: bool(true)
                    202: bool(false)
                    203: int(445)
                    204: bool(true)
                    205: 
                    206: -- Testing fgetss() with file opened using x+t mode --
                    207: int(453)
                    208: bool(true)
                    209: int(0)
                    210: bool(false)
                    211: -- Reading when file pointer points to EOF --
                    212: int(0)
                    213: int(453)
                    214: bool(false)
                    215: int(453)
                    216: bool(true)
                    217: bool(false)
                    218: int(453)
                    219: bool(true)
                    220: Done

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