ODS writer

Added ODS writer
Refactored XLSX writer to abstract some pieces into an abstract multi-sheets writer
Created an abstract style helper
Moved shared components around
This commit is contained in:
Adrien Loison committed 2015-08-28 20:19:45 -07:00
1 parent a8f1fba854
commit 5949cb2442
39 files changed
+2924 -533

No files matched your search

@@ -0,0 +1,95 @@
<?php
namespace Box\Spout\Writer\Common\Helper;
/**
* Class CellHelperTest
*
* @package Box\Spout\Writer\Common\Helper
*/
class CellHelperTest extends \PHPUnit_Framework_TestCase
{
/**
* @return array
*/
public function dataProviderForTestGetCellIndexFromColumnIndex()
{
return [
[0, 'A'],
[1, 'B'],
[25, 'Z'],
[26, 'AA'],
[28, 'AC'],
];
}
/**
* @dataProvider dataProviderForTestGetCellIndexFromColumnIndex
*
* @param int $columnIndex
* @param string $expectedCellIndex
* @return void
*/
public function testGetCellIndexFromColumnIndex($columnIndex, $expectedCellIndex)
{
$this->assertEquals($expectedCellIndex, CellHelper::getCellIndexFromColumnIndex($columnIndex));
}
/**
* @return array
*/
public function testIsNonEmptyString()
{
$this->assertTrue(CellHelper::isNonEmptyString("string"));
$this->assertFalse(CellHelper::isNonEmptyString(""));
$this->assertFalse(CellHelper::isNonEmptyString(0));
$this->assertFalse(CellHelper::isNonEmptyString(1));
$this->assertFalse(CellHelper::isNonEmptyString(true));
$this->assertFalse(CellHelper::isNonEmptyString(false));
$this->assertFalse(CellHelper::isNonEmptyString(["string"]));
$this->assertFalse(CellHelper::isNonEmptyString(new \stdClass()));
$this->assertFalse(CellHelper::isNonEmptyString(null));
}
/**
* @return array
*/
public function testIsNumeric()
{
$this->assertTrue(CellHelper::isNumeric(0));
$this->assertTrue(CellHelper::isNumeric(10));
$this->assertTrue(CellHelper::isNumeric(10.1));
$this->assertTrue(CellHelper::isNumeric(10.10000000000000000000001));
$this->assertTrue(CellHelper::isNumeric(0x539));
$this->assertTrue(CellHelper::isNumeric(02471));
$this->assertTrue(CellHelper::isNumeric(0b10100111001));
$this->assertTrue(CellHelper::isNumeric(1337e0));
$this->assertFalse(CellHelper::isNumeric("0"));
$this->assertFalse(CellHelper::isNumeric("42"));
$this->assertFalse(CellHelper::isNumeric(true));
$this->assertFalse(CellHelper::isNumeric([2]));
$this->assertFalse(CellHelper::isNumeric(new \stdClass()));
$this->assertFalse(CellHelper::isNumeric(null));
}
/**
* @return array
*/
public function testIsBoolean()
{
$this->assertTrue(CellHelper::isBoolean(true));
$this->assertTrue(CellHelper::isBoolean(false));
$this->assertFalse(CellHelper::isBoolean(0));
$this->assertFalse(CellHelper::isBoolean(1));
$this->assertFalse(CellHelper::isBoolean("0"));
$this->assertFalse(CellHelper::isBoolean("1"));
$this->assertFalse(CellHelper::isBoolean("true"));
$this->assertFalse(CellHelper::isBoolean("false"));
$this->assertFalse(CellHelper::isBoolean([true]));
$this->assertFalse(CellHelper::isBoolean(new \stdClass()));
$this->assertFalse(CellHelper::isBoolean(null));
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace Box\Spout\Writer\Common;
/**
* Class SheetTest
*
* @package Box\Spout\Writer\Common
*/
class SheetTest extends \PHPUnit_Framework_TestCase
{
/**
* @return void
*/
public function testGetSheetName()
{
$sheets = [new Sheet(0), new Sheet(1)];
$this->assertEquals('Sheet1', $sheets[0]->getName(), 'Invalid name for the first sheet');
$this->assertEquals('Sheet2', $sheets[1]->getName(), 'Invalid name for the second sheet');
}
/**
* @return void
*/
public function testSetSheetNameShouldCreateSheetWithCustomName()
{
$customSheetName = 'CustomName';
$sheet = new Sheet(0);
$sheet->setName($customSheetName);
$this->assertEquals($customSheetName, $sheet->getName(), "The sheet name should have been changed to '$customSheetName'");
}
/**
* @return array
*/
public function dataProviderForInvalidSheetNames()
{
return [
[null],
[21],
[''],
['this title exceeds the 31 characters limit'],
['Illegal \\'],
['Illegal /'],
['Illegal ?'],
['Illegal *'],
['Illegal :'],
['Illegal ['],
['Illegal ]'],
['\'Illegal start'],
['Illegal end\''],
];
}
/**
* @dataProvider dataProviderForInvalidSheetNames
* @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException
*
* @param string $customSheetName
* @return void
*/
public function testSetSheetNameShouldThrowOnInvalidName($customSheetName)
{
(new Sheet(0))->setName($customSheetName);
}
/**
* @return void
*/
public function testSetSheetNameShouldNotThrowWhenSettingSameNameAsCurrentOne()
{
$customSheetName = 'Sheet name';
$sheet = new Sheet(0);
$sheet->setName($customSheetName);
$sheet->setName($customSheetName);
}
/**
* @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException
* @return void
*/
public function testSetSheetNameShouldThrowWhenNameIsAlreadyUsed()
{
$customSheetName = 'Sheet name';
$sheet = new Sheet(0);
$sheet->setName($customSheetName);
$sheet = new Sheet(1);
$sheet->setName($customSheetName);
}
}