1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MewesK\TwigSpreadsheetBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class BasicFunctionalTest. |
9
|
|
|
*/ |
10
|
|
|
class BasicFunctionalTest extends BaseFunctionalTest |
11
|
|
|
{ |
12
|
|
|
protected static $ENVIRONMENT = 'basic'; |
13
|
|
|
protected static $TEMP_PATH = __DIR__.'/../../var/cache/functional/basic'; |
14
|
|
|
|
15
|
|
|
// |
16
|
|
|
// PhpUnit |
17
|
|
|
// |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @return array |
21
|
|
|
*/ |
22
|
|
|
public function formatProvider() |
23
|
|
|
{ |
24
|
|
|
return [['ods'], ['xls'], ['xlsx']]; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
// |
28
|
|
|
// Tests |
29
|
|
|
// |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param string $format |
33
|
|
|
* |
34
|
|
|
* @throws \Exception |
35
|
|
|
* |
36
|
|
|
* @dataProvider formatProvider |
37
|
|
|
*/ |
38
|
|
View Code Duplication |
public function testSimple($format) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
$document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'simple', '_format' => $format]), $format); |
41
|
|
|
static::assertNotNull($document, 'Document does not exist'); |
42
|
|
|
|
43
|
|
|
$sheet = $document->getSheetByName('Test'); |
44
|
|
|
static::assertNotNull($sheet, 'Sheet does not exist'); |
45
|
|
|
|
46
|
|
|
static::assertEquals(100270, $sheet->getCell('B22')->getValue(), 'Unexpected value in B22'); |
47
|
|
|
|
48
|
|
|
static::assertEquals('=SUM(B2:B21)', $sheet->getCell('B23')->getValue(), 'Unexpected value in B23'); |
49
|
|
|
static::assertTrue($sheet->getCell('B23')->isFormula(), 'Unexpected value in isFormula'); |
50
|
|
|
static::assertEquals(100270, $sheet->getCell('B23')->getCalculatedValue(), 'Unexpected calculated value in B23'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @param string $format |
55
|
|
|
* |
56
|
|
|
* @throws \Exception |
57
|
|
|
* |
58
|
|
|
* @dataProvider formatProvider |
59
|
|
|
*/ |
60
|
|
|
public function testCustomResponse($format) |
61
|
|
|
{ |
62
|
|
|
// Generate URI |
63
|
|
|
$uri = static::$router->generate('test_custom_response', ['templateName' => 'simple', '_format' => $format]); |
64
|
|
|
|
65
|
|
|
// Generate source |
66
|
|
|
static::$client->request('GET', $uri); |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @var Response |
70
|
|
|
*/ |
71
|
|
|
$response = static::$client->getResponse(); |
72
|
|
|
|
73
|
|
|
static::assertNotNull($response, 'Response does not exist'); |
74
|
|
|
static::assertEquals('attachment; filename="foobar.bin"', $response->headers->get('Content-Disposition'), 'Unexpected or missing header "Content-Disposition"'); |
75
|
|
|
static::assertEquals(600, $response->getMaxAge(), 'Unexpected value in maxAge'); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $format |
80
|
|
|
* |
81
|
|
|
* @throws \Exception |
82
|
|
|
* |
83
|
|
|
* @dataProvider formatProvider |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function testDocumentTemplatePath1($format) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'documentTemplatePath1', '_format' => $format]), $format); |
88
|
|
|
static::assertNotNull($document, 'Document does not exist'); |
89
|
|
|
|
90
|
|
|
$sheet = $document->getSheet(0); |
91
|
|
|
static::assertNotNull($sheet, 'Sheet does not exist'); |
92
|
|
|
|
93
|
|
|
static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
94
|
|
|
static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
95
|
|
|
static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
96
|
|
|
static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param string $format |
101
|
|
|
* |
102
|
|
|
* @throws \Exception |
103
|
|
|
* |
104
|
|
|
* @dataProvider formatProvider |
105
|
|
|
*/ |
106
|
|
View Code Duplication |
public function testDocumentTemplatePath2($format) |
|
|
|
|
107
|
|
|
{ |
108
|
|
|
$document = $this->getDocument(static::$router->generate('test_default', ['templateName' => 'documentTemplatePath2', '_format' => $format]), $format); |
109
|
|
|
static::assertNotNull($document, 'Document does not exist'); |
110
|
|
|
|
111
|
|
|
$sheet = $document->getSheet(0); |
112
|
|
|
static::assertNotNull($sheet, 'Sheet does not exist'); |
113
|
|
|
|
114
|
|
|
static::assertEquals('Hello', $sheet->getCell('A1')->getValue(), 'Unexpected value in A1'); |
115
|
|
|
static::assertEquals('World', $sheet->getCell('B1')->getValue(), 'Unexpected value in B1'); |
116
|
|
|
static::assertEquals('Foo', $sheet->getCell('A2')->getValue(), 'Unexpected value in A2'); |
117
|
|
|
static::assertEquals('Bar', $sheet->getCell('B2')->getValue(), 'Unexpected value in B2'); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.