Minimum Table range validation
Range must be at least 1 column and 2 rows
This commit is contained in:
parent
3c4a51acb5
commit
ea3263650b
|
|
@ -190,6 +190,11 @@ class Table
|
||||||
throw new PhpSpreadsheetException('Table must be set on a range of cells.');
|
throw new PhpSpreadsheetException('Table must be set on a range of cells.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[$width, $height] = Coordinate::rangeDimension($range);
|
||||||
|
if ($width < 1 || $height < 2) {
|
||||||
|
throw new PhpSpreadsheetException('The table range must be at least 1 column and 2 rows');
|
||||||
|
}
|
||||||
|
|
||||||
$this->range = $range;
|
$this->range = $range;
|
||||||
// Discard any column ruless that are no longer valid within this range
|
// Discard any column ruless that are no longer valid within this range
|
||||||
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);
|
[$rangeStart, $rangeEnd] = Coordinate::rangeBoundaries($this->range);
|
||||||
|
|
|
||||||
|
|
@ -173,14 +173,26 @@ class TableTest extends SetupTeardown
|
||||||
self::assertEquals($expectedResult, $result);
|
self::assertEquals($expectedResult, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetRangeInvalidRange(): void
|
/**
|
||||||
|
* @dataProvider invalidTableRangeProvider
|
||||||
|
*/
|
||||||
|
public function testSetRangeInvalidRange(string $range): void
|
||||||
{
|
{
|
||||||
$this->expectException(PhpSpreadsheetException::class);
|
$this->expectException(PhpSpreadsheetException::class);
|
||||||
|
|
||||||
$expectedResult = 'A1';
|
|
||||||
|
|
||||||
$sheet = $this->getSheet();
|
$sheet = $this->getSheet();
|
||||||
$table = new Table($expectedResult, $sheet);
|
new Table($range, $sheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invalidTableRangeProvider(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
['A1'],
|
||||||
|
['A1:A1'],
|
||||||
|
['B1:A4'],
|
||||||
|
['A1:D1'],
|
||||||
|
['D1:A1'],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetColumnsEmpty(): void
|
public function testGetColumnsEmpty(): void
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue