Annotation of embedaddon/php/ext/standard/tests/file/fgetcsv_variation21.phpt, revision 1.1.1.2

1.1       misho       1: --TEST--
                      2: Test fgetcsv() : usage variations - with default enclosure, blank line
                      3: --FILE--
                      4: <?php
                      5: /* 
                      6:  Prototype: array fgetcsv ( resource $handle [, int $length [, string $delimiter [, string $enclosure]]] );
                      7:  Description: Gets line from file pointer and parse for CSV fields
                      8: */
                      9: 
                     10: /*
                     11:   Testing fgetcsv() to read a file containing blank line when provided with 
                     12:   default enclosure argument
                     13: */
                     14: 
                     15: echo "*** Testing fgetcsv() : with default enclosure, blank line ***\n";
                     16: 
                     17: $filename = dirname(__FILE__) . '/fgetcsv_variation21.tmp';
                     18: @unlink($filename);
                     19: 
                     20: $file_modes = array ("r","rb", "rt", "r+", "r+b", "r+t",
                     21:                      "a+", "a+b", "a+t",
                     22:                      "w+", "w+b", "w+t",
                     23:                      "x+", "x+b", "x+t"); 
                     24: 
                     25: $loop_counter = 1;
                     26:   for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     27:     // create the file and add the content with has csv fields
                     28:     if ( strstr($file_modes[$mode_counter], "r") ) {
                     29:       $file_handle = fopen($filename, "w");
                     30:     } else {
                     31:       $file_handle = fopen($filename, $file_modes[$mode_counter] );
                     32:     }
                     33:     if ( !$file_handle ) {
                     34:       echo "Error: failed to create file $filename!\n";
                     35:       exit();
                     36:     }
                     37:     // write a blank line
                     38:     fwrite($file_handle, "\n"); // blank line
                     39: 
                     40:     // close the file if the mode to be used is read mode  and re-open using read mode
1.1.1.2 ! misho      41:     // else rewind the file pointer to beginning of the file 
1.1       misho      42:     if ( strstr($file_modes[$mode_counter], "r" ) ) {
                     43:       fclose($file_handle);
                     44:       $file_handle = fopen($filename, $file_modes[$mode_counter]);
                     45:     } else {
                     46:       // rewind the file pointer to bof
                     47:       rewind($file_handle);
                     48:     }
                     49:       
                     50:     echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; 
                     51: 
                     52:     // call fgetcsv() to parse csv fields
                     53:      
                     54:     // read the line which is a blank line to see the working of fgetcsv
                     55:     $fp_pos = ftell($file_handle);
                     56:     var_dump( fgetcsv($file_handle, 1024, '+') );
                     57:     // check the file pointer position and if eof
                     58:     var_dump( ftell($file_handle) );
                     59:     var_dump( feof($file_handle) );
                     60: 
                     61:     // close the file
                     62:     fclose($file_handle);
                     63:     //delete file
                     64:     unlink($filename);
                     65:   } //end of mode loop 
                     66: 
                     67: echo "Done\n";
                     68: ?>
                     69: --EXPECT--
                     70: *** Testing fgetcsv() : with default enclosure, blank line ***
                     71: 
                     72: -- Testing fgetcsv() with file opened using r mode --
                     73: array(1) {
                     74:   [0]=>
                     75:   NULL
                     76: }
                     77: int(1)
                     78: bool(false)
                     79: 
                     80: -- Testing fgetcsv() with file opened using rb mode --
                     81: array(1) {
                     82:   [0]=>
                     83:   NULL
                     84: }
                     85: int(1)
                     86: bool(false)
                     87: 
                     88: -- Testing fgetcsv() with file opened using rt mode --
                     89: array(1) {
                     90:   [0]=>
                     91:   NULL
                     92: }
                     93: int(1)
                     94: bool(false)
                     95: 
                     96: -- Testing fgetcsv() with file opened using r+ mode --
                     97: array(1) {
                     98:   [0]=>
                     99:   NULL
                    100: }
                    101: int(1)
                    102: bool(false)
                    103: 
                    104: -- Testing fgetcsv() with file opened using r+b mode --
                    105: array(1) {
                    106:   [0]=>
                    107:   NULL
                    108: }
                    109: int(1)
                    110: bool(false)
                    111: 
                    112: -- Testing fgetcsv() with file opened using r+t mode --
                    113: array(1) {
                    114:   [0]=>
                    115:   NULL
                    116: }
                    117: int(1)
                    118: bool(false)
                    119: 
                    120: -- Testing fgetcsv() with file opened using a+ mode --
                    121: array(1) {
                    122:   [0]=>
                    123:   NULL
                    124: }
                    125: int(1)
                    126: bool(false)
                    127: 
                    128: -- Testing fgetcsv() with file opened using a+b mode --
                    129: array(1) {
                    130:   [0]=>
                    131:   NULL
                    132: }
                    133: int(1)
                    134: bool(false)
                    135: 
                    136: -- Testing fgetcsv() with file opened using a+t mode --
                    137: array(1) {
                    138:   [0]=>
                    139:   NULL
                    140: }
                    141: int(1)
                    142: bool(false)
                    143: 
                    144: -- Testing fgetcsv() with file opened using w+ mode --
                    145: array(1) {
                    146:   [0]=>
                    147:   NULL
                    148: }
                    149: int(1)
                    150: bool(false)
                    151: 
                    152: -- Testing fgetcsv() with file opened using w+b mode --
                    153: array(1) {
                    154:   [0]=>
                    155:   NULL
                    156: }
                    157: int(1)
                    158: bool(false)
                    159: 
                    160: -- Testing fgetcsv() with file opened using w+t mode --
                    161: array(1) {
                    162:   [0]=>
                    163:   NULL
                    164: }
                    165: int(1)
                    166: bool(false)
                    167: 
                    168: -- Testing fgetcsv() with file opened using x+ mode --
                    169: array(1) {
                    170:   [0]=>
                    171:   NULL
                    172: }
                    173: int(1)
                    174: bool(false)
                    175: 
                    176: -- Testing fgetcsv() with file opened using x+b mode --
                    177: array(1) {
                    178:   [0]=>
                    179:   NULL
                    180: }
                    181: int(1)
                    182: bool(false)
                    183: 
                    184: -- Testing fgetcsv() with file opened using x+t mode --
                    185: array(1) {
                    186:   [0]=>
                    187:   NULL
                    188: }
                    189: int(1)
                    190: bool(false)
                    191: Done

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