| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
- use PhpOffice\PhpSpreadsheet\Cell\DataType;
- use PhpOffice\PhpSpreadsheet\Spreadsheet;
- use PhpOffice\PhpSpreadsheet\Worksheet\CellIterator;
- use PhpOffice\PhpSpreadsheet\Worksheet\RowIterator;
- use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
- use PHPUnit\Framework\TestCase;
- class RowIteratorEmptyTest extends TestCase
- {
- private static function getPopulatedSheet(Spreadsheet $spreadsheet): Worksheet
- {
- $sheet = $spreadsheet->getActiveSheet();
- $sheet->setCellValueExplicit('A1', 'Hello World', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('B3', null, DataType::TYPE_NULL);
- $sheet->setCellValueExplicit('B4', '', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('B5', null, DataType::TYPE_NULL);
- $sheet->setCellValueExplicit('C5', '', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('B6', null, DataType::TYPE_NULL);
- $sheet->setCellValueExplicit('C6', 'PHP', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('B7', '', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('C7', 'PHP', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('B8', null, DataType::TYPE_NULL);
- $sheet->setCellValueExplicit('C8', '', DataType::TYPE_STRING);
- $sheet->setCellValueExplicit('D8', 'PHP', DataType::TYPE_STRING);
- return $sheet;
- }
- /**
- * @dataProvider emptyRowBasic
- */
- public function testIteratorEmptyRow(int $rowId, bool $expectedEmpty): void
- {
- $spreadsheet = new Spreadsheet();
- $sheet = self::getPopulatedSheet($spreadsheet);
- $iterator = new RowIterator($sheet, 1, 9);
- $iterator->seek($rowId);
- $row = $iterator->current();
- $isEmpty = $row->isEmpty();
- self::assertSame($expectedEmpty, $isEmpty);
- $spreadsheet->disconnectWorksheets();
- }
- public function emptyRowBasic(): array
- {
- return [
- [1, false],
- [2, true],
- [3, false],
- [4, false],
- [5, false],
- [6, false],
- [7, false],
- [8, false],
- [9, true],
- ];
- }
- /**
- * @dataProvider emptyRowNullAsEmpty
- */
- public function testIteratorEmptyRowWithNull(int $rowId, bool $expectedEmpty): void
- {
- $spreadsheet = new Spreadsheet();
- $sheet = self::getPopulatedSheet($spreadsheet);
- $iterator = new RowIterator($sheet, 1, 9);
- $iterator->seek($rowId);
- $row = $iterator->current();
- $isEmpty = $row->isEmpty(CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL);
- self::assertSame($expectedEmpty, $isEmpty);
- $spreadsheet->disconnectWorksheets();
- }
- public function emptyRowNullAsEmpty(): array
- {
- return [
- [1, false],
- [2, true],
- [3, true],
- [4, false],
- [5, false],
- [6, false],
- [7, false],
- [8, false],
- [9, true],
- ];
- }
- /**
- * @dataProvider emptyRowEmptyStringAsEmpty
- */
- public function testIteratorEmptyRowWithEmptyString(int $rowId, bool $expectedEmpty): void
- {
- $spreadsheet = new Spreadsheet();
- $sheet = self::getPopulatedSheet($spreadsheet);
- $iterator = new RowIterator($sheet, 1, 9);
- $iterator->seek($rowId);
- $row = $iterator->current();
- $isEmpty = $row->isEmpty(CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL);
- self::assertSame($expectedEmpty, $isEmpty);
- $spreadsheet->disconnectWorksheets();
- }
- public function emptyRowEmptyStringAsEmpty(): array
- {
- return [
- [1, false],
- [2, true],
- [3, false],
- [4, true],
- [5, false],
- [6, false],
- [7, false],
- [8, false],
- [9, true],
- ];
- }
- /**
- * @dataProvider emptyRowNullAndEmptyStringAsEmpty
- */
- public function testIteratorEmptyRowWithNullAndEmptyString(int $rowId, bool $expectedEmpty): void
- {
- $spreadsheet = new Spreadsheet();
- $sheet = self::getPopulatedSheet($spreadsheet);
- $iterator = new RowIterator($sheet, 1, 9);
- $iterator->seek($rowId);
- $row = $iterator->current();
- $isEmpty = $row->isEmpty(
- CellIterator::TREAT_EMPTY_STRING_AS_EMPTY_CELL | CellIterator::TREAT_NULL_VALUE_AS_EMPTY_CELL
- );
- self::assertSame($expectedEmpty, $isEmpty);
- $spreadsheet->disconnectWorksheets();
- }
- public function emptyRowNullAndEmptyStringAsEmpty(): array
- {
- return [
- [1, false],
- [2, true],
- [3, true],
- [4, true],
- [5, true],
- [6, false],
- [7, false],
- [8, false],
- [9, true],
- ];
- }
- }
|