Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
12 | class BasicTwigTest extends BaseTwigTest |
||
13 | { |
||
14 | protected static $TEMP_PATH = '/../../tmp/basic/'; |
||
15 | |||
16 | // |
||
17 | // PhpUnit |
||
18 | // |
||
19 | |||
20 | /** |
||
21 | * @return array |
||
22 | */ |
||
23 | public function formatProvider() |
||
24 | { |
||
25 | return [['ods'], ['xls'], ['xlsx']]; |
||
26 | } |
||
27 | |||
28 | // |
||
29 | // Tests |
||
30 | // |
||
31 | |||
32 | /** |
||
33 | * @param string $format |
||
34 | * |
||
35 | * @throws \Exception |
||
36 | * |
||
37 | * @dataProvider formatProvider |
||
38 | */ |
||
39 | public function testBlock($format) |
||
40 | { |
||
41 | $document = $this->getDocument('block', $format); |
||
42 | static::assertNotNull($document, 'Document does not exist'); |
||
43 | |||
44 | $sheet = $document->getSheetByName('Test'); |
||
45 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
46 | |||
47 | static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
48 | static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
49 | static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
50 | static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @param string $format |
||
55 | * |
||
56 | * @throws \Exception |
||
57 | * |
||
58 | * @dataProvider formatProvider |
||
59 | */ |
||
60 | public function testBlockOverrideCell($format) |
||
61 | { |
||
62 | $document = $this->getDocument('blockOverrideCell', $format); |
||
63 | static::assertNotNull($document, 'Document does not exist'); |
||
64 | |||
65 | $sheet = $document->getSheetByName('Test'); |
||
66 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
67 | |||
68 | static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
69 | static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
70 | static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
71 | static::assertEquals('Bar2', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @param string $format |
||
76 | * |
||
77 | * @throws \Exception |
||
78 | * |
||
79 | * @dataProvider formatProvider |
||
80 | */ |
||
81 | public function testBlockOverrideContent($format) |
||
82 | { |
||
83 | $document = $this->getDocument('blockOverrideContent', $format); |
||
84 | static::assertNotNull($document, 'Document does not exist'); |
||
85 | |||
86 | $sheet = $document->getSheetByName('Test'); |
||
87 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
88 | |||
89 | static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
90 | static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
91 | static::assertEquals('Foo2', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
92 | static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @param string $format |
||
97 | * |
||
98 | * @throws \Exception |
||
99 | * |
||
100 | * @dataProvider formatProvider |
||
101 | */ |
||
102 | public function testBlockOverrideRow($format) |
||
103 | { |
||
104 | $document = $this->getDocument('blockOverrideRow', $format); |
||
105 | static::assertNotNull($document, 'Document does not exist'); |
||
106 | |||
107 | $sheet = $document->getSheetByName('Test'); |
||
108 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
109 | |||
110 | static::assertEquals('Hello2', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
111 | static::assertEquals('World2', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
112 | static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
113 | static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @param string $format |
||
118 | * |
||
119 | * @throws \Exception |
||
120 | * |
||
121 | * @dataProvider formatProvider |
||
122 | */ |
||
123 | public function testBlockOverrideSheet($format) |
||
124 | { |
||
125 | $document = $this->getDocument('blockOverrideSheet', $format); |
||
126 | static::assertNotNull($document, 'Document does not exist'); |
||
127 | |||
128 | $sheet = $document->getSheetByName('Test2'); |
||
129 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
130 | |||
131 | static::assertEquals('Hello3', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
132 | static::assertEquals('World3', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
133 | static::assertNotEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
134 | static::assertNotEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @param string $format |
||
139 | * |
||
140 | * @throws \Exception |
||
141 | * |
||
142 | * @dataProvider formatProvider |
||
143 | */ |
||
144 | public function testCellFormula($format) |
||
145 | { |
||
146 | $document = $this->getDocument('cellFormula', $format); |
||
147 | static::assertNotNull($document, 'Document does not exist'); |
||
148 | |||
149 | $sheet = $document->getSheetByName('Test'); |
||
150 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
151 | |||
152 | static::assertEquals('=A1*B1+2', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
153 | static::assertTrue($sheet->getCell('A2')->isFormula(), 'Unexpected value in isFormula'); |
||
154 | static::assertEquals(1337, $sheet->getCell('A2')->getCalculatedValue(), 'Unexpected calculated value in A2'); |
||
155 | |||
156 | static::assertEquals('=SUM(A1:B1)', $sheet->getCell('A3')->getValue(), 'Unexpected value in A3'); |
||
157 | static::assertTrue($sheet->getCell('A3')->isFormula(), 'Unexpected value in isFormula'); |
||
158 | static::assertEquals(669.5, $sheet->getCell('A3')->getCalculatedValue(), 'Unexpected calculated value in A3'); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @param string $format |
||
163 | * |
||
164 | * @throws \Exception |
||
165 | * |
||
166 | * @dataProvider formatProvider |
||
167 | */ |
||
168 | public function testCellIndex($format) |
||
169 | { |
||
170 | $document = $this->getDocument('cellIndex', $format); |
||
171 | static::assertNotNull($document, 'Document does not exist'); |
||
172 | |||
173 | $sheet = $document->getSheetByName('Test'); |
||
174 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
175 | |||
176 | static::assertEquals('Foo', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
177 | static::assertEquals('Hello', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
178 | static::assertNotEquals('Bar', $sheet->getCell('C1')->getValue(), 'Unexpected value in C1'); |
||
179 | static::assertEquals('Lorem', $sheet->getCell('C1')->getValue(), 'Unexpected value in C1'); |
||
180 | static::assertEquals('Ipsum', $sheet->getCell('D1')->getValue(), 'Unexpected value in D1'); |
||
181 | static::assertEquals('World', $sheet->getCell('E1')->getValue(), 'Unexpected value in E1'); |
||
182 | |||
183 | static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A1'); |
||
184 | static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B1'); |
||
185 | static::assertEquals('Lorem', $sheet->getCell('C2')->getValue(), 'Unexpected value in C1'); |
||
186 | static::assertEquals('Ipsum', $sheet->getCell('D2')->getValue(), 'Unexpected value in D1'); |
||
187 | static::assertEquals('Hello', $sheet->getCell('E2')->getValue(), 'Unexpected value in E1'); |
||
188 | static::assertEquals('World', $sheet->getCell('F2')->getValue(), 'Unexpected value in F1'); |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * @param string $format |
||
193 | * |
||
194 | * @throws \Exception |
||
195 | * |
||
196 | * @dataProvider formatProvider |
||
197 | */ |
||
198 | public function testCellProperties($format) |
||
199 | { |
||
200 | $document = $this->getDocument('cellProperties', $format); |
||
201 | static::assertNotNull($document, 'Document does not exist'); |
||
202 | |||
203 | $sheet = $document->getSheetByName('Test'); |
||
204 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
205 | |||
206 | $cell = $sheet->getCell('A1'); |
||
207 | static::assertNotNull($cell, 'Cell does not exist'); |
||
208 | |||
209 | $dataValidation = $cell->getDataValidation(); |
||
210 | static::assertNotNull($dataValidation, 'DataValidation does not exist'); |
||
211 | |||
212 | $style = $cell->getStyle(); |
||
213 | static::assertNotNull($style, 'Style does not exist'); |
||
214 | |||
215 | static::assertEquals(42, $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
216 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('A2')->getDataType(), 'Unexpected value in dataType'); |
||
217 | |||
218 | static::assertEquals('42', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
219 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('B2')->getDataType(), 'Unexpected value in dataType'); |
||
220 | |||
221 | static::assertEquals(42, $sheet->getCell('C2')->getValue(), 'Unexpected value in C2'); |
||
222 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('C2')->getDataType(), 'Unexpected value in dataType'); |
||
223 | |||
224 | static::assertEquals('007', $sheet->getCell('A3')->getValue(), 'Unexpected value in A3'); |
||
225 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('A3')->getDataType(), 'Unexpected value in dataType'); |
||
226 | |||
227 | static::assertEquals('007', $sheet->getCell('B3')->getValue(), 'Unexpected value in B3'); |
||
228 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('B3')->getDataType(), 'Unexpected value in dataType'); |
||
229 | |||
230 | static::assertEquals(7, $sheet->getCell('C3')->getValue(), 'Unexpected value in C3'); |
||
231 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('C3')->getDataType(), 'Unexpected value in dataType'); |
||
232 | |||
233 | static::assertEquals(0.1337, $sheet->getCell('A4')->getValue(), 'Unexpected value in A4'); |
||
234 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('A4')->getDataType(), 'Unexpected value in dataType'); |
||
235 | |||
236 | static::assertEquals('0.13370', $sheet->getCell('B4')->getValue(), 'Unexpected value in B4'); |
||
237 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('B4')->getDataType(), 'Unexpected value in dataType'); |
||
238 | |||
239 | static::assertEquals(0.1337, $sheet->getCell('C4')->getValue(), 'Unexpected value in C4'); |
||
240 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('C4')->getDataType(), 'Unexpected value in dataType'); |
||
241 | } |
||
242 | |||
243 | /** |
||
244 | * @param string $format |
||
245 | * |
||
246 | * @throws \Exception |
||
247 | * |
||
248 | * @dataProvider formatProvider |
||
249 | */ |
||
250 | public function testCellValue($format) |
||
251 | { |
||
252 | $document = $this->getDocument('cellValue', $format); |
||
253 | static::assertNotNull($document, 'Document does not exist'); |
||
254 | |||
255 | $sheet = $document->getSheetByName('Test'); |
||
256 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
257 | |||
258 | static::assertEquals(667.5, $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
259 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('A1')->getDataType(), 'Unexpected value in dataType'); |
||
260 | |||
261 | static::assertEquals(2, $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
262 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('B1')->getDataType(), 'Unexpected value in dataType'); |
||
263 | |||
264 | static::assertEquals('007', $sheet->getCell('C1')->getValue(), 'Unexpected value in C1'); |
||
265 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('C1')->getDataType(), 'Unexpected value in dataType'); |
||
266 | |||
267 | static::assertEquals('foo', $sheet->getCell('D1')->getValue(), 'Unexpected value in D1'); |
||
268 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('D1')->getDataType(), 'Unexpected value in dataType'); |
||
269 | |||
270 | static::assertEquals(0.42, $sheet->getCell('E1')->getValue(), 'Unexpected value in E1'); |
||
271 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('E1')->getDataType(), 'Unexpected value in dataType'); |
||
272 | |||
273 | static::assertEquals(21, $sheet->getCell('F1')->getValue(), 'Unexpected value in F1'); |
||
274 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('F1')->getDataType(), 'Unexpected value in dataType'); |
||
275 | |||
276 | static::assertEquals(1.2, $sheet->getCell('G1')->getValue(), 'Unexpected value in G1'); |
||
277 | static::assertEquals(DataType::TYPE_NUMERIC, $sheet->getCell('G1')->getDataType(), 'Unexpected value in dataType'); |
||
278 | |||
279 | static::assertEquals('BAR', $sheet->getCell('H1')->getValue(), 'Unexpected value in H1'); |
||
280 | static::assertEquals(DataType::TYPE_STRING, $sheet->getCell('H1')->getDataType(), 'Unexpected value in dataType'); |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * The following attributes are not supported by the readers and therefore cannot be tested: |
||
285 | * $security->getLockRevision() -> true |
||
286 | * $security->getLockStructure() -> true |
||
287 | * $security->getLockWindows() -> true |
||
288 | * $security->getRevisionsPassword() -> 'test' |
||
289 | * $security->getWorkbookPassword() -> 'test'. |
||
290 | * |
||
291 | * @param string $format |
||
292 | * |
||
293 | * @throws \Exception |
||
294 | * |
||
295 | * @dataProvider formatProvider |
||
296 | */ |
||
297 | public function testDocumentProperties($format) |
||
298 | { |
||
299 | $document = $this->getDocument('documentProperties', $format); |
||
300 | static::assertNotNull($document, 'Document does not exist'); |
||
301 | |||
302 | $properties = $document->getProperties(); |
||
303 | static::assertNotNull($properties, 'Properties do not exist'); |
||
304 | |||
305 | // +/- 24h range to allow possible timezone differences (946684800) |
||
306 | static::assertGreaterThanOrEqual(946598400, $properties->getCreated(), 'Unexpected value in created'); |
||
307 | static::assertLessThanOrEqual(946771200, $properties->getCreated(), 'Unexpected value in created'); |
||
308 | static::assertEquals('Test creator', $properties->getCreator(), 'Unexpected value in creator'); |
||
309 | |||
310 | $defaultStyle = $document->getDefaultStyle(); |
||
311 | static::assertNotNull($defaultStyle, 'DefaultStyle does not exist'); |
||
312 | |||
313 | static::assertEquals('Test description', $properties->getDescription(), 'Unexpected value in description'); |
||
314 | // +/- 24h range to allow possible timezone differences (946684800) |
||
315 | static::assertGreaterThanOrEqual(946598400, $properties->getModified(), 'Unexpected value in modified'); |
||
316 | static::assertLessThanOrEqual(946771200, $properties->getModified(), 'Unexpected value in modified'); |
||
317 | |||
318 | $security = $document->getSecurity(); |
||
319 | static::assertNotNull($security, 'Security does not exist'); |
||
320 | |||
321 | static::assertEquals('Test subject', $properties->getSubject(), 'Unexpected value in subject'); |
||
322 | static::assertEquals('Test title', $properties->getTitle(), 'Unexpected value in title'); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * @param string $format |
||
327 | * |
||
328 | * @throws \Exception |
||
329 | * |
||
330 | * @dataProvider formatProvider |
||
331 | */ |
||
332 | public function testDocumentSimple($format) |
||
333 | { |
||
334 | $document = $this->getDocument('documentSimple', $format); |
||
335 | static::assertNotNull($document, 'Document does not exist'); |
||
336 | |||
337 | $sheet = $document->getSheetByName('Test'); |
||
338 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
339 | |||
340 | static::assertEquals('Foo', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
341 | static::assertEquals('Bar', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
342 | static::assertEquals('Hello', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
343 | static::assertEquals('World', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * @param string $format |
||
348 | * |
||
349 | * @throws \Exception |
||
350 | * |
||
351 | * @dataProvider formatProvider |
||
352 | */ |
||
353 | public function testDocumentTemplate($format) |
||
354 | { |
||
355 | $document = $this->getDocument('documentTemplate.'.$format, $format); |
||
356 | static::assertNotNull($document, 'Document does not exist'); |
||
357 | |||
358 | $sheet = $document->getSheet(0); |
||
359 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
360 | |||
361 | static::assertEquals('Hello2', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
362 | static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
363 | static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
364 | static::assertEquals('Bar2', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * @param string $format |
||
369 | * |
||
370 | * @throws \Exception |
||
371 | * |
||
372 | * @dataProvider formatProvider |
||
373 | */ |
||
374 | public function testDocumentWhitespace($format) |
||
375 | { |
||
376 | $document = $this->getDocument('documentWhitespace', $format); |
||
377 | static::assertNotNull($document, 'Document does not exist'); |
||
378 | |||
379 | $sheet = $document->getSheetByName('Test'); |
||
380 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
381 | |||
382 | static::assertEquals('Foo', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
383 | static::assertEquals('Bar', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
384 | static::assertEquals('Hello', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
385 | static::assertEquals('World', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
386 | } |
||
387 | |||
388 | /** |
||
389 | * @param string $format |
||
390 | * |
||
391 | * @throws \Exception |
||
392 | * |
||
393 | * @dataProvider formatProvider |
||
394 | */ |
||
395 | public function testInclude($format) |
||
396 | { |
||
397 | $document = $this->getDocument('include', $format); |
||
398 | static::assertNotNull($document, 'Document does not exist'); |
||
399 | |||
400 | $sheet = $document->getSheetByName('Test'); |
||
401 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
402 | |||
403 | static::assertEquals('Hello1', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
404 | static::assertEquals('World1', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
405 | static::assertEquals('Hello2', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
406 | static::assertEquals('World2', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
407 | |||
408 | $sheet = $document->getSheetByName('Test2'); |
||
409 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
410 | |||
411 | static::assertEquals('Hello3', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
412 | static::assertEquals('World3', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
413 | } |
||
414 | |||
415 | /** |
||
416 | * @param string $format |
||
417 | * |
||
418 | * @throws \Exception |
||
419 | * |
||
420 | * @dataProvider formatProvider |
||
421 | */ |
||
422 | public function testMacro($format) |
||
423 | { |
||
424 | $document = $this->getDocument('macro', $format); |
||
425 | static::assertNotNull($document, 'Document does not exist'); |
||
426 | |||
427 | $sheet = $document->getSheetByName('Test'); |
||
428 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
429 | |||
430 | static::assertEquals('Hello1', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
431 | static::assertEquals('World1', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
432 | static::assertEquals('Hello2', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
433 | static::assertEquals('World2', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
||
434 | |||
435 | $sheet = $document->getSheetByName('Test2'); |
||
436 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
437 | |||
438 | static::assertEquals('Hello3', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
439 | static::assertEquals('World3', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
440 | |||
441 | $sheet = $document->getSheetByName('Test3'); |
||
442 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
443 | |||
444 | static::assertEquals('Hello4', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
445 | static::assertEquals('World4', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
446 | } |
||
447 | |||
448 | /** |
||
449 | * @param string $format |
||
450 | * |
||
451 | * @throws \Exception |
||
452 | * |
||
453 | * @dataProvider formatProvider |
||
454 | */ |
||
455 | public function testRowIndex($format) |
||
456 | { |
||
457 | $document = $this->getDocument('rowIndex', $format); |
||
458 | static::assertNotNull($document, 'Document does not exist'); |
||
459 | |||
460 | $sheet = $document->getSheetByName('Test'); |
||
461 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
462 | |||
463 | static::assertEquals('Foo', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
464 | static::assertNotEquals('Bar', $sheet->getCell('A3')->getValue(), 'Unexpected value in A3'); |
||
465 | static::assertEquals('Lorem', $sheet->getCell('A3')->getValue(), 'Unexpected value in A3'); |
||
466 | static::assertEquals('Ipsum', $sheet->getCell('A4')->getValue(), 'Unexpected value in A4'); |
||
467 | static::assertEquals('Hello', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
||
468 | static::assertEquals('World', $sheet->getCell('A5')->getValue(), 'Unexpected value in A5'); |
||
469 | |||
470 | static::assertEquals('Foo', $sheet->getCell('A6')->getValue(), 'Unexpected value in A6'); |
||
471 | static::assertEquals('Bar', $sheet->getCell('A7')->getValue(), 'Unexpected value in A7'); |
||
472 | static::assertEquals('Lorem', $sheet->getCell('A8')->getValue(), 'Unexpected value in A8'); |
||
473 | static::assertEquals('Ipsum', $sheet->getCell('A9')->getValue(), 'Unexpected value in A9'); |
||
474 | static::assertEquals('Hello', $sheet->getCell('A10')->getValue(), 'Unexpected value in A10'); |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * @param string $format |
||
479 | * |
||
480 | * @throws \Exception |
||
481 | * |
||
482 | * @dataProvider formatProvider |
||
483 | */ |
||
484 | public function testSheetComplex($format) |
||
485 | { |
||
486 | $document = $this->getDocument('sheetComplex', $format); |
||
487 | static::assertNotNull($document, 'Document does not exist'); |
||
488 | |||
489 | $sheet = $document->getSheetByName('Test 1'); |
||
490 | static::assertNotNull($sheet, 'Sheet "Test 1" does not exist'); |
||
491 | static::assertEquals('Foo', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
492 | static::assertEquals('Bar', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
||
493 | |||
494 | $sheet = $document->getSheetByName('Test 2'); |
||
495 | static::assertNotNull($sheet, 'Sheet "Test 2" does not exist'); |
||
496 | static::assertEquals('Hello World', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
||
497 | } |
||
498 | |||
499 | /** |
||
500 | * The following attributes are not supported by the readers and therefore cannot be tested: |
||
501 | * $columnDimension->getAutoSize() -> false |
||
502 | * $columnDimension->getCollapsed() -> true |
||
503 | * $columnDimension->getColumnIndex() -> 1 |
||
504 | * $columnDimension->getVisible() -> false |
||
505 | * $defaultColumnDimension->getAutoSize() -> true |
||
506 | * $defaultColumnDimension->getCollapsed() -> false |
||
507 | * $defaultColumnDimension->getColumnIndex() -> 1 |
||
508 | * $defaultColumnDimension->getVisible() -> true |
||
509 | * $defaultRowDimension->getCollapsed() -> false |
||
510 | * $defaultRowDimension->getRowIndex() -> 1 |
||
511 | * $defaultRowDimension->getVisible() -> true |
||
512 | * $defaultRowDimension->getzeroHeight() -> false |
||
513 | * $rowDimension->getCollapsed() -> true |
||
514 | * $rowDimension->getRowIndex() -> 1 |
||
515 | * $rowDimension->getVisible() -> false |
||
516 | * $rowDimension->getzeroHeight() -> true |
||
517 | * $sheet->getShowGridlines() -> false. |
||
518 | * |
||
519 | * @param string $format |
||
520 | * |
||
521 | * @throws \Exception |
||
522 | * |
||
523 | * @dataProvider formatProvider |
||
524 | */ |
||
525 | public function testSheetProperties($format) |
||
526 | { |
||
527 | $document = $this->getDocument('sheetProperties', $format); |
||
528 | static::assertNotNull($document, 'Document does not exist'); |
||
529 | |||
530 | $sheet = $document->getSheetByName('Test'); |
||
531 | static::assertNotNull($sheet, 'Sheet does not exist'); |
||
532 | |||
533 | $defaultColumnDimension = $sheet->getDefaultColumnDimension(); |
||
534 | static::assertNotNull($defaultColumnDimension, 'DefaultColumnDimension does not exist'); |
||
535 | static::assertEquals(0, $defaultColumnDimension->getOutlineLevel(), 'Unexpected value in outlineLevel'); |
||
536 | static::assertEquals(-1, $defaultColumnDimension->getWidth(), 'Unexpected value in width'); |
||
537 | static::assertEquals(0, $defaultColumnDimension->getXfIndex(), 'Unexpected value in xfIndex'); |
||
538 | |||
539 | $columnDimension = $sheet->getColumnDimension('D'); |
||
540 | static::assertNotNull($columnDimension, 'ColumnDimension does not exist'); |
||
541 | static::assertEquals(0, $columnDimension->getXfIndex(), 'Unexpected value in xfIndex'); |
||
542 | |||
543 | $pageSetup = $sheet->getPageSetup(); |
||
544 | static::assertNotNull($pageSetup, 'PageSetup does not exist'); |
||
545 | static::assertEquals(1, $pageSetup->getFitToHeight(), 'Unexpected value in fitToHeight'); |
||
546 | static::assertFalse($pageSetup->getFitToPage(), 'Unexpected value in fitToPage'); |
||
547 | static::assertEquals(1, $pageSetup->getFitToWidth(), 'Unexpected value in fitToWidth'); |
||
548 | static::assertFalse($pageSetup->getHorizontalCentered(), 'Unexpected value in horizontalCentered'); |
||
549 | static::assertEquals(100, $pageSetup->getScale(), 'Unexpected value in scale'); |
||
550 | static::assertFalse($pageSetup->getVerticalCentered(), 'Unexpected value in verticalCentered'); |
||
551 | |||
552 | $defaultRowDimension = $sheet->getDefaultRowDimension(); |
||
553 | static::assertNotNull($defaultRowDimension, 'DefaultRowDimension does not exist'); |
||
554 | static::assertEquals(0, $defaultRowDimension->getOutlineLevel(), 'Unexpected value in outlineLevel'); |
||
555 | static::assertEquals(-1, $defaultRowDimension->getRowHeight(), 'Unexpected value in rowHeight'); |
||
556 | static::assertEquals(0, $defaultRowDimension->getXfIndex(), 'Unexpected value in xfIndex'); |
||
557 | } |
||
558 | } |
||
559 |