Completed
Push — master ( e63334...a00c3a )
by Mewes
09:18
created

XlsTwigTest::testCellProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

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