GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 0dcb27...fb7903 )
by Mewes
11:26
created

XlsTwigTest::testDrawingProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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