1 parent
30366e6a5d
commit
3bb4fd3d48
14 files changed
+252
-112
No files matched your search
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace Box\Spout\Writer\Common\Entity;
|
||||
|
||||
use Box\Spout\Common\Helper\StringHelper;
|
||||
use Box\Spout\Writer\Common\Manager\SheetManager;
|
||||
|
||||
/**
|
||||
* Class SheetTest
|
||||
*
|
||||
* @package Box\Spout\Writer\Common\Entity
|
||||
*/
|
||||
class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var SheetManager */
|
||||
private $sheetManager;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$this->sheetManager = new SheetManager(new StringHelper());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $sheetIndex
|
||||
* @param int $associatedWorkbookId
|
||||
* @return Sheet
|
||||
*/
|
||||
private function createSheet($sheetIndex, $associatedWorkbookId)
|
||||
{
|
||||
return new Sheet($sheetIndex, $associatedWorkbookId, $this->sheetManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testGetSheetName()
|
||||
{
|
||||
$sheets = [$this->createSheet(0, 'workbookId1'), $this->createSheet(1, 'workbookId1')];
|
||||
|
||||
$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 = $this->createSheet(0, 'workbookId1');
|
||||
$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)
|
||||
{
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSheetNameShouldNotThrowWhenSettingSameNameAsCurrentOne()
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSheetNameShouldThrowWhenNameIsAlreadyUsed()
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = $this->createSheet(1, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSheetNameShouldNotThrowWhenSameNameUsedInDifferentWorkbooks()
|
||||
{
|
||||
$customSheetName = 'Sheet name';
|
||||
|
||||
$sheet = $this->createSheet(0, 'workbookId1');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = $this->createSheet(0, 'workbookId2');
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$sheet = $this->createSheet(1, 'workbookId3');
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user