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

1.1       misho       1: --TEST--
                      2: Test fputcsv() : usage variations - with line without any csv fields 
                      3: --FILE--
                      4: <?php
                      5: /* 
                      6:  Prototype: array fputcsv ( resource $handle , array $fields [, string $delimiter [, string $enclosure]]] );
                      7:  Description: Format line as CSV and write to the file pointer 
                      8: */
                      9: 
                     10: 
                     11: /* Testing fputcsv() to write to a file when the field has no CSV format */
                     12: 
                     13: echo "*** Testing fputcsv() : with no CSV format in the field ***\n";
                     14: 
                     15: /* the array is with three elements in it. Each element should be read as 
                     16:    1st element is delimiter, 2nd element is enclosure 
                     17:    and 3rd element is csv fields
                     18: */
                     19: 
                     20: $fields = array( array('water_fruit\n'),
                     21:                 array("water_fruit\n"),
                     22:                 array("")
                     23:          );
                     24: 
                     25: $file_path = dirname(__FILE__);
                     26: $filename = "$file_path/fputcsv_variation10.tmp";
                     27: 
                     28: $file_modes = array ("r+", "r+b", "r+t",
                     29:                      "a+", "a+b", "a+t",
                     30:                      "w+", "w+b", "w+t",
                     31:                      "x+", "x+b", "x+t"); 
                     32: 
                     33: $loop_counter = 1;
                     34: foreach ($fields as $field) {
                     35:   for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     36:     
                     37:     echo "\n-- file opened in $file_modes[$mode_counter] --\n";  
                     38:     // create the file and add the content with has csv fields
                     39:     if ( strstr($file_modes[$mode_counter], "r") ) {
                     40:       $file_handle = fopen($filename, "w");
                     41:     } else {
                     42:       $file_handle = fopen($filename, $file_modes[$mode_counter] );
                     43:     }
                     44:     if ( !$file_handle ) {
                     45:       echo "Error: failed to create file $filename!\n";
                     46:       exit();
                     47:     }
                     48:     $csv_field = $field;
                     49:     
                     50:     // write to a file in csv format
                     51:     var_dump( fputcsv($file_handle, $csv_field) );
                     52:     
                     53:     // check the file pointer position and eof
                     54:     var_dump( ftell($file_handle) );
                     55:     var_dump( feof($file_handle) );
                     56:     //close the file
                     57:     fclose($file_handle);
                     58:     
                     59:     // print the file contents 
                     60:     var_dump( file_get_contents($filename) );
                     61: 
                     62:     //delete file
                     63:     unlink($filename);
                     64:   } //end of mode loop 
                     65: } // end of foreach
                     66: 
                     67: echo "Done\n";
                     68: ?>
                     69: --EXPECTF--
                     70: *** Testing fputcsv() : with no CSV format in the field ***
                     71: 
                     72: -- file opened in r+ --
                     73: int(16)
                     74: int(16)
                     75: bool(false)
                     76: string(16) ""water_fruit\n"
                     77: "
                     78: 
                     79: -- file opened in r+b --
                     80: int(16)
                     81: int(16)
                     82: bool(false)
                     83: string(16) ""water_fruit\n"
                     84: "
                     85: 
                     86: -- file opened in r+t --
                     87: int(16)
                     88: int(16)
                     89: bool(false)
                     90: string(%d) ""water_fruit\n"
                     91: "
                     92: 
                     93: -- file opened in a+ --
                     94: int(16)
                     95: int(16)
                     96: bool(false)
                     97: string(16) ""water_fruit\n"
                     98: "
                     99: 
                    100: -- file opened in a+b --
                    101: int(16)
                    102: int(16)
                    103: bool(false)
                    104: string(16) ""water_fruit\n"
                    105: "
                    106: 
                    107: -- file opened in a+t --
                    108: int(16)
                    109: int(16)
                    110: bool(false)
                    111: string(%d) ""water_fruit\n"
                    112: "
                    113: 
                    114: -- file opened in w+ --
                    115: int(16)
                    116: int(16)
                    117: bool(false)
                    118: string(16) ""water_fruit\n"
                    119: "
                    120: 
                    121: -- file opened in w+b --
                    122: int(16)
                    123: int(16)
                    124: bool(false)
                    125: string(16) ""water_fruit\n"
                    126: "
                    127: 
                    128: -- file opened in w+t --
                    129: int(16)
                    130: int(16)
                    131: bool(false)
                    132: string(%d) ""water_fruit\n"
                    133: "
                    134: 
                    135: -- file opened in x+ --
                    136: int(16)
                    137: int(16)
                    138: bool(false)
                    139: string(16) ""water_fruit\n"
                    140: "
                    141: 
                    142: -- file opened in x+b --
                    143: int(16)
                    144: int(16)
                    145: bool(false)
                    146: string(16) ""water_fruit\n"
                    147: "
                    148: 
                    149: -- file opened in x+t --
                    150: int(16)
                    151: int(16)
                    152: bool(false)
                    153: string(%d) ""water_fruit\n"
                    154: "
                    155: 
                    156: -- file opened in r+ --
                    157: int(15)
                    158: int(15)
                    159: bool(false)
                    160: string(15) ""water_fruit
                    161: "
                    162: "
                    163: 
                    164: -- file opened in r+b --
                    165: int(15)
                    166: int(15)
                    167: bool(false)
                    168: string(15) ""water_fruit
                    169: "
                    170: "
                    171: 
                    172: -- file opened in r+t --
                    173: int(15)
                    174: int(15)
                    175: bool(false)
                    176: string(%d) ""water_fruit
                    177: "
                    178: "
                    179: 
                    180: -- file opened in a+ --
                    181: int(15)
                    182: int(15)
                    183: bool(false)
                    184: string(15) ""water_fruit
                    185: "
                    186: "
                    187: 
                    188: -- file opened in a+b --
                    189: int(15)
                    190: int(15)
                    191: bool(false)
                    192: string(15) ""water_fruit
                    193: "
                    194: "
                    195: 
                    196: -- file opened in a+t --
                    197: int(15)
                    198: int(15)
                    199: bool(false)
                    200: string(%d) ""water_fruit
                    201: "
                    202: "
                    203: 
                    204: -- file opened in w+ --
                    205: int(15)
                    206: int(15)
                    207: bool(false)
                    208: string(15) ""water_fruit
                    209: "
                    210: "
                    211: 
                    212: -- file opened in w+b --
                    213: int(15)
                    214: int(15)
                    215: bool(false)
                    216: string(15) ""water_fruit
                    217: "
                    218: "
                    219: 
                    220: -- file opened in w+t --
                    221: int(15)
                    222: int(15)
                    223: bool(false)
                    224: string(%d) ""water_fruit
                    225: "
                    226: "
                    227: 
                    228: -- file opened in x+ --
                    229: int(15)
                    230: int(15)
                    231: bool(false)
                    232: string(15) ""water_fruit
                    233: "
                    234: "
                    235: 
                    236: -- file opened in x+b --
                    237: int(15)
                    238: int(15)
                    239: bool(false)
                    240: string(15) ""water_fruit
                    241: "
                    242: "
                    243: 
                    244: -- file opened in x+t --
                    245: int(15)
                    246: int(15)
                    247: bool(false)
                    248: string(%d) ""water_fruit
                    249: "
                    250: "
                    251: 
                    252: -- file opened in r+ --
                    253: int(1)
                    254: int(1)
                    255: bool(false)
                    256: string(1) "
                    257: "
                    258: 
                    259: -- file opened in r+b --
                    260: int(1)
                    261: int(1)
                    262: bool(false)
                    263: string(1) "
                    264: "
                    265: 
                    266: -- file opened in r+t --
                    267: int(1)
                    268: int(1)
                    269: bool(false)
                    270: string(%d) "
                    271: "
                    272: 
                    273: -- file opened in a+ --
                    274: int(1)
                    275: int(1)
                    276: bool(false)
                    277: string(1) "
                    278: "
                    279: 
                    280: -- file opened in a+b --
                    281: int(1)
                    282: int(1)
                    283: bool(false)
                    284: string(1) "
                    285: "
                    286: 
                    287: -- file opened in a+t --
                    288: int(1)
                    289: int(1)
                    290: bool(false)
                    291: string(%d) "
                    292: "
                    293: 
                    294: -- file opened in w+ --
                    295: int(1)
                    296: int(1)
                    297: bool(false)
                    298: string(1) "
                    299: "
                    300: 
                    301: -- file opened in w+b --
                    302: int(1)
                    303: int(1)
                    304: bool(false)
                    305: string(1) "
                    306: "
                    307: 
                    308: -- file opened in w+t --
                    309: int(1)
                    310: int(1)
                    311: bool(false)
                    312: string(%d) "
                    313: "
                    314: 
                    315: -- file opened in x+ --
                    316: int(1)
                    317: int(1)
                    318: bool(false)
                    319: string(1) "
                    320: "
                    321: 
                    322: -- file opened in x+b --
                    323: int(1)
                    324: int(1)
                    325: bool(false)
                    326: string(1) "
                    327: "
                    328: 
                    329: -- file opened in x+t --
                    330: int(1)
                    331: int(1)
                    332: bool(false)
                    333: string(%d) "
                    334: "
                    335: Done
                    336: 

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