@@ -285,31 +285,52 @@ private function doTestEncodeFormulas(bool $legacy = false)
285
285
286
286
$ this ->assertSame (<<<'CSV'
287
287
0
288
- " =2+3"
288
+ ' =2+3
289
289
290
290
CSV
291
291
, $ this ->encoder ->encode (['=2+3 ' ], 'csv ' ));
292
292
293
293
$ this ->assertSame (<<<'CSV'
294
294
0
295
- " -2+3"
295
+ ' -2+3
296
296
297
297
CSV
298
298
, $ this ->encoder ->encode (['-2+3 ' ], 'csv ' ));
299
299
300
300
$ this ->assertSame (<<<'CSV'
301
301
0
302
- " +2+3"
302
+ ' +2+3
303
303
304
304
CSV
305
305
, $ this ->encoder ->encode (['+2+3 ' ], 'csv ' ));
306
306
307
307
$ this ->assertSame (<<<'CSV'
308
308
0
309
- " @MyDataColumn"
309
+ ' @MyDataColumn
310
310
311
311
CSV
312
312
, $ this ->encoder ->encode (['@MyDataColumn ' ], 'csv ' ));
313
+
314
+ $ this ->assertSame (<<<'CSV'
315
+ 0
316
+ "' tab"
317
+
318
+ CSV
319
+ , $ this ->encoder ->encode (["\ttab " ], 'csv ' ));
320
+
321
+ $ this ->assertSame (<<<'CSV'
322
+ 0
323
+ "'=1+2"";=1+2"
324
+
325
+ CSV
326
+ , $ this ->encoder ->encode (['=1+2";=1+2 ' ], 'csv ' ));
327
+
328
+ $ this ->assertSame (<<<'CSV'
329
+ 0
330
+ "'=1+2'"" ;,=1+2"
331
+
332
+ CSV
333
+ , $ this ->encoder ->encode (['=1+2 \'" ;,=1+2 ' ], 'csv ' ));
313
334
}
314
335
315
336
public function testDoNotEncodeFormulas ()
@@ -341,13 +362,34 @@ public function testDoNotEncodeFormulas()
341
362
342
363
CSV
343
364
, $ this ->encoder ->encode (['@MyDataColumn ' ], 'csv ' ));
365
+
366
+ $ this ->assertSame (<<<'CSV'
367
+ 0
368
+ " tab"
369
+
370
+ CSV
371
+ , $ this ->encoder ->encode (["\ttab " ], 'csv ' ));
372
+
373
+ $ this ->assertSame (<<<'CSV'
374
+ 0
375
+ "=1+2"";=1+2"
376
+
377
+ CSV
378
+ , $ this ->encoder ->encode (['=1+2";=1+2 ' ], 'csv ' ));
379
+
380
+ $ this ->assertSame (<<<'CSV'
381
+ 0
382
+ "=1+2'"" ;,=1+2"
383
+
384
+ CSV
385
+ , $ this ->encoder ->encode (['=1+2 \'" ;,=1+2 ' ], 'csv ' ));
344
386
}
345
387
346
388
public function testEncodeFormulasWithSettingsPassedInContext ()
347
389
{
348
390
$ this ->assertSame (<<<'CSV'
349
391
0
350
- " =2+3"
392
+ ' =2+3
351
393
352
394
CSV
353
395
, $ this ->encoder ->encode (['=2+3 ' ], 'csv ' , [
@@ -356,7 +398,7 @@ public function testEncodeFormulasWithSettingsPassedInContext()
356
398
357
399
$ this ->assertSame (<<<'CSV'
358
400
0
359
- " -2+3"
401
+ ' -2+3
360
402
361
403
CSV
362
404
, $ this ->encoder ->encode (['-2+3 ' ], 'csv ' , [
@@ -365,7 +407,7 @@ public function testEncodeFormulasWithSettingsPassedInContext()
365
407
366
408
$ this ->assertSame (<<<'CSV'
367
409
0
368
- " +2+3"
410
+ ' +2+3
369
411
370
412
CSV
371
413
, $ this ->encoder ->encode (['+2+3 ' ], 'csv ' , [
@@ -374,12 +416,39 @@ public function testEncodeFormulasWithSettingsPassedInContext()
374
416
375
417
$ this ->assertSame (<<<'CSV'
376
418
0
377
- " @MyDataColumn"
419
+ ' @MyDataColumn
378
420
379
421
CSV
380
422
, $ this ->encoder ->encode (['@MyDataColumn ' ], 'csv ' , [
381
423
CsvEncoder::ESCAPE_FORMULAS_KEY => true ,
382
424
]));
425
+
426
+ $ this ->assertSame (<<<'CSV'
427
+ 0
428
+ "' tab"
429
+
430
+ CSV
431
+ , $ this ->encoder ->encode (["\ttab " ], 'csv ' , [
432
+ CsvEncoder::ESCAPE_FORMULAS_KEY => true ,
433
+ ]));
434
+
435
+ $ this ->assertSame (<<<'CSV'
436
+ 0
437
+ "'=1+2"";=1+2"
438
+
439
+ CSV
440
+ , $ this ->encoder ->encode (['=1+2";=1+2 ' ], 'csv ' , [
441
+ CsvEncoder::ESCAPE_FORMULAS_KEY => true ,
442
+ ]));
443
+
444
+ $ this ->assertSame (<<<'CSV'
445
+ 0
446
+ "'=1+2'"" ;,=1+2"
447
+
448
+ CSV
449
+ , $ this ->encoder ->encode (['=1+2 \'" ;,=1+2 ' ], 'csv ' , [
450
+ CsvEncoder::ESCAPE_FORMULAS_KEY => true ,
451
+ ]));
383
452
}
384
453
385
454
public function testEncodeWithoutHeader ()
0 commit comments