Annotation of embedaddon/php/ext/standard/tests/file/fgetss_variation1.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test fgetss() function : usage variations - write only modes
                      3: --SKIPIF--
                      4: <?php
                      5: if (substr(PHP_OS, 0, 3) == 'WIN') {
                      6:     die('skip.. Not 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 fgets on files which are opened in non readable modes
                     17:     w, wb, wt,
                     18:     a, ab, at,
                     19:     x, xb, xt
                     20: */
                     21: 
                     22: // include the common file related test functions 
                     23: include ("file.inc");
                     24: 
                     25: echo "*** Testing fgetss() : usage variations ***\n";
                     26: 
                     27: /* string with html and php tags */
                     28: $string_with_tags = <<<EOT
                     29: <test>Testing fgetss() functions</test>
                     30: <?php echo "this string is within php tag"; ?> {;}<{> this
                     31: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
                     32: <html> html </html> <?php echo "php"; ?>
                     33: this line is without any html and php tags
                     34: this is a line with more than eighty character,want to check line splitting correctly after 80 characters
                     35: this text contains some html tags <body> body </body> <br> br </br>
                     36: this is the line with \n character. 
                     37: EOT;
                     38: 
                     39: $filename = dirname(__FILE__)."/fgetss_variation1.tmp";
                     40: 
                     41: /* try reading the file opened in different modes of reading */
                     42: $file_modes = array("w","wb", "wt","a", "ab", "at","x","xb","xt");
                     43: 
                     44: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     45:   echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
                     46: 
                     47:   /* create an empty file and write the strings with tags */
                     48:   $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     49:   fwrite($file_handle,$string_with_tags);
                     50:   if(!$file_handle) {
                     51:     echo "Error: failed to open file $filename!\n";
                     52:     exit();
                     53:   }
                     54:   
                     55:   // rewind the file pointer to begining of the file
                     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:   /* read entire file and strip tags */ 
                     62:   echo "-- fgetss() with default length, file pointer at 0 , expected : no character should be read --\n";
                     63:   var_dump( fgetss($file_handle) ); // expected : no character should be read
                     64:   var_dump( ftell($file_handle) ); //ensure that file pointer position is not changed
                     65:   var_dump( feof($file_handle) ); // check if end of file pointer is set
                     66:   
                     67:   // close the file 
                     68:   fclose($file_handle);
                     69:    
                     70:   // delete the file 
                     71:   delete_file($filename);
                     72: } // end of for - mode_counter
                     73: 
                     74: echo "Done\n";
                     75: ?>
                     76: --EXPECTF--
                     77: *** Testing fgetss() : usage variations ***
                     78: 
                     79: -- Testing fgetss() with file opened using w mode --
                     80: int(445)
                     81: bool(true)
                     82: int(0)
                     83: bool(false)
                     84: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                     85: bool(false)
                     86: int(0)
                     87: bool(false)
                     88: 
                     89: -- Testing fgetss() with file opened using wb mode --
                     90: int(445)
                     91: bool(true)
                     92: int(0)
                     93: bool(false)
                     94: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                     95: bool(false)
                     96: int(0)
                     97: bool(false)
                     98: 
                     99: -- Testing fgetss() with file opened using wt mode --
                    100: int(445)
                    101: bool(true)
                    102: int(0)
                    103: bool(false)
                    104: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    105: bool(false)
                    106: int(0)
                    107: bool(false)
                    108: 
                    109: -- Testing fgetss() with file opened using a mode --
                    110: int(445)
                    111: bool(true)
                    112: int(0)
                    113: bool(false)
                    114: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    115: bool(false)
                    116: int(0)
                    117: bool(false)
                    118: 
                    119: -- Testing fgetss() with file opened using ab mode --
                    120: int(445)
                    121: bool(true)
                    122: int(0)
                    123: bool(false)
                    124: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    125: bool(false)
                    126: int(0)
                    127: bool(false)
                    128: 
                    129: -- Testing fgetss() with file opened using at mode --
                    130: int(445)
                    131: bool(true)
                    132: int(0)
                    133: bool(false)
                    134: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    135: bool(false)
                    136: int(0)
                    137: bool(false)
                    138: 
                    139: -- Testing fgetss() with file opened using x mode --
                    140: int(445)
                    141: bool(true)
                    142: int(0)
                    143: bool(false)
                    144: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    145: bool(false)
                    146: int(0)
                    147: bool(false)
                    148: 
                    149: -- Testing fgetss() with file opened using xb mode --
                    150: int(445)
                    151: bool(true)
                    152: int(0)
                    153: bool(false)
                    154: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    155: bool(false)
                    156: int(0)
                    157: bool(false)
                    158: 
                    159: -- Testing fgetss() with file opened using xt mode --
                    160: int(445)
                    161: bool(true)
                    162: int(0)
                    163: bool(false)
                    164: -- fgetss() with default length, file pointer at 0 , expected : no character should be read --
                    165: bool(false)
                    166: int(0)
                    167: bool(false)
                    168: Done

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