mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-20 10:33:24 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
94 lines
2.9 KiB
PHP
94 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Worksheet\Table;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Exception as PhpSpreadsheetException;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Table\Column;
|
|
|
|
class ColumnTest extends SetupTeardown
|
|
{
|
|
protected function initTable(): Table
|
|
{
|
|
$sheet = $this->getSheet();
|
|
$sheet->getCell('G1')->setValue('Heading');
|
|
$sheet->getCell('G2')->setValue(2);
|
|
$sheet->getCell('G3')->setValue(3);
|
|
$sheet->getCell('G4')->setValue(4);
|
|
$sheet->getCell('H1')->setValue('Heading2');
|
|
$sheet->getCell('H2')->setValue(1);
|
|
$sheet->getCell('H3')->setValue(2);
|
|
$sheet->getCell('H4')->setValue(3);
|
|
$this->maxRow = $maxRow = 4;
|
|
$table = new Table();
|
|
$table->setRange("G1:H$maxRow");
|
|
|
|
return $table;
|
|
}
|
|
|
|
public function testVariousGets(): void
|
|
{
|
|
$table = $this->initTable();
|
|
$column = $table->getColumn('H');
|
|
$result = $column->getColumnIndex();
|
|
self::assertEquals('H', $result);
|
|
}
|
|
|
|
public function testGetBadColumnIndex(): void
|
|
{
|
|
$this->expectException(PhpSpreadsheetException::class);
|
|
$this->expectExceptionMessage('Column is outside of current table range.');
|
|
$table = $this->initTable();
|
|
$table->getColumn('B');
|
|
}
|
|
|
|
public function testSetColumnIndex(): void
|
|
{
|
|
$table = $this->initTable();
|
|
$column = $table->getColumn('H');
|
|
$column->setShowFilterButton(false);
|
|
$expectedResult = 'G';
|
|
|
|
$result = $column->setColumnIndex($expectedResult);
|
|
self::assertInstanceOf(Column::class, $result);
|
|
|
|
$result = $result->getColumnIndex();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function testVariousSets(): void
|
|
{
|
|
$table = $this->initTable();
|
|
$column = $table->getColumn('H');
|
|
|
|
$result = $column->setShowFilterButton(false);
|
|
self::assertInstanceOf(Column::class, $result);
|
|
self::assertFalse($column->getShowFilterButton());
|
|
|
|
$label = 'Total';
|
|
$result = $column->setTotalsRowLabel($label);
|
|
self::assertInstanceOf(Column::class, $result);
|
|
self::assertEquals($label, $column->getTotalsRowLabel());
|
|
|
|
$function = 'sum';
|
|
$result = $column->setTotalsRowFunction($function);
|
|
self::assertInstanceOf(Column::class, $result);
|
|
self::assertEquals($function, $column->getTotalsRowFunction());
|
|
|
|
$formula = '=SUM(Sales_Data[[#This Row],[Q1]:[Q4]])';
|
|
$result = $column->setColumnFormula($formula);
|
|
self::assertInstanceOf(Column::class, $result);
|
|
self::assertEquals($formula, $column->getColumnFormula());
|
|
}
|
|
|
|
public function testTable(): void
|
|
{
|
|
$table = $this->initTable();
|
|
$column = new Column('H');
|
|
$column->setTable($table);
|
|
self::assertEquals($table, $column->getTable());
|
|
}
|
|
}
|