XlsTwigTest::formatProvider()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Tests\Twig;
4
5
/**
6
 * Class XlsTwigTest
7
 * @package MewesK\TwigExcelBundle\Tests\Twig
8
 */
9
class XlsTwigTest extends AbstractTwigTest
10
{
11
    protected static $TEMP_PATH = '/../../tmp/xls/';
12
13
    //
14
    // PhpUnit
15
    //
16
17
    /**
18
     * @return array
19
     */
20
    public function formatProvider()
21
    {
22
        return [['xls'], ['xlsx']];
23
    }
24
25
    //
26
    // Tests
27
    //
28
29
    /**
30
     * @param string $format
31
     * @throws \Exception
32
     *
33
     * @dataProvider formatProvider
34
     */
35
    public function testCellIndex($format)
36
    {
37
        $document = $this->getDocument('cellIndex', $format);
38
        static::assertNotNull($document, 'Document does not exist');
39
40
        $sheet = $document->getSheetByName('Test');
41
        static::assertNotNull($sheet, 'Sheet does not exist');
42
43
        static::assertEquals('A2:C2', $sheet->getCell('A2')->getMergeRange(), 'Unexpected value in mergeRange');
44
        static::assertEquals('A3:C3', $sheet->getCell('A3')->getMergeRange(), 'Unexpected value in mergeRange');
45
        static::assertEquals('A4:A6', $sheet->getCell('A4')->getMergeRange(), 'Unexpected value in mergeRange');
46
    }
47
48
    /**
49
     * @param string $format
50
     * @throws \Exception
51
     *
52
     * @dataProvider formatProvider
53
     */
54
    public function testCellProperties($format)
55
    {
56
        $document = $this->getDocument('cellProperties', $format);
57
        $sheet = $document->getSheetByName('Test');
58
        $cell = $sheet->getCell('A1');
59
        $style = $cell->getStyle();
60
61
        $breaks = $sheet->getBreaks();
62
        static::assertCount(1, $breaks, 'Unexpected break count');
63
        static::assertArrayHasKey('A1', $breaks, 'Break does not exist');
64
65
        $break = $breaks['A1'];
66
        static::assertNotNull($break, 'Break is null');
67
68
        $font = $style->getFont();
69
        static::assertNotNull($font, 'Font does not exist');
70
        static::assertEquals(18, $font->getSize(), 'Unexpected value in size');
71
72
        static::assertEquals('http://example.com/', $cell->getHyperlink()->getUrl(), 'Unexpected value in url');
73
    }
74
75
    /**
76
     * The following attributes are not supported by the readers and therefore cannot be tested:
77
     * $security->getLockRevision() -> true
78
     * $security->getLockStructure() -> true
79
     * $security->getLockWindows() -> true
80
     * $security->getRevisionsPassword() -> 'test'
81
     * $security->getWorkbookPassword() -> 'test'
82
     *
83
     * @param string $format
84
     * @throws \Exception
85
     *
86
     * @dataProvider formatProvider
87
     */
88
    public function testDocumentProperties($format)
89
    {
90
        $document = $this->getDocument('documentProperties', $format);
91
        $properties = $document->getProperties();
92
        $defaultStyle = $document->getDefaultStyle();
93
94
        static::assertEquals('Test category', $properties->getCategory(), 'Unexpected value in category');
95
96
        $font = $defaultStyle->getFont();
97
        static::assertNotNull($font, 'Font does not exist');
98
        static::assertEquals(18, $font->getSize(), 'Unexpected value in size');
99
100
        static::assertEquals('Test keywords', $properties->getKeywords(), 'Unexpected value in keywords');
101
        static::assertEquals('Test modifier', $properties->getLastModifiedBy(), 'Unexpected value in lastModifiedBy');
102
    }
103
104
    /**
105
     * @param string $format
106
     * @throws \Exception
107
     *
108
     * @dataProvider formatProvider
109
     */
110
    public function testDrawingProperties($format)
111
    {
112
        $document = $this->getDocument('drawingProperties', $format);
113
        static::assertNotNull($document, 'Document does not exist');
114
115
        $sheet = $document->getSheetByName('Test');
116
        static::assertNotNull($sheet, 'Sheet does not exist');
117
118
        $drawings = $sheet->getDrawingCollection();
119
        static::assertCount(1, $drawings, 'Unexpected drawing count');
120
        static::assertArrayHasKey(0, $drawings, 'Drawing does not exist');
121
122
        $drawing = $drawings[0];
123
        static::assertNotNull($drawing, 'Drawing is null');
124
125
        static::assertEquals('B2', $drawing->getCoordinates(), 'Unexpected value in coordinates');
126
        static::assertEquals(200, $drawing->getHeight(), 'Unexpected value in height');
127
        static::assertFalse($drawing->getResizeProportional(), 'Unexpected value in resizeProportional');
128
        static::assertEquals(300, $drawing->getWidth(), 'Unexpected value in width');
129
130
        $shadow = $drawing->getShadow();
131
        static::assertNotNull($shadow, 'Shadow is null');
132
    }
133
134
    /**
135
     * @param string $format
136
     * @throws \Exception
137
     *
138
     * @dataProvider formatProvider
139
     */
140
    public function testDrawingSimple($format)
141
    {
142
        $document = $this->getDocument('drawingSimple', $format);
143
        static::assertNotNull($document, 'Document does not exist');
144
145
        $sheet = $document->getSheetByName('Test');
146
        static::assertNotNull($sheet, 'Sheet does not exist');
147
148
        $drawings = $sheet->getDrawingCollection();
149
        static::assertCount(1, $drawings, 'Unexpected drawing count');
150
        static::assertArrayHasKey(0, $drawings, 'Drawing does not exist');
151
152
        $drawing = $drawings[0];
153
        static::assertNotNull($drawing, 'Drawing is null');
154
        static::assertEquals(100, $drawing->getWidth(), 'Unexpected value in width');
155
        static::assertEquals(100, $drawing->getHeight(), 'Unexpected value in height');
156
    }
157
158
    /**
159
     * @param string $format
160
     * @throws \Exception
161
     *
162
     * @dataProvider formatProvider
163
     */
164
    public function testHeaderFooterComplex($format)
165
    {
166
        $document = $this->getDocument('headerFooterComplex', $format);
167
        static::assertNotNull($document, 'Document does not exist');
168
169
        $sheet = $document->getSheetByName('Test');
170
        static::assertNotNull($sheet, 'Sheet does not exist');
171
172
        $headerFooter = $sheet->getHeaderFooter();
173
        static::assertNotNull($headerFooter, 'HeaderFooter does not exist');
174
175
        static::assertEquals('&LoddHeader left&CoddHeader center&RoddHeader right', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
176
        static::assertEquals('&LoddFooter left&CoddFooter center&RoddFooter right', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
177
    }
178
179
    /**
180
     * The following attributes are not supported by the readers and therefore cannot be tested:
181
     * $columnDimension->getAutoSize() -> false
182
     * $columnDimension->getCollapsed() -> true
183
     * $columnDimension->getColumnIndex() -> 1
184
     * $columnDimension->getVisible() -> false
185
     * $defaultColumnDimension->getAutoSize() -> true
186
     * $defaultColumnDimension->getCollapsed() -> false
187
     * $defaultColumnDimension->getColumnIndex() -> 1
188
     * $defaultColumnDimension->getVisible() -> true
189
     * $defaultRowDimension->getCollapsed() -> false
190
     * $defaultRowDimension->getRowIndex() -> 1
191
     * $defaultRowDimension->getVisible() -> true
192
     * $defaultRowDimension->getzeroHeight() -> false
193
     * $rowDimension->getCollapsed() -> true
194
     * $rowDimension->getRowIndex() -> 1
195
     * $rowDimension->getVisible() -> false
196
     * $rowDimension->getzeroHeight() -> true
197
     * $sheet->getShowGridlines() -> false
198
     *
199
     * @param string $format
200
     * @throws \Exception
201
     *
202
     * @dataProvider formatProvider
203
     */
204
    public function testSheetProperties($format)
205
    {
206
        $document = $this->getDocument('sheetProperties', $format);
207
        $sheet = $document->getSheetByName('Test');
208
        $columnDimension = $sheet->getColumnDimension('D');
209
        $pageSetup = $sheet->getPageSetup();
210
211
        static::assertEquals(1, $columnDimension->getOutlineLevel(), 'Unexpected value in outlineLevel');
212
        static::assertEquals(200, $columnDimension->getWidth(), 'Unexpected value in width');
213
214
        $pageMargins = $sheet->getPageMargins();
215
        static::assertNotNull($pageMargins, 'PageMargins does not exist');
216
        static::assertEquals(1, $pageMargins->getTop(), 'Unexpected value in top');
217
        static::assertEquals(1, $pageMargins->getBottom(), 'Unexpected value in bottom');
218
        static::assertEquals(0.75, $pageMargins->getLeft(), 'Unexpected value in left');
219
        static::assertEquals(0.75, $pageMargins->getRight(), 'Unexpected value in right');
220
        static::assertEquals(0.5, $pageMargins->getHeader(), 'Unexpected value in header');
221
        static::assertEquals(0.5, $pageMargins->getFooter(), 'Unexpected value in footer');
222
223
        static::assertEquals('landscape', $pageSetup->getOrientation(), 'Unexpected value in orientation');
224
        static::assertEquals(9, $pageSetup->getPaperSize(), 'Unexpected value in paperSize');
225
        static::assertEquals('A1:B1', $pageSetup->getPrintArea(), 'Unexpected value in printArea');
226
227
        $protection = $sheet->getProtection();
228
        static::assertTrue($protection->getAutoFilter(), 'Unexpected value in autoFilter');
229
        static::assertNotNull($protection, 'Protection does not exist');
230
        static::assertTrue($protection->getDeleteColumns(), 'Unexpected value in deleteColumns');
231
        static::assertTrue($protection->getDeleteRows(), 'Unexpected value in deleteRows');
232
        static::assertTrue($protection->getFormatCells(), 'Unexpected value in formatCells');
233
        static::assertTrue($protection->getFormatColumns(), 'Unexpected value in formatColumns');
234
        static::assertTrue($protection->getFormatRows(), 'Unexpected value in formatRows');
235
        static::assertTrue($protection->getInsertColumns(), 'Unexpected value in insertColumns');
236
        static::assertTrue($protection->getInsertHyperlinks(), 'Unexpected value in insertHyperlinks');
237
        static::assertTrue($protection->getInsertRows(), 'Unexpected value in insertRows');
238
        static::assertTrue($protection->getObjects(), 'Unexpected value in objects');
239
        static::assertEquals(\PHPExcel_Shared_PasswordHasher::hashPassword('testpassword'), $protection->getPassword(), 'Unexpected value in password');
240
        static::assertTrue($protection->getPivotTables(), 'Unexpected value in pivotTables');
241
        static::assertTrue($protection->getScenarios(), 'Unexpected value in scenarios');
242
        static::assertTrue($protection->getSelectLockedCells(), 'Unexpected value in selectLockedCells');
243
        static::assertTrue($protection->getSelectUnlockedCells(), 'Unexpected value in selectUnlockedCells');
244
        static::assertTrue($protection->getSheet(), 'Unexpected value in sheet');
245
        static::assertTrue($protection->getSort(), 'Unexpected value in sort');
246
247
        static::assertTrue($sheet->getPrintGridlines(), 'Unexpected value in printGridlines');
248
        static::assertTrue($sheet->getRightToLeft(), 'Unexpected value in rightToLeft');
249
        static::assertEquals('c0c0c0', strtolower($sheet->getTabColor()->getRGB()), 'Unexpected value in tabColor');
250
        static::assertEquals(75, $sheet->getSheetView()->getZoomScale(), 'Unexpected value in zoomScale');
251
252
        $rowDimension = $sheet->getRowDimension(2);
253
        static::assertNotNull($rowDimension, 'RowDimension does not exist');
254
        static::assertEquals(1, $rowDimension->getOutlineLevel(), 'Unexpected value in outlineLevel');
255
        static::assertEquals(30, $rowDimension->getRowHeight(), 'Unexpected value in rowHeight');
256
        static::assertEquals(0, $rowDimension->getXfIndex(), 'Unexpected value in xfIndex');
257
    }
258
}
259