1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Reader\Gnumeric; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Reader\Gnumeric; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class PageSetupTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
private const MARGIN_PRECISION = 0.001; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @var Spreadsheet |
16
|
|
|
*/ |
17
|
|
|
private $spreadsheet; |
18
|
|
|
|
19
|
|
|
protected function setup(): void |
20
|
|
|
{ |
21
|
|
|
$filename = 'tests/data/Reader/Gnumeric/PageSetup.gnumeric'; |
22
|
|
|
$reader = new Gnumeric(); |
23
|
|
|
$this->spreadsheet = $reader->load($filename); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function testPageSetup(): void |
27
|
|
|
{ |
28
|
|
|
$assertions = $this->pageSetupAssertions(); |
29
|
|
|
|
30
|
|
|
foreach ($this->spreadsheet->getAllSheets() as $worksheet) { |
31
|
|
|
if (!array_key_exists($worksheet->getTitle(), $assertions)) { |
32
|
|
|
continue; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
$sheetAssertions = $assertions[$worksheet->getTitle()]; |
36
|
|
|
foreach ($sheetAssertions as $test => $expectedResult) { |
37
|
|
|
$testMethodName = 'get' . ucfirst($test); |
38
|
|
|
$actualResult = $worksheet->getPageSetup()->$testMethodName(); |
39
|
|
|
self::assertSame( |
40
|
|
|
$expectedResult, |
41
|
|
|
$actualResult, |
42
|
|
|
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test}" |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testPageMargins(): void |
49
|
|
|
{ |
50
|
|
|
$assertions = $this->pageMarginAssertions(); |
51
|
|
|
|
52
|
|
|
foreach ($this->spreadsheet->getAllSheets() as $worksheet) { |
53
|
|
|
if (!array_key_exists($worksheet->getTitle(), $assertions)) { |
54
|
|
|
continue; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$sheetAssertions = $assertions[$worksheet->getTitle()]; |
58
|
|
|
foreach ($sheetAssertions as $test => $expectedResult) { |
59
|
|
|
$testMethodName = 'get' . ucfirst($test); |
60
|
|
|
$actualResult = $worksheet->getPageMargins()->$testMethodName(); |
61
|
|
|
self::assertEqualsWithDelta( |
62
|
|
|
$expectedResult, |
63
|
|
|
$actualResult, |
64
|
|
|
self::MARGIN_PRECISION, |
65
|
|
|
"Failed assertion for Worksheet '{$worksheet->getTitle()}' {$test} margin" |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
private function pageSetupAssertions(): array |
72
|
|
|
{ |
73
|
|
|
return [ |
74
|
|
|
'Sheet1' => [ |
75
|
|
|
'orientation' => PageSetup::ORIENTATION_PORTRAIT, |
76
|
|
|
'scale' => 75, |
77
|
|
|
'horizontalCentered' => true, |
78
|
|
|
'verticalCentered' => false, |
79
|
|
|
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER, |
80
|
|
|
], |
81
|
|
|
'Sheet2' => [ |
82
|
|
|
'orientation' => PageSetup::ORIENTATION_LANDSCAPE, |
83
|
|
|
'scale' => 100, |
84
|
|
|
'horizontalCentered' => false, |
85
|
|
|
'verticalCentered' => true, |
86
|
|
|
'pageOrder' => PageSetup::PAGEORDER_OVER_THEN_DOWN, |
87
|
|
|
], |
88
|
|
|
'Sheet3' => [ |
89
|
|
|
'orientation' => PageSetup::ORIENTATION_PORTRAIT, |
90
|
|
|
'scale' => 90, |
91
|
|
|
'horizontalCentered' => true, |
92
|
|
|
'verticalCentered' => true, |
93
|
|
|
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER, |
94
|
|
|
], |
95
|
|
|
'Sheet4' => [ |
96
|
|
|
// Default Settings |
97
|
|
|
'orientation' => PageSetup::ORIENTATION_PORTRAIT, |
98
|
|
|
'scale' => 100, |
99
|
|
|
'horizontalCentered' => false, |
100
|
|
|
'verticalCentered' => false, |
101
|
|
|
'pageOrder' => PageSetup::PAGEORDER_DOWN_THEN_OVER, |
102
|
|
|
], |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
private function pageMarginAssertions(): array |
107
|
|
|
{ |
108
|
|
|
return [ |
109
|
|
|
'Sheet1' => [ |
110
|
|
|
// Here the values are in inches |
111
|
|
|
'top' => 0.315, |
112
|
|
|
'header' => 0.630, |
113
|
|
|
'left' => 0.512, |
114
|
|
|
'right' => 0.512, |
115
|
|
|
'bottom' => 0.315, |
116
|
|
|
'footer' => 0.433, |
117
|
|
|
], |
118
|
|
|
'Sheet2' => [ |
119
|
|
|
// Here the values are in inches |
120
|
|
|
'top' => 0.315, |
121
|
|
|
'header' => 0.433, |
122
|
|
|
'left' => 0.709, |
123
|
|
|
'right' => 0.709, |
124
|
|
|
'bottom' => 0.315, |
125
|
|
|
'footer' => 0.433, |
126
|
|
|
], |
127
|
|
|
'Sheet3' => [ |
128
|
|
|
// Here the values are in inches |
129
|
|
|
'top' => 0.512, |
130
|
|
|
'header' => 0.433, |
131
|
|
|
'left' => 0.709, |
132
|
|
|
'right' => 0.709, |
133
|
|
|
'bottom' => 0.512, |
134
|
|
|
'footer' => 0.433, |
135
|
|
|
], |
136
|
|
|
'Sheet4' => [ |
137
|
|
|
// Default Settings (in inches) |
138
|
|
|
'top' => 0.3, |
139
|
|
|
'header' => 0.45, |
140
|
|
|
'left' => 0.7, |
141
|
|
|
'right' => 0.7, |
142
|
|
|
'bottom' => 0.3, |
143
|
|
|
'footer' => 0.45, |
144
|
|
|
], |
145
|
|
|
]; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|