mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-19 06:26:48 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
102 lines
3.4 KiB
PHP
102 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Ods;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Ods;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class PageSetupBug1772Test extends TestCase
|
|
{
|
|
private const MARGIN_PRECISION = 0.00000001;
|
|
|
|
public function testPageSetup(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/bug1772.ods';
|
|
$reader = new Ods();
|
|
$spreadsheet = $reader->load($filename);
|
|
$assertions = $this->pageSetupAssertions();
|
|
|
|
$sheetCount = 0;
|
|
foreach ($spreadsheet->getAllSheets() as $worksheet) {
|
|
++$sheetCount;
|
|
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
|
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
|
|
}
|
|
|
|
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
|
foreach ($sheetAssertions as $test => $expectedResult) {
|
|
$testMethodName = 'get' . ucfirst($test);
|
|
$actualResult = $worksheet->getPageSetup()->$testMethodName();
|
|
self::assertSame(
|
|
$expectedResult,
|
|
$actualResult,
|
|
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}"
|
|
);
|
|
}
|
|
}
|
|
self::assertCount($sheetCount, $assertions);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
public function testPageMargins(): void
|
|
{
|
|
$filename = 'tests/data/Reader/Ods/bug1772.ods';
|
|
$reader = new Ods();
|
|
$spreadsheet = $reader->load($filename);
|
|
$assertions = $this->pageMarginAssertions();
|
|
|
|
$sheetCount = 0;
|
|
foreach ($spreadsheet->getAllSheets() as $worksheet) {
|
|
++$sheetCount;
|
|
if (!array_key_exists($worksheet->getTitle(), $assertions)) {
|
|
self::fail('Unexpected worksheet ' . $worksheet->getTitle());
|
|
}
|
|
|
|
$sheetAssertions = $assertions[$worksheet->getTitle()];
|
|
foreach ($sheetAssertions as $test => $expectedResult) {
|
|
$testMethodName = 'get' . ucfirst($test);
|
|
$actualResult = $worksheet->getPageMargins()->$testMethodName();
|
|
self::assertEqualsWithDelta(
|
|
$expectedResult,
|
|
$actualResult,
|
|
self::MARGIN_PRECISION,
|
|
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin"
|
|
);
|
|
}
|
|
}
|
|
self::assertCount($sheetCount, $assertions);
|
|
$spreadsheet->disconnectWorksheets();
|
|
}
|
|
|
|
private function pageSetupAssertions(): array
|
|
{
|
|
return [
|
|
'Employee update template' => [
|
|
'orientation' => PageSetup::ORIENTATION_DEFAULT,
|
|
'scale' => 100,
|
|
'horizontalCentered' => false,
|
|
'verticalCentered' => false,
|
|
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER,
|
|
],
|
|
];
|
|
}
|
|
|
|
private function pageMarginAssertions(): array
|
|
{
|
|
return [
|
|
'Employee update template' => [
|
|
// Here the values are in cm
|
|
'top' => 0.0,
|
|
'header' => 0.2953,
|
|
'left' => 0.0,
|
|
'right' => 0.0,
|
|
'bottom' => 0.0,
|
|
'footer' => 0.2953,
|
|
],
|
|
];
|
|
}
|
|
}
|