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

XlsxTwigTest::formatProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace MewesK\TwigExcelBundle\Tests\Twig;
4
5
/**
6
 * Class XlsxTwigTest
7
 * @package MewesK\TwigExcelBundle\Tests\Twig
8
 */
9
class XlsxTwigTest extends AbstractTwigTest
10
{
11
    protected static $TEMP_PATH = '/../../tmp/xlsx/';
12
13
    //
14
    // PhpUnit
15
    //
16
17
    /**
18
     * @return array
19
     */
20
    public function formatProvider()
21
    {
22
        return [['xlsx']];
23
    }
24
25
    //
26
    // Tests
27
    //
28
29
30
    /**
31
     * @param string $format
32
     * @throws \Exception
33
     *
34
     * @dataProvider formatProvider
35
     */
36
    public function testCellProperties($format)
37
    {
38
        $document = $this->getDocument('cellProperties', $format);
39
        $sheet = $document->getSheetByName('Test');
40
        $cell = $sheet->getCell('A1');
41
        $dataValidation = $cell->getDataValidation();
42
43
        static::assertTrue($dataValidation->getAllowBlank(), 'Unexpected value in allowBlank');
44
        static::assertEquals('Test error', $dataValidation->getError(), 'Unexpected value in error');
45
        static::assertEquals('information', $dataValidation->getErrorStyle(), 'Unexpected value in errorStyle');
46
        static::assertEquals('Test errorTitle', $dataValidation->getErrorTitle(), 'Unexpected value in errorTitle');
47
        static::assertEquals('', $dataValidation->getFormula1(), 'Unexpected value in formula1');
48
        static::assertEquals('', $dataValidation->getFormula2(), 'Unexpected value in formula2');
49
        static::assertEquals('', $dataValidation->getOperator(), 'Unexpected value in operator');
50
        static::assertEquals('Test prompt', $dataValidation->getPrompt(), 'Unexpected value in prompt');
51
        static::assertEquals('Test promptTitle', $dataValidation->getPromptTitle(), 'Unexpected value in promptTitle');
52
        static::assertTrue($dataValidation->getShowDropDown(), 'Unexpected value in showDropDown');
53
        static::assertTrue($dataValidation->getShowErrorMessage(), 'Unexpected value in showErrorMessage');
54
        static::assertTrue($dataValidation->getShowInputMessage(), 'Unexpected value in showInputMessage');
55
        static::assertEquals('custom', $dataValidation->getType(), 'Unexpected value in type');
56
    }
57
58
    /**
59
     * The following attributes are not supported by the readers and therefore cannot be tested:
60
     * $security->getLockRevision() -> true
61
     * $security->getLockStructure() -> true
62
     * $security->getLockWindows() -> true
63
     * $security->getRevisionsPassword() -> 'test'
64
     * $security->getWorkbookPassword() -> 'test'
65
     *
66
     * @param string $format
67
     * @throws \Exception
68
     *
69
     * @dataProvider formatProvider
70
     */
71
    public function testDocumentProperties($format)
72
    {
73
        $document = $this->getDocument('documentProperties', $format);
74
        $properties = $document->getProperties();
75
76
        static::assertEquals('Test company', $properties->getCompany(), 'Unexpected value in company');
77
        static::assertEquals('Test manager', $properties->getManager(), 'Unexpected value in manager');
78
    }
79
80
    /**
81
     * @param string $format
82
     * @throws \Exception
83
     *
84
     * @dataProvider formatProvider
85
     */
86
    public function testDocumentTemplate($format)
87
    {
88
        $document = $this->getDocument('documentTemplateAdvanced', $format);
89
        static::assertNotNull($document, 'Document does not exist');
90
91
        $sheet = $document->getSheet(0);
92
        static::assertNotNull($sheet, 'Sheet does not exist');
93
94
        static::assertEquals('Hello2', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1');
95
        static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1');
96
        static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2');
97
        static::assertEquals('Bar2', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2');
98
99
        static::assertTrue($sheet->getCell('A1')->getStyle()->getFont()->getBold(), 'Unexpected value in bold');
100
        static::assertTrue($sheet->getCell('B1')->getStyle()->getFont()->getItalic(), 'Unexpected value in italic');
101
        static::assertEquals('single', $sheet->getCell('A2')->getStyle()->getFont()->getUnderline(), 'Unexpected value in underline');
102
        static::assertEquals('FFFF3333', $sheet->getCell('B2')->getStyle()->getFont()->getColor()->getARGB(), 'Unexpected value in color');
103
104
        $headerFooter = $sheet->getHeaderFooter();
105
        static::assertNotNull($headerFooter, 'HeaderFooter does not exist');
106
        static::assertContains('Left area header', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
107
        static::assertContains('12Center area header', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
108
        static::assertContains('12Right area header', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
109
        static::assertContains('Left area footer', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
110
        static::assertContains('12Center area footer', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
111
        static::assertContains('12Right area footer', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
112
113
        $drawings = $sheet->getDrawingCollection();
114
        static::assertCount(1, $drawings, 'Not enough drawings exist');
115
116
        $drawing = $drawings[0];
117
        static::assertEquals(196, $drawing->getWidth(), 'Unexpected value in width');
118
        static::assertEquals(187, $drawing->getHeight(), 'Unexpected value in height');
119
    }
120
121
    /**
122
     * @param string $format
123
     * @throws \Exception
124
     *
125
     * @dataProvider formatProvider
126
     */
127
    public function testDrawingProperties($format)
128
    {
129
        $document = $this->getDocument('drawingProperties', $format);
130
        static::assertNotNull($document, 'Document does not exist');
131
132
        $sheet = $document->getSheetByName('Test');
133
        static::assertNotNull($sheet, 'Sheet does not exist');
134
135
        $drawings = $sheet->getDrawingCollection();
136
        static::assertCount(1, $drawings, 'Not enough drawings exist');
137
138
        $drawing = $drawings[0];
139
        static::assertEquals('Test Description', $drawing->getDescription(), 'Unexpected value in description');
140
        static::assertEquals('Test Name', $drawing->getName(), 'Unexpected value in name');
141
        static::assertEquals(30, $drawing->getOffsetX(), 'Unexpected value in offsetX');
142
        static::assertEquals(20, $drawing->getOffsetY(), 'Unexpected value in offsetY');
143
        static::assertEquals(45, $drawing->getRotation(), 'Unexpected value in rotation');
144
145
        $shadow = $drawing->getShadow();
146
        static::assertEquals('ctr', $shadow->getAlignment(), 'Unexpected value in alignment');
147
        static::assertEquals(100, $shadow->getAlpha(), 'Unexpected value in alpha');
148
        static::assertEquals(11, $shadow->getBlurRadius(), 'Unexpected value in blurRadius');
149
        static::assertEquals('0000cc', $shadow->getColor()->getRGB(), 'Unexpected value in color');
150
        static::assertEquals(30, $shadow->getDirection(), 'Unexpected value in direction');
151
        static::assertEquals(4, $shadow->getDistance(), 'Unexpected value in distance');
152
        static::assertTrue($shadow->getVisible(), 'Unexpected value in visible');
153
    }
154
155
    /**
156
     * @param string $format
157
     * @throws \Exception
158
     *
159
     * @dataProvider formatProvider
160
     */
161
    public function testHeaderFooterComplex($format)
162
    {
163
        $document = $this->getDocument('headerFooterComplex', $format);
164
        static::assertNotNull($document, 'Document does not exist');
165
166
        $sheet = $document->getSheetByName('Test');
167
        static::assertNotNull($sheet, 'Sheet does not exist');
168
169
        $headerFooter = $sheet->getHeaderFooter();
170
        static::assertNotNull($headerFooter, 'HeaderFooter does not exist');
171
        static::assertEquals('&LfirstHeader left&CfirstHeader center&RfirstHeader right', 
172
            $headerFooter->getFirstHeader(),
173
            'Unexpected value in firstHeader');
174
        static::assertEquals('&LevenHeader left&CevenHeader center&RevenHeader right',
175
            $headerFooter->getEvenHeader(),
176
            'Unexpected value in evenHeader');
177
        static::assertEquals('&LfirstFooter left&CfirstFooter center&RfirstFooter right',
178
            $headerFooter->getFirstFooter(),
179
            'Unexpected value in firstFooter');
180
        static::assertEquals('&LevenFooter left&CevenFooter center&RevenFooter right',
181
            $headerFooter->getEvenFooter(),
182
            'Unexpected value in evenFooter');
183
    }
184
185
    /**
186
     * @param string $format
187
     * @throws \Exception
188
     *
189
     * @dataProvider formatProvider
190
     */
191
    public function testHeaderFooterDrawing($format)
192
    {
193
        $document = $this->getDocument('headerFooterDrawing', $format);
194
        static::assertNotNull($document, 'Document does not exist');
195
196
        $sheet = $document->getSheetByName('Test');
197
        static::assertNotNull($sheet, 'Sheet does not exist');
198
199
        $headerFooter = $sheet->getHeaderFooter();
200
        static::assertNotNull($headerFooter, 'HeaderFooter does not exist');
201
        static::assertEquals('&L&G&CHeader', $headerFooter->getFirstHeader(), 'Unexpected value in firstHeader');
202
        static::assertEquals('&L&G&CHeader', $headerFooter->getEvenHeader(), 'Unexpected value in evenHeader');
203
        static::assertEquals('&L&G&CHeader', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
204
        static::assertEquals('&LFooter&R&G', $headerFooter->getFirstFooter(), 'Unexpected value in firstFooter');
205
        static::assertEquals('&LFooter&R&G', $headerFooter->getEvenFooter(), 'Unexpected value in evenFooter');
206
        static::assertEquals('&LFooter&R&G', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
207
208
        $drawings = $headerFooter->getImages();
209
        static::assertCount(2, $drawings, 'Sheet has not exactly 2 drawings');
210
        static::assertArrayHasKey('LH', $drawings, 'Header drawing does not exist');
211
        static::assertArrayHasKey('RF', $drawings, 'Footer drawing does not exist');
212
213
        $drawing = $drawings['LH'];
214
        static::assertNotNull($drawing, 'Header drawing is null');
215
        static::assertEquals(40, $drawing->getWidth(), 'Unexpected value in width');
216
        static::assertEquals(40, $drawing->getHeight(), 'Unexpected value in height');
217
218
        $drawing = $drawings['RF'];
219
        static::assertNotNull($drawing, 'Footer drawing is null');
220
        static::assertEquals(20, $drawing->getWidth(), 'Unexpected value in width');
221
        static::assertEquals(20, $drawing->getHeight(), 'Unexpected value in height');
222
    }
223
224
    /**
225
     * @param string $format
226
     * @throws \Exception
227
     *
228
     * @dataProvider formatProvider
229
     */
230
    public function testHeaderFooterProperties($format)
231
    {
232
        $document = $this->getDocument('headerFooterProperties', $format);
233
        static::assertNotNull($document, 'Document does not exist');
234
235
        $sheet = $document->getSheetByName('Test');
236
        static::assertNotNull($sheet, 'Sheet does not exist');
237
238
        $headerFooter = $sheet->getHeaderFooter();
239
        static::assertNotNull($headerFooter, 'HeaderFooter does not exist');
240
241
        static::assertEquals('&CHeader', $headerFooter->getFirstHeader(), 'Unexpected value in firstHeader');
242
        static::assertEquals('&CHeader', $headerFooter->getEvenHeader(), 'Unexpected value in evenHeader');
243
        static::assertEquals('&CHeader', $headerFooter->getOddHeader(), 'Unexpected value in oddHeader');
244
        static::assertEquals('&CFooter', $headerFooter->getFirstFooter(), 'Unexpected value in firstFooter');
245
        static::assertEquals('&CFooter', $headerFooter->getEvenFooter(), 'Unexpected value in evenFooter');
246
        static::assertEquals('&CFooter', $headerFooter->getOddFooter(), 'Unexpected value in oddFooter');
247
248
        static::assertFalse($headerFooter->getAlignWithMargins(), 'Unexpected value in alignWithMargins');
249
        static::assertFalse($headerFooter->getScaleWithDocument(), 'Unexpected value in scaleWithDocument');
250
    }
251
}
252