From 4f08cbb561c9bb610f416504ec36926de99ce7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Bl=C3=A4ul?= Date: Sat, 25 Nov 2017 12:30:14 +0100 Subject: [PATCH] PHPUnit: added test for UTF-8 and sep= row Thanks to https://github.com/blaubaer! Some things in the CSV file originate from java-kata-1 by Gregor Noczinski --- .../UTF-8_sep_row_but_no_BOM.csv | 5 ++++ tests/methods/parse_test.php | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/example_files/UTF-8_sep_row_but_no_BOM.csv diff --git a/tests/example_files/UTF-8_sep_row_but_no_BOM.csv b/tests/example_files/UTF-8_sep_row_but_no_BOM.csv new file mode 100644 index 0000000..69a120c --- /dev/null +++ b/tests/example_files/UTF-8_sep_row_but_no_BOM.csv @@ -0,0 +1,5 @@ +sep=; +title;isbn;publishedAt +Красивая кулинария;5454-5587-3210;21.05.2011 +The Wine Connoisseurs;2547-8548-2541;12.12.2011 +Weißwein;1313-4545-8875;23.02.2012 diff --git a/tests/methods/parse_test.php b/tests/methods/parse_test.php index 62ead34..8946a22 100644 --- a/tests/methods/parse_test.php +++ b/tests/methods/parse_test.php @@ -39,6 +39,11 @@ class parse_test extends PHPUnit_Framework_TestCase { $this->assertEquals($expected_data, $row); } + public function test_sep_row_auto_detection_UTF8_no_BOM() { + $this->csv->auto(__DIR__ . '/../example_files/UTF-8_sep_row_but_no_BOM.csv'); + $this->assertEquals($this->_get_magazines_data(), $this->csv->data); + } + public function test_single_column() { $this->csv->auto(__DIR__ . '/../example_files/single_column.csv'); $expected = [ @@ -50,4 +55,24 @@ class parse_test extends PHPUnit_Framework_TestCase { $this->assertEquals($expected, $this->csv->data); } + + protected function _get_magazines_data() { + return [ + [ + 'title' => 'Красивая кулинария', + 'isbn' => '5454-5587-3210', + 'publishedAt' => '21.05.2011', + ], + [ + 'title' => 'The Wine Connoisseurs', + 'isbn' => '2547-8548-2541', + 'publishedAt' => '12.12.2011', + ], + [ + 'title' => 'Weißwein', + 'isbn' => '1313-4545-8875', + 'publishedAt' => '23.02.2012', + ], + ]; + } }