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

1.1       misho       1: --TEST--
                      2: Test fgetss() function : Basic functionality - read modes only
                      3: --FILE--
                      4: <?php
                      5: /*
                      6:  Prototype: string fgetss ( resource $handle [, int $length [, string $allowable_tags]] );
                      7:  Description: Gets line from file pointer and strip HTML tags
                      8: */
                      9: 
                     10: /* test fgetss with all read modes */
                     11: 
                     12: // include the common file related test functions 
                     13: include ("file.inc");
                     14: 
                     15: echo "*** Testing fgetss() : Basic operations ***\n";
                     16: 
                     17: /* string with html and php tags */
                     18: $string_with_tags = <<<EOT
                     19: <test>Testing fgetss() functions</test>
                     20: <?php echo "this string is within php tag"; ?> {;}<{> this
                     21: is a heredoc string. <pg>ksklnm@@$$&$&^%&^%&^%&</pg>
                     22: <html> html </html> <?php echo "php"; ?>
                     23: EOT;
                     24: 
                     25: if(substr(PHP_OS, 0, 3) == "WIN")  {
                     26:        $string_with_tags = str_replace("\r",'', $string_with_tags);
                     27: }
                     28: /* try reading the file opened in different modes of reading */
                     29: $file_modes = array("r","rb", "rt","r+", "r+b", "r+t");
                     30: 
                     31: for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     32:   echo "\n-- Testing fgetss() with file opened using $file_modes[$mode_counter] mode --\n";
                     33: 
                     34:   /* create an empty file and write the strings with tags */
                     35:   $filename = dirname(__FILE__)."/fgetss_basic1.tmp"; 
                     36:   create_file ($filename); //create an empty file
                     37:   file_put_contents($filename, $string_with_tags); 
                     38:   $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     39:   if(!$file_handle) {
                     40:     echo "Error: failed to open file $filename!\n";
                     41:     exit();
                     42:   }
                     43:   
                     44:   rewind($file_handle); 
                     45:   /* read entire file and strip tags */ 
                     46:   echo "-- fgetss() with default length, file pointer at 0 --\n";
                     47:   var_dump( fgetss($file_handle) ); // no length and allowable tags provided, reads entire file
                     48:   var_dump( ftell($file_handle) );
                     49:   var_dump( feof($file_handle) );
                     50:  
                     51:   rewind($file_handle);
                     52:   /* read entire file and strip tags tags */
                     53:   echo "-- fgets() with length = 30, file pointer at 0 --\n";
                     54:   var_dump( fgetss($file_handle ,30) ); // length parameter given,not reading entire file
                     55:   var_dump( ftell($file_handle) ); // checking file pointer position initially
                     56:   var_dump( feof($file_handle) ); // confirm file pointer is not at eof
                     57:  
                     58:   // close the file 
                     59:   fclose($file_handle);
                     60:  
                     61:   // delete the file 
                     62:   delete_file($filename);
                     63: } // end of for - mode_counter
                     64: 
                     65: echo "Done\n";
                     66: ?>
                     67: --EXPECT--
                     68: *** Testing fgetss() : Basic operations ***
                     69: 
                     70: -- Testing fgetss() with file opened using r mode --
                     71: -- fgetss() with default length, file pointer at 0 --
                     72: string(27) "Testing fgetss() functions
                     73: "
                     74: int(40)
                     75: bool(false)
                     76: -- fgets() with length = 30, file pointer at 0 --
                     77: string(23) "Testing fgetss() functi"
                     78: int(29)
                     79: bool(false)
                     80: 
                     81: -- Testing fgetss() with file opened using rb mode --
                     82: -- fgetss() with default length, file pointer at 0 --
                     83: string(27) "Testing fgetss() functions
                     84: "
                     85: int(40)
                     86: bool(false)
                     87: -- fgets() with length = 30, file pointer at 0 --
                     88: string(23) "Testing fgetss() functi"
                     89: int(29)
                     90: bool(false)
                     91: 
                     92: -- Testing fgetss() with file opened using rt mode --
                     93: -- fgetss() with default length, file pointer at 0 --
                     94: string(27) "Testing fgetss() functions
                     95: "
                     96: int(40)
                     97: bool(false)
                     98: -- fgets() with length = 30, file pointer at 0 --
                     99: string(23) "Testing fgetss() functi"
                    100: int(29)
                    101: bool(false)
                    102: 
                    103: -- Testing fgetss() with file opened using r+ mode --
                    104: -- fgetss() with default length, file pointer at 0 --
                    105: string(27) "Testing fgetss() functions
                    106: "
                    107: int(40)
                    108: bool(false)
                    109: -- fgets() with length = 30, file pointer at 0 --
                    110: string(23) "Testing fgetss() functi"
                    111: int(29)
                    112: bool(false)
                    113: 
                    114: -- Testing fgetss() with file opened using r+b mode --
                    115: -- fgetss() with default length, file pointer at 0 --
                    116: string(27) "Testing fgetss() functions
                    117: "
                    118: int(40)
                    119: bool(false)
                    120: -- fgets() with length = 30, file pointer at 0 --
                    121: string(23) "Testing fgetss() functi"
                    122: int(29)
                    123: bool(false)
                    124: 
                    125: -- Testing fgetss() with file opened using r+t mode --
                    126: -- fgetss() with default length, file pointer at 0 --
                    127: string(27) "Testing fgetss() functions
                    128: "
                    129: int(40)
                    130: bool(false)
                    131: -- fgets() with length = 30, file pointer at 0 --
                    132: string(23) "Testing fgetss() functi"
                    133: int(29)
                    134: bool(false)
                    135: Done

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