Sheet Visibility Tests
This commit is contained in:
parent
0eae4b27c3
commit
78d7b307c6
@ -51,4 +51,17 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
return $sheets;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReaderShouldReturnCorrectSheetVisibility()
|
||||
{
|
||||
|
||||
$sheets = $this->openFileAndReturnSheets('two_sheets_one_hidden_one_not.xlsx');
|
||||
|
||||
$this->assertFalse($sheets[0]->isVisible());
|
||||
|
||||
$this->assertTrue($sheets[1]->isVisible());
|
||||
}
|
||||
}
|
||||
|
@ -52,6 +52,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSheetNameEquals($customSheetName, $fileName, "The sheet name should have been changed to '$customSheetName'");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException
|
||||
* @return void
|
||||
@ -75,6 +76,18 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSheetVisibilityShouldCreateSheetHidden()
|
||||
{
|
||||
$fileName = 'test_set_visibility_should_create_sheet_hidden.xlsx';
|
||||
// $customSheetName = 'CustomName';
|
||||
$this->writeDataAndReturnSheetHidden($fileName);
|
||||
|
||||
$this->assertSheetVisibilityEquals(false, $fileName, "The sheet visibility should have been changed to 'false'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $sheetName
|
||||
@ -117,6 +130,25 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
return $writer->getSheets();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return Sheet
|
||||
*/
|
||||
private function writeDataAndReturnSheetHidden($fileName)
|
||||
{
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
$sheet = $writer->getCurrentSheet();
|
||||
$sheet->setIsVisible(false);
|
||||
|
||||
$writer->addRow(['xlsx--11', 'xlsx--12']);
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedName
|
||||
* @param string $fileName
|
||||
@ -131,4 +163,19 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertContains("<sheet name=\"$expectedName\"", $xmlContents, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedVisibility
|
||||
* @param string $fileName
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
private function assertSheetVisibilityEquals($expectedVisibility, $fileName, $message = '')
|
||||
{
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
$pathToWorkbookFile = $resourcePath . '#xl/workbook.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains(" state=\"hidden\"", $xmlContents, $message);
|
||||
}
|
||||
}
|
||||
|
BIN
tests/resources/xlsx/two_sheets_one_hidden_one_not.xlsx
Normal file
BIN
tests/resources/xlsx/two_sheets_one_hidden_one_not.xlsx
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user