diff --git a/tests/Spout/Reader/CSV/ReaderTest.php b/tests/Spout/Reader/CSV/ReaderTest.php index cdbca56..78d6721 100644 --- a/tests/Spout/Reader/CSV/ReaderTest.php +++ b/tests/Spout/Reader/CSV/ReaderTest.php @@ -343,6 +343,38 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expectedRows, $allRows); } + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldInludeRowsWithZerosOnly() + { + $allRows = $this->getAllRowsForFile('sheet_with_zeros_in_row.csv'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['1', '2', '3'], + ['0', '0', '0'] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); + } + + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldCreateOutputEmptyCellPreserved() + { + $allRows = $this->getAllRowsForFile('sheet_with_empty_cells.csv'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['0', '', ''], + ['1', '1', ''] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); + } + /** * @param string $fileName * @param string|void $fieldDelimiter diff --git a/tests/Spout/Reader/ODS/ReaderTest.php b/tests/Spout/Reader/ODS/ReaderTest.php index 8d9977b..e852630 100644 --- a/tests/Spout/Reader/ODS/ReaderTest.php +++ b/tests/Spout/Reader/ODS/ReaderTest.php @@ -387,6 +387,38 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $reader->open('php://memory'); } + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldInludeRowsWithZerosOnly() + { + $allRows = $this->getAllRowsForFile('sheet_with_zeros_in_row.ods'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['1', '2', '3'], + ['0', '0', '0'] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); + } + + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldCreateOutputEmptyCellPreserved() + { + $allRows = $this->getAllRowsForFile('sheet_with_empty_cells.ods'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['0', '', ''], + ['1', '1', ''] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); + } + /** * @param string $fileName * @return array All the read rows the given file diff --git a/tests/Spout/Reader/XLSX/ReaderTest.php b/tests/Spout/Reader/XLSX/ReaderTest.php index a3bdf7b..65a0069 100644 --- a/tests/Spout/Reader/XLSX/ReaderTest.php +++ b/tests/Spout/Reader/XLSX/ReaderTest.php @@ -428,6 +428,39 @@ class ReaderTest extends \PHPUnit_Framework_TestCase $reader->open('php://memory'); } + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldInludeRowsWithZerosOnly() + { + $allRows = $this->getAllRowsForFile('sheet_with_zeros_in_row.xlsx'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['1', '2', '3'], + ['0', '0', '0'] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be only 3 rows, because zeros (0) are valid values'); + } + + /** + * https://github.com/box/spout/issues/184 + * @return void + */ + public function testReadShouldCreateOutputEmptyCellPreserved() + { + $allRows = $this->getAllRowsForFile('sheet_with_empty_cells.xlsx'); + + $expectedRows = [ + ['A', 'B', 'C'], + ['0', '', ''], + ['1', '1', ''] + ]; + $this->assertEquals($expectedRows, $allRows, 'There should be 3 rows, with equal length'); + } + + /** * @param string $fileName * @return array All the read rows the given file diff --git a/tests/resources/csv/sheet_with_empty_cells.csv b/tests/resources/csv/sheet_with_empty_cells.csv new file mode 100644 index 0000000..157a854 --- /dev/null +++ b/tests/resources/csv/sheet_with_empty_cells.csv @@ -0,0 +1,3 @@ +"A","B","C" +0,, +1,1, diff --git a/tests/resources/csv/sheet_with_zeros_in_row.csv b/tests/resources/csv/sheet_with_zeros_in_row.csv new file mode 100644 index 0000000..6078d9e --- /dev/null +++ b/tests/resources/csv/sheet_with_zeros_in_row.csv @@ -0,0 +1,3 @@ +"A","B","C" +1,2,3 +0,0,0 diff --git a/tests/resources/ods/sheet_with_empty_cells.ods b/tests/resources/ods/sheet_with_empty_cells.ods new file mode 100644 index 0000000..b7c3a91 Binary files /dev/null and b/tests/resources/ods/sheet_with_empty_cells.ods differ diff --git a/tests/resources/ods/sheet_with_zeros_in_row.ods b/tests/resources/ods/sheet_with_zeros_in_row.ods new file mode 100644 index 0000000..0b71aae Binary files /dev/null and b/tests/resources/ods/sheet_with_zeros_in_row.ods differ diff --git a/tests/resources/xlsx/sheet_with_empty_cells.xlsx b/tests/resources/xlsx/sheet_with_empty_cells.xlsx new file mode 100644 index 0000000..d815a1c Binary files /dev/null and b/tests/resources/xlsx/sheet_with_empty_cells.xlsx differ diff --git a/tests/resources/xlsx/sheet_with_zeros_in_row.xlsx b/tests/resources/xlsx/sheet_with_zeros_in_row.xlsx new file mode 100644 index 0000000..3812e7d Binary files /dev/null and b/tests/resources/xlsx/sheet_with_zeros_in_row.xlsx differ