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

1.1       misho       1: --TEST--
                      2: Test fgetcsv() : usage variations - reading files opened in write only mode (Bug #42036)
                      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: /* Testing fgetcsv() to read from files opened in write only mode */
                     11: 
                     12: echo "*** Testing fgetcsv() : reading the files opened in write only mode ***\n";
                     13: 
                     14: /* the array is with three elements in it. Each element should be read as 
                     15:    1st element is delimiter, 2nd element is enclosure 
                     16:    and 3rd element is csv fields
                     17: */
                     18: $csv_lists = array (
                     19:   array(',', '"', '"water",fruit'),
                     20:   array(',', '"', '"water","fruit"'),
                     21:   array(' ', '^', '^water^ ^fruit^'),
                     22:   array(':', '&', '&water&:&fruit&'),
                     23:   array('=', '=', '=water===fruit='),
                     24:   array('-', '-', '-water--fruit-air'),
                     25:   array('-', '-', '-water---fruit---air-'),
                     26:   array(':', '&', '&""""&:&"&:,:":&,&:,,,,')
                     27: );
                     28: 
                     29: $filename = dirname(__FILE__) . '/fgetcsv_variation26.tmp';
                     30: @unlink($filename);
                     31: 
                     32: $file_modes = array ("w", "wb", "wt",
                     33:                      "a", "ab", "at",
                     34:                      "x", "xb", "xt");
                     35: 
                     36: $loop_counter = 1;
                     37: foreach ($csv_lists as $csv_list) {
                     38:   for($mode_counter = 0; $mode_counter < count($file_modes); $mode_counter++) {
                     39:     // create the file and add the content with has csv fields
                     40:     $file_handle = fopen($filename, $file_modes[$mode_counter] );
                     41:     
                     42:     if ( !$file_handle ) {
                     43:       echo "Error: failed to create file $filename!\n";
                     44:       exit();
                     45:     }
                     46:     $delimiter = $csv_list[0];
                     47:     $enclosure = $csv_list[1];
                     48:     $csv_field = $csv_list[2];
                     49:     
                     50:     fwrite($file_handle, $csv_field . "\n");
                     51:     // write another line of text and a blank line
                     52:     // this will be used to test, if the fgetcsv() read more than a line and its
                     53:     // working when only a blank line is read
                     54:     fwrite($file_handle, "This is line of text without csv fields\n");
                     55:     fwrite($file_handle, "\n"); // blank line
                     56: 
                     57:     // rewind the file pointer to bof
                     58:       rewind($file_handle);
                     59:       
                     60:     echo "\n-- Testing fgetcsv() with file opened using $file_modes[$mode_counter] mode --\n"; 
                     61: 
                     62:     // call fgetcsv() to parse csv fields
                     63:       
                     64:     // use the right delimiter and enclosure with max length 
                     65:     var_dump( fgetcsv($file_handle, 1024, $delimiter, $enclosure) );
                     66:     // check the file pointer position and if eof
                     67:     var_dump( ftell($file_handle) );
                     68:     var_dump( feof($file_handle) );
                     69:       
                     70:     // close the file
                     71:     fclose($file_handle);
                     72:     //delete file
                     73:     unlink($filename);
                     74:   } //end of mode loop 
                     75: } // end of foreach
                     76: 
                     77: echo "Done\n";
                     78: ?>
                     79: --EXPECT--
                     80: *** Testing fgetcsv() : reading the files opened in write only mode ***
                     81: 
                     82: -- Testing fgetcsv() with file opened using w mode --
                     83: bool(false)
                     84: int(0)
                     85: bool(false)
                     86: 
                     87: -- Testing fgetcsv() with file opened using wb mode --
                     88: bool(false)
                     89: int(0)
                     90: bool(false)
                     91: 
                     92: -- Testing fgetcsv() with file opened using wt mode --
                     93: bool(false)
                     94: int(0)
                     95: bool(false)
                     96: 
                     97: -- Testing fgetcsv() with file opened using a mode --
                     98: bool(false)
                     99: int(0)
                    100: bool(false)
                    101: 
                    102: -- Testing fgetcsv() with file opened using ab mode --
                    103: bool(false)
                    104: int(0)
                    105: bool(false)
                    106: 
                    107: -- Testing fgetcsv() with file opened using at mode --
                    108: bool(false)
                    109: int(0)
                    110: bool(false)
                    111: 
                    112: -- Testing fgetcsv() with file opened using x mode --
                    113: bool(false)
                    114: int(0)
                    115: bool(false)
                    116: 
                    117: -- Testing fgetcsv() with file opened using xb mode --
                    118: bool(false)
                    119: int(0)
                    120: bool(false)
                    121: 
                    122: -- Testing fgetcsv() with file opened using xt mode --
                    123: bool(false)
                    124: int(0)
                    125: bool(false)
                    126: 
                    127: -- Testing fgetcsv() with file opened using w mode --
                    128: bool(false)
                    129: int(0)
                    130: bool(false)
                    131: 
                    132: -- Testing fgetcsv() with file opened using wb mode --
                    133: bool(false)
                    134: int(0)
                    135: bool(false)
                    136: 
                    137: -- Testing fgetcsv() with file opened using wt mode --
                    138: bool(false)
                    139: int(0)
                    140: bool(false)
                    141: 
                    142: -- Testing fgetcsv() with file opened using a mode --
                    143: bool(false)
                    144: int(0)
                    145: bool(false)
                    146: 
                    147: -- Testing fgetcsv() with file opened using ab mode --
                    148: bool(false)
                    149: int(0)
                    150: bool(false)
                    151: 
                    152: -- Testing fgetcsv() with file opened using at mode --
                    153: bool(false)
                    154: int(0)
                    155: bool(false)
                    156: 
                    157: -- Testing fgetcsv() with file opened using x mode --
                    158: bool(false)
                    159: int(0)
                    160: bool(false)
                    161: 
                    162: -- Testing fgetcsv() with file opened using xb mode --
                    163: bool(false)
                    164: int(0)
                    165: bool(false)
                    166: 
                    167: -- Testing fgetcsv() with file opened using xt mode --
                    168: bool(false)
                    169: int(0)
                    170: bool(false)
                    171: 
                    172: -- Testing fgetcsv() with file opened using w mode --
                    173: bool(false)
                    174: int(0)
                    175: bool(false)
                    176: 
                    177: -- Testing fgetcsv() with file opened using wb mode --
                    178: bool(false)
                    179: int(0)
                    180: bool(false)
                    181: 
                    182: -- Testing fgetcsv() with file opened using wt mode --
                    183: bool(false)
                    184: int(0)
                    185: bool(false)
                    186: 
                    187: -- Testing fgetcsv() with file opened using a mode --
                    188: bool(false)
                    189: int(0)
                    190: bool(false)
                    191: 
                    192: -- Testing fgetcsv() with file opened using ab mode --
                    193: bool(false)
                    194: int(0)
                    195: bool(false)
                    196: 
                    197: -- Testing fgetcsv() with file opened using at mode --
                    198: bool(false)
                    199: int(0)
                    200: bool(false)
                    201: 
                    202: -- Testing fgetcsv() with file opened using x mode --
                    203: bool(false)
                    204: int(0)
                    205: bool(false)
                    206: 
                    207: -- Testing fgetcsv() with file opened using xb mode --
                    208: bool(false)
                    209: int(0)
                    210: bool(false)
                    211: 
                    212: -- Testing fgetcsv() with file opened using xt mode --
                    213: bool(false)
                    214: int(0)
                    215: bool(false)
                    216: 
                    217: -- Testing fgetcsv() with file opened using w mode --
                    218: bool(false)
                    219: int(0)
                    220: bool(false)
                    221: 
                    222: -- Testing fgetcsv() with file opened using wb mode --
                    223: bool(false)
                    224: int(0)
                    225: bool(false)
                    226: 
                    227: -- Testing fgetcsv() with file opened using wt mode --
                    228: bool(false)
                    229: int(0)
                    230: bool(false)
                    231: 
                    232: -- Testing fgetcsv() with file opened using a mode --
                    233: bool(false)
                    234: int(0)
                    235: bool(false)
                    236: 
                    237: -- Testing fgetcsv() with file opened using ab mode --
                    238: bool(false)
                    239: int(0)
                    240: bool(false)
                    241: 
                    242: -- Testing fgetcsv() with file opened using at mode --
                    243: bool(false)
                    244: int(0)
                    245: bool(false)
                    246: 
                    247: -- Testing fgetcsv() with file opened using x mode --
                    248: bool(false)
                    249: int(0)
                    250: bool(false)
                    251: 
                    252: -- Testing fgetcsv() with file opened using xb mode --
                    253: bool(false)
                    254: int(0)
                    255: bool(false)
                    256: 
                    257: -- Testing fgetcsv() with file opened using xt mode --
                    258: bool(false)
                    259: int(0)
                    260: bool(false)
                    261: 
                    262: -- Testing fgetcsv() with file opened using w mode --
                    263: bool(false)
                    264: int(0)
                    265: bool(false)
                    266: 
                    267: -- Testing fgetcsv() with file opened using wb mode --
                    268: bool(false)
                    269: int(0)
                    270: bool(false)
                    271: 
                    272: -- Testing fgetcsv() with file opened using wt mode --
                    273: bool(false)
                    274: int(0)
                    275: bool(false)
                    276: 
                    277: -- Testing fgetcsv() with file opened using a mode --
                    278: bool(false)
                    279: int(0)
                    280: bool(false)
                    281: 
                    282: -- Testing fgetcsv() with file opened using ab mode --
                    283: bool(false)
                    284: int(0)
                    285: bool(false)
                    286: 
                    287: -- Testing fgetcsv() with file opened using at mode --
                    288: bool(false)
                    289: int(0)
                    290: bool(false)
                    291: 
                    292: -- Testing fgetcsv() with file opened using x mode --
                    293: bool(false)
                    294: int(0)
                    295: bool(false)
                    296: 
                    297: -- Testing fgetcsv() with file opened using xb mode --
                    298: bool(false)
                    299: int(0)
                    300: bool(false)
                    301: 
                    302: -- Testing fgetcsv() with file opened using xt mode --
                    303: bool(false)
                    304: int(0)
                    305: bool(false)
                    306: 
                    307: -- Testing fgetcsv() with file opened using w mode --
                    308: bool(false)
                    309: int(0)
                    310: bool(false)
                    311: 
                    312: -- Testing fgetcsv() with file opened using wb mode --
                    313: bool(false)
                    314: int(0)
                    315: bool(false)
                    316: 
                    317: -- Testing fgetcsv() with file opened using wt mode --
                    318: bool(false)
                    319: int(0)
                    320: bool(false)
                    321: 
                    322: -- Testing fgetcsv() with file opened using a mode --
                    323: bool(false)
                    324: int(0)
                    325: bool(false)
                    326: 
                    327: -- Testing fgetcsv() with file opened using ab mode --
                    328: bool(false)
                    329: int(0)
                    330: bool(false)
                    331: 
                    332: -- Testing fgetcsv() with file opened using at mode --
                    333: bool(false)
                    334: int(0)
                    335: bool(false)
                    336: 
                    337: -- Testing fgetcsv() with file opened using x mode --
                    338: bool(false)
                    339: int(0)
                    340: bool(false)
                    341: 
                    342: -- Testing fgetcsv() with file opened using xb mode --
                    343: bool(false)
                    344: int(0)
                    345: bool(false)
                    346: 
                    347: -- Testing fgetcsv() with file opened using xt mode --
                    348: bool(false)
                    349: int(0)
                    350: bool(false)
                    351: 
                    352: -- Testing fgetcsv() with file opened using w mode --
                    353: bool(false)
                    354: int(0)
                    355: bool(false)
                    356: 
                    357: -- Testing fgetcsv() with file opened using wb mode --
                    358: bool(false)
                    359: int(0)
                    360: bool(false)
                    361: 
                    362: -- Testing fgetcsv() with file opened using wt mode --
                    363: bool(false)
                    364: int(0)
                    365: bool(false)
                    366: 
                    367: -- Testing fgetcsv() with file opened using a mode --
                    368: bool(false)
                    369: int(0)
                    370: bool(false)
                    371: 
                    372: -- Testing fgetcsv() with file opened using ab mode --
                    373: bool(false)
                    374: int(0)
                    375: bool(false)
                    376: 
                    377: -- Testing fgetcsv() with file opened using at mode --
                    378: bool(false)
                    379: int(0)
                    380: bool(false)
                    381: 
                    382: -- Testing fgetcsv() with file opened using x mode --
                    383: bool(false)
                    384: int(0)
                    385: bool(false)
                    386: 
                    387: -- Testing fgetcsv() with file opened using xb mode --
                    388: bool(false)
                    389: int(0)
                    390: bool(false)
                    391: 
                    392: -- Testing fgetcsv() with file opened using xt mode --
                    393: bool(false)
                    394: int(0)
                    395: bool(false)
                    396: 
                    397: -- Testing fgetcsv() with file opened using w mode --
                    398: bool(false)
                    399: int(0)
                    400: bool(false)
                    401: 
                    402: -- Testing fgetcsv() with file opened using wb mode --
                    403: bool(false)
                    404: int(0)
                    405: bool(false)
                    406: 
                    407: -- Testing fgetcsv() with file opened using wt mode --
                    408: bool(false)
                    409: int(0)
                    410: bool(false)
                    411: 
                    412: -- Testing fgetcsv() with file opened using a mode --
                    413: bool(false)
                    414: int(0)
                    415: bool(false)
                    416: 
                    417: -- Testing fgetcsv() with file opened using ab mode --
                    418: bool(false)
                    419: int(0)
                    420: bool(false)
                    421: 
                    422: -- Testing fgetcsv() with file opened using at mode --
                    423: bool(false)
                    424: int(0)
                    425: bool(false)
                    426: 
                    427: -- Testing fgetcsv() with file opened using x mode --
                    428: bool(false)
                    429: int(0)
                    430: bool(false)
                    431: 
                    432: -- Testing fgetcsv() with file opened using xb mode --
                    433: bool(false)
                    434: int(0)
                    435: bool(false)
                    436: 
                    437: -- Testing fgetcsv() with file opened using xt mode --
                    438: bool(false)
                    439: int(0)
                    440: bool(false)
                    441: Done

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