Sheet visibility - ODS writer and reader
This commit is contained in:
1 parent
b9206fcb4b
commit
1c69dee9c9
11 files changed
+145
-19
No files matched your search
@@ -42,6 +42,17 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($sheets[1]->isActive());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testReaderShouldReturnCorrectSheetVisibility()
|
||||
{
|
||||
$sheets = $this->openFileAndReturnSheets('two_sheets_one_hidden_one_not.ods');
|
||||
|
||||
$this->assertFalse($sheets[0]->isVisible());
|
||||
$this->assertTrue($sheets[1]->isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return Sheet[]
|
||||
|
||||
@@ -78,6 +78,21 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
$sheet->setName($customSheetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetSheetVisibilityShouldCreateSheetHidden()
|
||||
{
|
||||
$fileName = 'test_set_visibility_should_create_sheet_hidden.xlsx';
|
||||
$this->writeDataToHiddenSheet($fileName);
|
||||
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
$pathToContentFile = $resourcePath . '#content.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToContentFile);
|
||||
|
||||
$this->assertContains(' table:display="false"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @param string $sheetName
|
||||
@@ -121,6 +136,26 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
return $writer->getSheets();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $fileName
|
||||
* @return void
|
||||
*/
|
||||
private function writeDataToHiddenSheet($fileName)
|
||||
{
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
/** @var \Box\Spout\Writer\ODS\Writer $writer */
|
||||
$writer = EntityFactory::createWriter(Type::ODS);
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
$sheet = $writer->getCurrentSheet();
|
||||
$sheet->setIsVisible(false);
|
||||
|
||||
$writer->addRow($this->createRowFromValues(['ods--11', 'ods--12']));
|
||||
$writer->close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedName
|
||||
* @param string $fileName
|
||||
|
||||
@@ -90,7 +90,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
|
||||
$pathToWorkbookFile = $resourcePath . '#xl/workbook.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains(" state=\"hidden\"", $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
$this->assertContains(' state="hidden"', $xmlContents, 'The sheet visibility should have been changed to "hidden"');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user