Sheet Visibility Tests

This commit is contained in:
alexisparron 2017-07-05 16:49:34 +02:00
parent 0eae4b27c3
commit 78d7b307c6
3 changed files with 60 additions and 0 deletions

View File

@ -51,4 +51,17 @@ class SheetTest extends \PHPUnit_Framework_TestCase
return $sheets; 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());
}
} }

View File

@ -52,6 +52,7 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$this->assertSheetNameEquals($customSheetName, $fileName, "The sheet name should have been changed to '$customSheetName'"); $this->assertSheetNameEquals($customSheetName, $fileName, "The sheet name should have been changed to '$customSheetName'");
} }
/** /**
* @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException * @expectedException \Box\Spout\Writer\Exception\InvalidSheetNameException
* @return void * @return void
@ -75,6 +76,18 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$sheet->setName($customSheetName); $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 $fileName
* @param string $sheetName * @param string $sheetName
@ -117,6 +130,25 @@ class SheetTest extends \PHPUnit_Framework_TestCase
return $writer->getSheets(); 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 $expectedName
* @param string $fileName * @param string $fileName
@ -131,4 +163,19 @@ class SheetTest extends \PHPUnit_Framework_TestCase
$this->assertContains("<sheet name=\"$expectedName\"", $xmlContents, $message); $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);
}
} }