Updates to 3rd party libraries
Add Dockerfile and specific docker-php.ini
This commit is contained in:
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter\Column;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RuleTest extends TestCase
|
||||
{
|
||||
private $testAutoFilterRuleObject;
|
||||
|
||||
private $mockAutoFilterColumnObject;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockAutoFilterColumnObject = $this->getMockBuilder(Column::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->testAutoFilterRuleObject = new Column\Rule(
|
||||
$this->mockAutoFilterColumnObject
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetRuleType()
|
||||
{
|
||||
$result = $this->testAutoFilterRuleObject->getRuleType();
|
||||
self::assertEquals(Column\Rule::AUTOFILTER_RULETYPE_FILTER, $result);
|
||||
}
|
||||
|
||||
public function testSetRuleType()
|
||||
{
|
||||
$expectedResult = Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP;
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterRuleObject->setRuleType($expectedResult);
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterRuleObject->getRuleType();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testSetValue()
|
||||
{
|
||||
$expectedResult = 100;
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterRuleObject->setValue($expectedResult);
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterRuleObject->getValue();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testGetOperator()
|
||||
{
|
||||
$result = $this->testAutoFilterRuleObject->getOperator();
|
||||
self::assertEquals(Column\Rule::AUTOFILTER_COLUMN_RULE_EQUAL, $result);
|
||||
}
|
||||
|
||||
public function testSetOperator()
|
||||
{
|
||||
$expectedResult = Column\Rule::AUTOFILTER_COLUMN_RULE_LESSTHAN;
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterRuleObject->setOperator($expectedResult);
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterRuleObject->getOperator();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testSetGrouping()
|
||||
{
|
||||
$expectedResult = Column\Rule::AUTOFILTER_RULETYPE_DATEGROUP_MONTH;
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterRuleObject->setGrouping($expectedResult);
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterRuleObject->getGrouping();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testGetParent()
|
||||
{
|
||||
$result = $this->testAutoFilterRuleObject->getParent();
|
||||
self::assertInstanceOf(Column::class, $result);
|
||||
}
|
||||
|
||||
public function testSetParent()
|
||||
{
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterRuleObject->setParent($this->mockAutoFilterColumnObject);
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$result = clone $this->testAutoFilterRuleObject;
|
||||
self::assertInstanceOf(Column\Rule::class, $result);
|
||||
}
|
||||
}
|
176
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php
vendored
Normal file
176
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/AutoFilter/ColumnTest.php
vendored
Normal file
@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet\AutoFilter;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ColumnTest extends TestCase
|
||||
{
|
||||
private $testInitialColumn = 'H';
|
||||
|
||||
private $testAutoFilterColumnObject;
|
||||
|
||||
private $mockAutoFilterObject;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockAutoFilterObject = $this->getMockBuilder(AutoFilter::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockAutoFilterObject->expects($this->any())
|
||||
->method('testColumnInRange')
|
||||
->will($this->returnValue(3));
|
||||
|
||||
$this->testAutoFilterColumnObject = new AutoFilter\Column($this->testInitialColumn, $this->mockAutoFilterObject);
|
||||
}
|
||||
|
||||
public function testGetColumnIndex()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->getColumnIndex();
|
||||
self::assertEquals($this->testInitialColumn, $result);
|
||||
}
|
||||
|
||||
public function testSetColumnIndex()
|
||||
{
|
||||
$expectedResult = 'L';
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterColumnObject->setColumnIndex($expectedResult);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterColumnObject->getColumnIndex();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testGetParent()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->getParent();
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
}
|
||||
|
||||
public function testSetParent()
|
||||
{
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterColumnObject->setParent($this->mockAutoFilterObject);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
}
|
||||
|
||||
public function testGetFilterType()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->getFilterType();
|
||||
self::assertEquals(AutoFilter\Column::AUTOFILTER_FILTERTYPE_FILTER, $result);
|
||||
}
|
||||
|
||||
public function testSetFilterType()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->setFilterType(AutoFilter\Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterColumnObject->getFilterType();
|
||||
self::assertEquals(AutoFilter\Column::AUTOFILTER_FILTERTYPE_DYNAMICFILTER, $result);
|
||||
}
|
||||
|
||||
public function testSetInvalidFilterTypeThrowsException()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$expectedResult = 'Unfiltered';
|
||||
|
||||
$this->testAutoFilterColumnObject->setFilterType($expectedResult);
|
||||
}
|
||||
|
||||
public function testGetJoin()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->getJoin();
|
||||
self::assertEquals(AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_OR, $result);
|
||||
}
|
||||
|
||||
public function testSetJoin()
|
||||
{
|
||||
$result = $this->testAutoFilterColumnObject->setJoin(AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterColumnObject->getJoin();
|
||||
self::assertEquals(AutoFilter\Column::AUTOFILTER_COLUMN_JOIN_AND, $result);
|
||||
}
|
||||
|
||||
public function testSetInvalidJoinThrowsException()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$expectedResult = 'Neither';
|
||||
|
||||
$this->testAutoFilterColumnObject->setJoin($expectedResult);
|
||||
}
|
||||
|
||||
public function testSetAttributes()
|
||||
{
|
||||
$attributeSet = [
|
||||
'val' => 100,
|
||||
'maxVal' => 200,
|
||||
];
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterColumnObject->setAttributes($attributeSet);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
}
|
||||
|
||||
public function testGetAttributes()
|
||||
{
|
||||
$attributeSet = [
|
||||
'val' => 100,
|
||||
'maxVal' => 200,
|
||||
];
|
||||
|
||||
$this->testAutoFilterColumnObject->setAttributes($attributeSet);
|
||||
|
||||
$result = $this->testAutoFilterColumnObject->getAttributes();
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(count($attributeSet), $result);
|
||||
}
|
||||
|
||||
public function testSetAttribute()
|
||||
{
|
||||
$attributeSet = [
|
||||
'val' => 100,
|
||||
'maxVal' => 200,
|
||||
];
|
||||
|
||||
foreach ($attributeSet as $attributeName => $attributeValue) {
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterColumnObject->setAttribute($attributeName, $attributeValue);
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetAttribute()
|
||||
{
|
||||
$attributeSet = [
|
||||
'val' => 100,
|
||||
'maxVal' => 200,
|
||||
];
|
||||
|
||||
$this->testAutoFilterColumnObject->setAttributes($attributeSet);
|
||||
|
||||
foreach ($attributeSet as $attributeName => $attributeValue) {
|
||||
$result = $this->testAutoFilterColumnObject->getAttribute($attributeName);
|
||||
self::assertEquals($attributeValue, $result);
|
||||
}
|
||||
$result = $this->testAutoFilterColumnObject->getAttribute('nonExistentAttribute');
|
||||
self::assertNull($result);
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$originalRule = $this->testAutoFilterColumnObject->createRule();
|
||||
$result = clone $this->testAutoFilterColumnObject;
|
||||
self::assertInstanceOf(AutoFilter\Column::class, $result);
|
||||
self::assertCount(1, $result->getRules());
|
||||
self::assertContainsOnlyInstancesOf(AutoFilter\Column\Rule::class, $result->getRules());
|
||||
$clonedRule = $result->getRules()[0];
|
||||
self::assertNotSame($originalRule, $clonedRule);
|
||||
self::assertSame($result, $clonedRule->getParent());
|
||||
}
|
||||
}
|
336
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php
vendored
Normal file
336
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/AutoFilterTest.php
vendored
Normal file
@ -0,0 +1,336 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Collection\Cells;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AutoFilterTest extends TestCase
|
||||
{
|
||||
private $testInitialRange = 'H2:O256';
|
||||
|
||||
/**
|
||||
* @var AutoFilter
|
||||
*/
|
||||
private $testAutoFilterObject;
|
||||
|
||||
private $mockWorksheetObject;
|
||||
|
||||
private $cellCollection;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockWorksheetObject = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->cellCollection = $this->getMockBuilder(Cells::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->mockWorksheetObject->expects($this->any())
|
||||
->method('getCellCollection')
|
||||
->will($this->returnValue($this->cellCollection));
|
||||
|
||||
$this->testAutoFilterObject = new AutoFilter($this->testInitialRange, $this->mockWorksheetObject);
|
||||
}
|
||||
|
||||
public function testToString()
|
||||
{
|
||||
$expectedResult = $this->testInitialRange;
|
||||
|
||||
// magic __toString should return the active autofilter range
|
||||
$result = $this->testAutoFilterObject;
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testGetParent()
|
||||
{
|
||||
$result = $this->testAutoFilterObject->getParent();
|
||||
self::assertInstanceOf(Worksheet::class, $result);
|
||||
}
|
||||
|
||||
public function testSetParent()
|
||||
{
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setParent($this->mockWorksheetObject);
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
}
|
||||
|
||||
public function testGetRange()
|
||||
{
|
||||
$expectedResult = $this->testInitialRange;
|
||||
|
||||
// Result should be the active autofilter range
|
||||
$result = $this->testAutoFilterObject->getRange();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testSetRange()
|
||||
{
|
||||
$ranges = [
|
||||
'G1:J512' => 'Worksheet1!G1:J512',
|
||||
'K1:N20' => 'K1:N20',
|
||||
];
|
||||
|
||||
foreach ($ranges as $actualRange => $fullRange) {
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setRange($fullRange);
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
// Result should be the new autofilter range
|
||||
$result = $this->testAutoFilterObject->getRange();
|
||||
self::assertEquals($actualRange, $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function testClearRange()
|
||||
{
|
||||
$expectedResult = '';
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setRange('');
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
// Result should be a clear range
|
||||
$result = $this->testAutoFilterObject->getRange();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
}
|
||||
|
||||
public function testSetRangeInvalidRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$expectedResult = 'A1';
|
||||
|
||||
$this->testAutoFilterObject->setRange($expectedResult);
|
||||
}
|
||||
|
||||
public function testGetColumnsEmpty()
|
||||
{
|
||||
// There should be no columns yet defined
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(0, $result);
|
||||
}
|
||||
|
||||
public function testGetColumnOffset()
|
||||
{
|
||||
$columnIndexes = [
|
||||
'H' => 0,
|
||||
'K' => 3,
|
||||
'M' => 5,
|
||||
];
|
||||
|
||||
// If we request a specific column by its column ID, we should get an
|
||||
// integer returned representing the column offset within the range
|
||||
foreach ($columnIndexes as $columnIndex => $columnOffset) {
|
||||
$result = $this->testAutoFilterObject->getColumnOffset($columnIndex);
|
||||
self::assertEquals($columnOffset, $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetInvalidColumnOffset()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$invalidColumn = 'G';
|
||||
|
||||
$this->testAutoFilterObject->getColumnOffset($invalidColumn);
|
||||
}
|
||||
|
||||
public function testSetColumnWithString()
|
||||
{
|
||||
$expectedResult = 'L';
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setColumn($expectedResult);
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
// Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column
|
||||
// objects for each column we set indexed by the column ID
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(1, $result);
|
||||
self::assertArrayHasKey($expectedResult, $result);
|
||||
self::assertInstanceOf(Column::class, $result[$expectedResult]);
|
||||
}
|
||||
|
||||
public function testSetInvalidColumnWithString()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$invalidColumn = 'A';
|
||||
|
||||
$this->testAutoFilterObject->setColumn($invalidColumn);
|
||||
}
|
||||
|
||||
public function testSetColumnWithColumnObject()
|
||||
{
|
||||
$expectedResult = 'M';
|
||||
$columnObject = new AutoFilter\Column($expectedResult);
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setColumn($columnObject);
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
// Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column
|
||||
// objects for each column we set indexed by the column ID
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(1, $result);
|
||||
self::assertArrayHasKey($expectedResult, $result);
|
||||
self::assertInstanceOf(Column::class, $result[$expectedResult]);
|
||||
}
|
||||
|
||||
public function testSetInvalidColumnWithObject()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$invalidColumn = 'E';
|
||||
$this->testAutoFilterObject->setColumn($invalidColumn);
|
||||
}
|
||||
|
||||
public function testSetColumnWithInvalidDataType()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$invalidColumn = 123.456;
|
||||
$this->testAutoFilterObject->setColumn($invalidColumn);
|
||||
}
|
||||
|
||||
public function testGetColumns()
|
||||
{
|
||||
$columnIndexes = ['L', 'M'];
|
||||
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
// Result should be an array of \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column
|
||||
// objects for each column we set indexed by the column ID
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(count($columnIndexes), $result);
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
self::assertArrayHasKey($columnIndex, $result);
|
||||
self::assertInstanceOf(Column::class, $result[$columnIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetColumn()
|
||||
{
|
||||
$columnIndexes = ['L', 'M'];
|
||||
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
|
||||
// If we request a specific column by its column ID, we should
|
||||
// get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
$result = $this->testAutoFilterObject->getColumn($columnIndex);
|
||||
self::assertInstanceOf(Column::class, $result);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetColumnByOffset()
|
||||
{
|
||||
$columnIndexes = [
|
||||
0 => 'H',
|
||||
3 => 'K',
|
||||
5 => 'M',
|
||||
];
|
||||
|
||||
// If we request a specific column by its offset, we should
|
||||
// get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned
|
||||
foreach ($columnIndexes as $columnIndex => $columnID) {
|
||||
$result = $this->testAutoFilterObject->getColumnByOffset($columnIndex);
|
||||
self::assertInstanceOf(Column::class, $result);
|
||||
self::assertEquals($result->getColumnIndex(), $columnID);
|
||||
}
|
||||
}
|
||||
|
||||
public function testGetColumnIfNotSet()
|
||||
{
|
||||
// If we request a specific column by its column ID, we should
|
||||
// get a \PhpOffice\PhpSpreadsheet\Worksheet\Worksheet\AutoFilter\Column object returned
|
||||
$result = $this->testAutoFilterObject->getColumn('K');
|
||||
self::assertInstanceOf(Column::class, $result);
|
||||
}
|
||||
|
||||
public function testGetColumnWithoutRangeSet()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
// Clear the range
|
||||
$this->testAutoFilterObject->setRange('');
|
||||
$this->testAutoFilterObject->getColumn('A');
|
||||
}
|
||||
|
||||
public function testClearRangeWithExistingColumns()
|
||||
{
|
||||
$expectedResult = '';
|
||||
|
||||
$columnIndexes = ['L', 'M', 'N'];
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setRange('');
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
// Range should be cleared
|
||||
$result = $this->testAutoFilterObject->getRange();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
|
||||
// Column array should be cleared
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(0, $result);
|
||||
}
|
||||
|
||||
public function testSetRangeWithExistingColumns()
|
||||
{
|
||||
$expectedResult = 'G1:J512';
|
||||
|
||||
// These columns should be retained
|
||||
$columnIndexes1 = ['I', 'J'];
|
||||
foreach ($columnIndexes1 as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
// These columns should be discarded
|
||||
$columnIndexes2 = ['K', 'L', 'M'];
|
||||
foreach ($columnIndexes2 as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
|
||||
// Setters return the instance to implement the fluent interface
|
||||
$result = $this->testAutoFilterObject->setRange($expectedResult);
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
|
||||
// Range should be correctly set
|
||||
$result = $this->testAutoFilterObject->getRange();
|
||||
self::assertEquals($expectedResult, $result);
|
||||
|
||||
// Only columns that existed in the original range and that
|
||||
// still fall within the new range should be retained
|
||||
$result = $this->testAutoFilterObject->getColumns();
|
||||
self::assertInternalType('array', $result);
|
||||
self::assertCount(count($columnIndexes1), $result);
|
||||
}
|
||||
|
||||
public function testClone()
|
||||
{
|
||||
$columnIndexes = ['L', 'M'];
|
||||
|
||||
foreach ($columnIndexes as $columnIndex) {
|
||||
$this->testAutoFilterObject->setColumn($columnIndex);
|
||||
}
|
||||
|
||||
$result = clone $this->testAutoFilterObject;
|
||||
self::assertInstanceOf(AutoFilter::class, $result);
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ColumnCellIteratorTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockCell;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockCell = $this->getMockBuilder(Cell::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestRow')
|
||||
->will($this->returnValue(5));
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getCellByColumnAndRow')
|
||||
->will($this->returnValue($this->mockCell));
|
||||
}
|
||||
|
||||
public function testIteratorFullRange()
|
||||
{
|
||||
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A');
|
||||
$ColumnCellIndexResult = 1;
|
||||
self::assertEquals($ColumnCellIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $ColumnCell) {
|
||||
self::assertEquals($ColumnCellIndexResult++, $key);
|
||||
self::assertInstanceOf(Cell::class, $ColumnCell);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorStartEndRange()
|
||||
{
|
||||
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
||||
$ColumnCellIndexResult = 2;
|
||||
self::assertEquals($ColumnCellIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $ColumnCell) {
|
||||
self::assertEquals($ColumnCellIndexResult++, $key);
|
||||
self::assertInstanceOf(Cell::class, $ColumnCell);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorSeekAndPrev()
|
||||
{
|
||||
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
||||
$columnIndexResult = 4;
|
||||
$iterator->seek(4);
|
||||
self::assertEquals($columnIndexResult, $iterator->key());
|
||||
|
||||
for ($i = 1; $i < $columnIndexResult - 1; ++$i) {
|
||||
$iterator->prev();
|
||||
self::assertEquals($columnIndexResult - $i, $iterator->key());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeekOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
||||
$iterator->seek(1);
|
||||
}
|
||||
|
||||
public function testPrevOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new ColumnCellIterator($this->mockWorksheet, 'A', 2, 4);
|
||||
$iterator->prev();
|
||||
}
|
||||
}
|
85
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php
vendored
Normal file
85
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/ColumnIteratorTest.php
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Column;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ColumnIteratorTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockColumn;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockColumn = $this->getMockBuilder(Column::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestColumn')
|
||||
->will($this->returnValue('E'));
|
||||
}
|
||||
|
||||
public function testIteratorFullRange()
|
||||
{
|
||||
$iterator = new ColumnIterator($this->mockWorksheet);
|
||||
$columnIndexResult = 'A';
|
||||
self::assertEquals($columnIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $column) {
|
||||
self::assertEquals($columnIndexResult++, $key);
|
||||
self::assertInstanceOf(Column::class, $column);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorStartEndRange()
|
||||
{
|
||||
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
|
||||
$columnIndexResult = 'B';
|
||||
self::assertEquals($columnIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $column) {
|
||||
self::assertEquals($columnIndexResult++, $key);
|
||||
self::assertInstanceOf(Column::class, $column);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorSeekAndPrev()
|
||||
{
|
||||
$ranges = range('A', 'E');
|
||||
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
|
||||
$columnIndexResult = 'D';
|
||||
$iterator->seek('D');
|
||||
self::assertEquals($columnIndexResult, $iterator->key());
|
||||
|
||||
for ($i = 1; $i < array_search($columnIndexResult, $ranges); ++$i) {
|
||||
$iterator->prev();
|
||||
$expectedResult = $ranges[array_search($columnIndexResult, $ranges) - $i];
|
||||
self::assertEquals($expectedResult, $iterator->key());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeekOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
|
||||
$iterator->seek('A');
|
||||
}
|
||||
|
||||
public function testPrevOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new ColumnIterator($this->mockWorksheet, 'B', 'D');
|
||||
$iterator->prev();
|
||||
}
|
||||
}
|
48
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php
vendored
Normal file
48
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/ColumnTest.php
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Column;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\ColumnCellIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ColumnTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockColumn;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestRow')
|
||||
->will($this->returnValue(5));
|
||||
}
|
||||
|
||||
public function testInstantiateColumnDefault()
|
||||
{
|
||||
$column = new Column($this->mockWorksheet);
|
||||
self::assertInstanceOf(Column::class, $column);
|
||||
$columnIndex = $column->getColumnIndex();
|
||||
self::assertEquals('A', $columnIndex);
|
||||
}
|
||||
|
||||
public function testInstantiateColumnSpecified()
|
||||
{
|
||||
$column = new Column($this->mockWorksheet, 'E');
|
||||
self::assertInstanceOf(Column::class, $column);
|
||||
$columnIndex = $column->getColumnIndex();
|
||||
self::assertEquals('E', $columnIndex);
|
||||
}
|
||||
|
||||
public function testGetCellIterator()
|
||||
{
|
||||
$column = new Column($this->mockWorksheet);
|
||||
$cellIterator = $column->getCellIterator();
|
||||
self::assertInstanceOf(ColumnCellIterator::class, $cellIterator);
|
||||
}
|
||||
}
|
40
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
vendored
Normal file
40
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/DrawingTest.php
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\MemoryDrawing;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class DrawingTest extends TestCase
|
||||
{
|
||||
public function testCloningWorksheetWithImages()
|
||||
{
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$aSheet = $spreadsheet->getActiveSheet();
|
||||
|
||||
$gdImage = @imagecreatetruecolor(120, 20);
|
||||
$textColor = imagecolorallocate($gdImage, 255, 255, 255);
|
||||
imagestring($gdImage, 1, 5, 5, 'Created with PhpSpreadsheet', $textColor);
|
||||
|
||||
$drawing = new MemoryDrawing();
|
||||
$drawing->setName('In-Memory image 1');
|
||||
$drawing->setDescription('In-Memory image 1');
|
||||
$drawing->setCoordinates('A1');
|
||||
$drawing->setImageResource($gdImage);
|
||||
$drawing->setRenderingFunction(
|
||||
MemoryDrawing::RENDERING_JPEG
|
||||
);
|
||||
$drawing->setMimeType(MemoryDrawing::MIMETYPE_DEFAULT);
|
||||
$drawing->setHeight(36);
|
||||
$drawing->setWorksheet($aSheet);
|
||||
|
||||
$originDrawingCount = count($aSheet->getDrawingCollection());
|
||||
$clonedWorksheet = clone $aSheet;
|
||||
$clonedDrawingCount = count($clonedWorksheet->getDrawingCollection());
|
||||
|
||||
self::assertEquals($originDrawingCount, $clonedDrawingCount);
|
||||
self::assertNotSame($aSheet, $clonedWorksheet);
|
||||
self::assertNotSame($aSheet->getDrawingCollection(), $clonedWorksheet->getDrawingCollection());
|
||||
}
|
||||
}
|
88
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php
vendored
Normal file
88
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowCellIteratorTest.php
vendored
Normal file
@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Cell\Cell;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RowCellIteratorTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockCell;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockCell = $this->getMockBuilder(Cell::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestColumn')
|
||||
->will($this->returnValue('E'));
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getCellByColumnAndRow')
|
||||
->will($this->returnValue($this->mockCell));
|
||||
}
|
||||
|
||||
public function testIteratorFullRange()
|
||||
{
|
||||
$iterator = new RowCellIterator($this->mockWorksheet);
|
||||
$RowCellIndexResult = 'A';
|
||||
self::assertEquals($RowCellIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $RowCell) {
|
||||
self::assertEquals($RowCellIndexResult++, $key);
|
||||
self::assertInstanceOf(Cell::class, $RowCell);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorStartEndRange()
|
||||
{
|
||||
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
|
||||
$RowCellIndexResult = 'B';
|
||||
self::assertEquals($RowCellIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $RowCell) {
|
||||
self::assertEquals($RowCellIndexResult++, $key);
|
||||
self::assertInstanceOf(Cell::class, $RowCell);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorSeekAndPrev()
|
||||
{
|
||||
$ranges = range('A', 'E');
|
||||
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
|
||||
$RowCellIndexResult = 'D';
|
||||
$iterator->seek('D');
|
||||
self::assertEquals($RowCellIndexResult, $iterator->key());
|
||||
|
||||
for ($i = 1; $i < array_search($RowCellIndexResult, $ranges); ++$i) {
|
||||
$iterator->prev();
|
||||
$expectedResult = $ranges[array_search($RowCellIndexResult, $ranges) - $i];
|
||||
self::assertEquals($expectedResult, $iterator->key());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeekOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
|
||||
$iterator->seek(1);
|
||||
}
|
||||
|
||||
public function testPrevOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new RowCellIterator($this->mockWorksheet, 2, 'B', 'D');
|
||||
$iterator->prev();
|
||||
}
|
||||
}
|
83
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php
vendored
Normal file
83
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowIteratorTest.php
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Row;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\RowIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RowIteratorTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockRow;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockRow = $this->getMockBuilder(Row::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestRow')
|
||||
->will($this->returnValue(5));
|
||||
}
|
||||
|
||||
public function testIteratorFullRange()
|
||||
{
|
||||
$iterator = new RowIterator($this->mockWorksheet);
|
||||
$rowIndexResult = 1;
|
||||
self::assertEquals($rowIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $row) {
|
||||
self::assertEquals($rowIndexResult++, $key);
|
||||
self::assertInstanceOf(Row::class, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorStartEndRange()
|
||||
{
|
||||
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
|
||||
$rowIndexResult = 2;
|
||||
self::assertEquals($rowIndexResult, $iterator->key());
|
||||
|
||||
foreach ($iterator as $key => $row) {
|
||||
self::assertEquals($rowIndexResult++, $key);
|
||||
self::assertInstanceOf(Row::class, $row);
|
||||
}
|
||||
}
|
||||
|
||||
public function testIteratorSeekAndPrev()
|
||||
{
|
||||
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
|
||||
$columnIndexResult = 4;
|
||||
$iterator->seek(4);
|
||||
self::assertEquals($columnIndexResult, $iterator->key());
|
||||
|
||||
for ($i = 1; $i < $columnIndexResult - 1; ++$i) {
|
||||
$iterator->prev();
|
||||
self::assertEquals($columnIndexResult - $i, $iterator->key());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSeekOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
|
||||
$iterator->seek(1);
|
||||
}
|
||||
|
||||
public function testPrevOutOfRange()
|
||||
{
|
||||
$this->expectException(\PhpOffice\PhpSpreadsheet\Exception::class);
|
||||
|
||||
$iterator = new RowIterator($this->mockWorksheet, 2, 4);
|
||||
$iterator->prev();
|
||||
}
|
||||
}
|
48
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowTest.php
vendored
Normal file
48
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/RowTest.php
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Row;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\RowCellIterator;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RowTest extends TestCase
|
||||
{
|
||||
public $mockWorksheet;
|
||||
|
||||
public $mockRow;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockWorksheet = $this->getMockBuilder(Worksheet::class)
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->mockWorksheet->expects($this->any())
|
||||
->method('getHighestColumn')
|
||||
->will($this->returnValue('E'));
|
||||
}
|
||||
|
||||
public function testInstantiateRowDefault()
|
||||
{
|
||||
$row = new Row($this->mockWorksheet);
|
||||
self::assertInstanceOf(Row::class, $row);
|
||||
$rowIndex = $row->getRowIndex();
|
||||
self::assertEquals(1, $rowIndex);
|
||||
}
|
||||
|
||||
public function testInstantiateRowSpecified()
|
||||
{
|
||||
$row = new Row($this->mockWorksheet, 5);
|
||||
self::assertInstanceOf(Row::class, $row);
|
||||
$rowIndex = $row->getRowIndex();
|
||||
self::assertEquals(5, $rowIndex);
|
||||
}
|
||||
|
||||
public function testGetCellIterator()
|
||||
{
|
||||
$row = new Row($this->mockWorksheet);
|
||||
$cellIterator = $row->getCellIterator();
|
||||
self::assertInstanceOf(RowCellIterator::class, $cellIterator);
|
||||
}
|
||||
}
|
133
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php
vendored
Normal file
133
inc/vendor/phpoffice/phpspreadsheet/tests/PhpSpreadsheetTests/Worksheet/WorksheetTest.php
vendored
Normal file
@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Worksheet;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class WorksheetTest extends TestCase
|
||||
{
|
||||
public function testSetTitle()
|
||||
{
|
||||
$testTitle = str_repeat('a', 31);
|
||||
|
||||
$worksheet = new Worksheet();
|
||||
$worksheet->setTitle($testTitle);
|
||||
self::assertSame($testTitle, $worksheet->getTitle());
|
||||
}
|
||||
|
||||
public function setTitleInvalidProvider()
|
||||
{
|
||||
return [
|
||||
[str_repeat('a', 32), 'Maximum 31 characters allowed in sheet title.'],
|
||||
['invalid*title', 'Invalid character found in sheet title'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
* @param string $expectMessage
|
||||
* @dataProvider setTitleInvalidProvider
|
||||
*/
|
||||
public function testSetTitleInvalid($title, $expectMessage)
|
||||
{
|
||||
// First, test setting title with validation disabled -- should be successful
|
||||
$worksheet = new Worksheet();
|
||||
$worksheet->setTitle($title, true, false);
|
||||
|
||||
// Next, test again with validation enabled -- this time we should fail
|
||||
$worksheet = new Worksheet();
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage($expectMessage);
|
||||
$worksheet->setTitle($title);
|
||||
}
|
||||
|
||||
public function testSetTitleDuplicate()
|
||||
{
|
||||
// Create a Spreadsheet with three Worksheets (the first is created automatically)
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$spreadsheet->createSheet();
|
||||
$spreadsheet->createSheet();
|
||||
|
||||
// Set unique title -- should be unchanged
|
||||
$sheet = $spreadsheet->getSheet(0);
|
||||
$sheet->setTitle('Test Title');
|
||||
self::assertSame('Test Title', $sheet->getTitle());
|
||||
|
||||
// Set duplicate title -- should have numeric suffix appended
|
||||
$sheet = $spreadsheet->getSheet(1);
|
||||
$sheet->setTitle('Test Title');
|
||||
self::assertSame('Test Title 1', $sheet->getTitle());
|
||||
|
||||
// Set duplicate title with validation disabled -- should be unchanged
|
||||
$sheet = $spreadsheet->getSheet(2);
|
||||
$sheet->setTitle('Test Title', true, false);
|
||||
self::assertSame('Test Title', $sheet->getTitle());
|
||||
}
|
||||
|
||||
public function testSetCodeName()
|
||||
{
|
||||
$testCodeName = str_repeat('a', 31);
|
||||
|
||||
$worksheet = new Worksheet();
|
||||
$worksheet->setCodeName($testCodeName);
|
||||
self::assertSame($testCodeName, $worksheet->getCodeName());
|
||||
}
|
||||
|
||||
public function setCodeNameInvalidProvider()
|
||||
{
|
||||
return [
|
||||
[str_repeat('a', 32), 'Maximum 31 characters allowed in sheet code name.'],
|
||||
['invalid*code*name', 'Invalid character found in sheet code name'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $codeName
|
||||
* @param string $expectMessage
|
||||
* @dataProvider setCodeNameInvalidProvider
|
||||
*/
|
||||
public function testSetCodeNameInvalid($codeName, $expectMessage)
|
||||
{
|
||||
// First, test setting code name with validation disabled -- should be successful
|
||||
$worksheet = new Worksheet();
|
||||
$worksheet->setCodeName($codeName, false);
|
||||
|
||||
// Next, test again with validation enabled -- this time we should fail
|
||||
$worksheet = new Worksheet();
|
||||
$this->expectException(\Exception::class);
|
||||
$this->expectExceptionMessage($expectMessage);
|
||||
$worksheet->setCodeName($codeName);
|
||||
}
|
||||
|
||||
public function testSetCodeNameDuplicate()
|
||||
{
|
||||
// Create a Spreadsheet with three Worksheets (the first is created automatically)
|
||||
$spreadsheet = new Spreadsheet();
|
||||
$spreadsheet->createSheet();
|
||||
$spreadsheet->createSheet();
|
||||
|
||||
// Set unique code name -- should be massaged to Snake_Case
|
||||
$sheet = $spreadsheet->getSheet(0);
|
||||
$sheet->setCodeName('Test Code Name');
|
||||
self::assertSame('Test_Code_Name', $sheet->getCodeName());
|
||||
|
||||
// Set duplicate code name -- should be massaged and have numeric suffix appended
|
||||
$sheet = $spreadsheet->getSheet(1);
|
||||
$sheet->setCodeName('Test Code Name');
|
||||
self::assertSame('Test_Code_Name_1', $sheet->getCodeName());
|
||||
|
||||
// Set duplicate code name with validation disabled -- should be unchanged, and unmassaged
|
||||
$sheet = $spreadsheet->getSheet(2);
|
||||
$sheet->setCodeName('Test Code Name', false);
|
||||
self::assertSame('Test Code Name', $sheet->getCodeName());
|
||||
}
|
||||
|
||||
public function testFreezePaneSelectedCell()
|
||||
{
|
||||
$worksheet = new Worksheet();
|
||||
$worksheet->freezePane('B2');
|
||||
self::assertSame('B2', $worksheet->getTopLeftCell());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user