-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathSectionTest.php
350 lines (287 loc) · 11.3 KB
/
SectionTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
<?php
/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/
namespace PhpOffice\PhpWordTests\Style;
use PhpOffice\PhpWord\SimpleType\VerticalJc;
use PhpOffice\PhpWord\Style\Section;
/**
* Test class for PhpOffice\PhpWord\Style\Section.
*
* @coversDefaultClass \PhpOffice\PhpWord\Element\Section
*
* @runTestsInSeparateProcesses
*/
class SectionTest extends \PHPUnit\Framework\TestCase
{
/**
* Executed before each method of the class.
*/
public function testSettingValue(): void
{
$oSettings = new Section();
self::assertEquals('portrait', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
self::assertEquals('A4', $oSettings->getPaperSize());
$oSettings->setSettingValue('orientation', 'landscape');
self::assertEquals('landscape', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
$iVal = mt_rand(1, 1000);
$oSettings->setSettingValue('borderSize', $iVal);
self::assertEquals([$iVal, $iVal, $iVal, $iVal], $oSettings->getBorderSize());
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
self::assertEquals($iVal, $oSettings->getBorderRightSize());
self::assertEquals($iVal, $oSettings->getBorderTopSize());
$oSettings->setSettingValue('borderColor', 'FF00AA');
self::assertEquals(['FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'], $oSettings->getBorderColor());
self::assertEquals('FF00AA', $oSettings->getBorderBottomColor());
self::assertEquals('FF00AA', $oSettings->getBorderLeftColor());
self::assertEquals('FF00AA', $oSettings->getBorderRightColor());
self::assertEquals('FF00AA', $oSettings->getBorderTopColor());
$iVal = mt_rand(1, 1000);
$oSettings->setSettingValue('headerHeight', $iVal);
self::assertEquals($iVal, $oSettings->getHeaderHeight());
$oSettings->setSettingValue('lineNumbering', []);
$oSettings->setSettingValue(
'lineNumbering',
[
'start' => 1,
'increment' => 1,
'distance' => 240,
'restart' => 'newPage',
]
);
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\LineNumbering', $oSettings->getLineNumbering());
$oSettings->setSettingValue('lineNumbering', null);
self::assertNull($oSettings->getLineNumbering());
}
/**
* Set/get margin.
*/
public function testMargin(): void
{
// Section Settings
$oSettings = new Section();
$iVal = mt_rand(1, 1000);
$oSettings->setMarginTop($iVal);
self::assertEquals($iVal, $oSettings->getMarginTop());
$iVal = mt_rand(1, 1000);
$oSettings->setMarginBottom($iVal);
self::assertEquals($iVal, $oSettings->getMarginBottom());
$iVal = mt_rand(1, 1000);
$oSettings->setMarginLeft($iVal);
self::assertEquals($iVal, $oSettings->getMarginLeft());
$iVal = mt_rand(1, 1000);
$oSettings->setMarginRight($iVal);
self::assertEquals($iVal, $oSettings->getMarginRight());
}
/**
* Set/get page width.
*/
public function testPageWidth(): void
{
// Section Settings
$oSettings = new Section();
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
$iVal = mt_rand(1, 1000);
$oSettings->setSettingValue('pageSizeW', $iVal);
self::assertEquals($iVal, $oSettings->getPageSizeW());
}
/**
* Set/get page height.
*/
public function testPageHeight(): void
{
// Section Settings
$oSettings = new Section();
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
$iVal = mt_rand(1, 1000);
$oSettings->setSettingValue('pageSizeH', $iVal);
self::assertEquals($iVal, $oSettings->getPageSizeH());
}
/**
* Set/get landscape orientation.
*/
public function testOrientationLandscape(): void
{
// Section Settings
$oSettings = new Section();
$oSettings->setLandscape();
self::assertEquals('landscape', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeH(), 0.000000001);
}
/**
* Set/get portrait orientation.
*/
public function testOrientationPortrait(): void
{
// Section Settings
$oSettings = new Section();
$oSettings->setPortrait();
self::assertEquals('portrait', $oSettings->getOrientation());
self::assertEqualsWithDelta(Section::DEFAULT_WIDTH, $oSettings->getPageSizeW(), 0.000000001);
self::assertEqualsWithDelta(Section::DEFAULT_HEIGHT, $oSettings->getPageSizeH(), 0.000000001);
}
/**
* Set/get border size.
*/
public function testBorderSize(): void
{
// Section Settings
$oSettings = new Section();
$iVal = mt_rand(1, 1000);
$oSettings->setBorderSize($iVal);
self::assertEquals([$iVal, $iVal, $iVal, $iVal], $oSettings->getBorderSize());
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
self::assertEquals($iVal, $oSettings->getBorderRightSize());
self::assertEquals($iVal, $oSettings->getBorderTopSize());
$iVal = mt_rand(1, 1000);
$oSettings->setBorderBottomSize($iVal);
self::assertEquals($iVal, $oSettings->getBorderBottomSize());
$iVal = mt_rand(1, 1000);
$oSettings->setBorderLeftSize($iVal);
self::assertEquals($iVal, $oSettings->getBorderLeftSize());
$iVal = mt_rand(1, 1000);
$oSettings->setBorderRightSize($iVal);
self::assertEquals($iVal, $oSettings->getBorderRightSize());
$iVal = mt_rand(1, 1000);
$oSettings->setBorderTopSize($iVal);
self::assertEquals($iVal, $oSettings->getBorderTopSize());
}
/**
* Set/get border color.
*/
public function testBorderColor(): void
{
// Section Settings
$oSettings = new Section();
$oSettings->setBorderColor('FF00AA');
self::assertEquals(['FF00AA', 'FF00AA', 'FF00AA', 'FF00AA'], $oSettings->getBorderColor());
self::assertEquals('FF00AA', $oSettings->getBorderBottomColor());
self::assertEquals('FF00AA', $oSettings->getBorderLeftColor());
self::assertEquals('FF00AA', $oSettings->getBorderRightColor());
self::assertEquals('FF00AA', $oSettings->getBorderTopColor());
$oSettings->setBorderBottomColor('BBCCDD');
self::assertEquals('BBCCDD', $oSettings->getBorderBottomColor());
$oSettings->setBorderLeftColor('CCDDEE');
self::assertEquals('CCDDEE', $oSettings->getBorderLeftColor());
$oSettings->setBorderRightColor('11EE22');
self::assertEquals('11EE22', $oSettings->getBorderRightColor());
$oSettings->setBorderTopColor('22FF33');
self::assertEquals('22FF33', $oSettings->getBorderTopColor());
}
/**
* Set/get page numbering start.
*/
public function testNumberingStart(): void
{
// Section Settings
$oSettings = new Section();
self::assertNull($oSettings->getPageNumberingStart());
$iVal = mt_rand(1, 1000);
$oSettings->setPageNumberingStart($iVal);
self::assertEquals($iVal, $oSettings->getPageNumberingStart());
$oSettings->setPageNumberingStart();
self::assertNull($oSettings->getPageNumberingStart());
}
/**
* Set/get header height.
*/
public function testHeader(): void
{
$oSettings = new Section();
self::assertEquals(720, $oSettings->getHeaderHeight());
$iVal = mt_rand(1, 1000);
$oSettings->setHeaderHeight($iVal);
self::assertEquals($iVal, $oSettings->getHeaderHeight());
$oSettings->setHeaderHeight();
self::assertEquals(720, $oSettings->getHeaderHeight());
}
/**
* Set/get footer height.
*/
public function testFooter(): void
{
// Section Settings
$oSettings = new Section();
self::assertEquals(720, $oSettings->getFooterHeight());
$iVal = mt_rand(1, 1000);
$oSettings->setFooterHeight($iVal);
self::assertEquals($iVal, $oSettings->getFooterHeight());
$oSettings->setFooterHeight();
self::assertEquals(720, $oSettings->getFooterHeight());
}
/**
* Set/get column number.
*/
public function testColumnsNum(): void
{
// Section Settings
$oSettings = new Section();
// Default
self::assertEquals(1, $oSettings->getColsNum());
// Null value
$oSettings->setColsNum();
self::assertEquals(1, $oSettings->getColsNum());
// Random value
$iVal = mt_rand(1, 1000);
$oSettings->setColsNum($iVal);
self::assertEquals($iVal, $oSettings->getColsNum());
}
/**
* Set/get column spacing.
*/
public function testColumnsSpace(): void
{
// Section Settings
$oSettings = new Section();
// Default
self::assertEquals(720, $oSettings->getColsSpace());
$iVal = mt_rand(1, 1000);
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace($iVal));
self::assertEquals($iVal, $oSettings->getColsSpace());
self::assertInstanceOf('PhpOffice\\PhpWord\\Style\\Section', $oSettings->setColsSpace());
self::assertEquals(720, $oSettings->getColsSpace());
}
/**
* Set/get break type.
*/
public function testBreakType(): void
{
// Section Settings
$oSettings = new Section();
self::assertNull($oSettings->getBreakType());
$oSettings->setBreakType('continuous');
self::assertEquals('continuous', $oSettings->getBreakType());
$oSettings->setBreakType();
self::assertNull($oSettings->getBreakType());
}
/**
* Vertical page alignment.
*/
public function testVerticalAlign(): void
{
// Section Settings
$oSettings = new Section();
self::assertNull($oSettings->getVAlign());
$oSettings->setVAlign(VerticalJc::BOTH);
self::assertEquals('both', $oSettings->getVAlign());
}
}