PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/ReadBlankCellsTest.php
phinor 98d1782bbb Xls(x) Readers now respect the readBlankCells setting. (#835)
* Prevented reading of blank cells.

The "readEmptyCells" attribute is ignored when reading spreadsheets, resulting in memory bloat.

* Included a test file for Unit Testing

A file that contains 100 referenced cells, one of which contains data.

* New test file for reading in empty cells

* Added test for reading in a blank cell

* Updated CHANGELOG

* Changed "s to 's

Change required for code style compliance

* Further Code Style Changes

Removed spaces after variable, before array indices.

* Further Code Style Changes

* Further Code Style Changes

Removed additional spaces.

* Updated reader and tests.
2019-04-15 21:40:20 +02:00

51 lines
1.8 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Reader\IReadFilter;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class ReadBlankCellsTest extends AbstractFunctional
{
public function providerSheetFormat()
{
return [
['Xlsx'],
['Xls'],
// ['Ods'], // Broken. Requires fix in Ods reader.
// ['Csv'], // never reads blank cells
// ['Html'], // never reads blank cells
];
}
/**
* Test generate file with some empty cells
*
* @dataProvider providerSheetFormat
*
* @param array $arrayData
* @param mixed $format
*/
public function testXlsxLoadWithNoBlankCells($format)
{
$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()->getCell('B2')->setValue('');
$spreadsheet->getActiveSheet()->getCell('C1')->setValue('C1');
$spreadsheet->getActiveSheet()->getCell('C3')->setValue('C3');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
$this->assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('B2'));
$this->assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C2'));
$this->assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C3'));
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format, function($reader) {
$reader->setReadEmptyCells(false);
});
$this->assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('B2'));
$this->assertFalse($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C2'));
$this->assertTrue($reloadedSpreadsheet->getActiveSheet()->getCellCollection()->has('C3'));
}
}