1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MewesK\TwigExcelBundle\Tests\Functional; |
4
|
|
|
|
5
|
|
|
use Symfony\Component\HttpFoundation\Response; |
6
|
|
|
use Twig_Error_Runtime; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Class DefaultControllerTest |
10
|
|
|
* @package MewesK\TwigExcelBundle\Tests\Functional |
11
|
|
|
*/ |
12
|
|
|
class DefaultControllerTest extends AbstractControllerTest |
13
|
|
|
{ |
14
|
|
|
// |
15
|
|
|
// PhpUnit |
16
|
|
|
// |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @return array |
20
|
|
|
*/ |
21
|
|
|
public function formatProvider() |
22
|
|
|
{ |
23
|
|
|
return [['ods'], ['xls'], ['xlsx']]; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
// |
27
|
|
|
// Tests |
28
|
|
|
// |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param string $format |
32
|
|
|
* |
33
|
|
|
* @throws \PHPExcel_Exception |
34
|
|
|
* |
35
|
|
|
* @dataProvider formatProvider |
36
|
|
|
*/ |
37
|
|
|
public function testSimple($format) |
38
|
|
|
{ |
39
|
|
|
try { |
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
|
|
|
} catch (Twig_Error_Runtime $e) { |
52
|
|
|
static::fail($e->getMessage()); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param string $format |
58
|
|
|
* |
59
|
|
|
* @throws \PHPExcel_Exception |
60
|
|
|
* |
61
|
|
|
* @dataProvider formatProvider |
62
|
|
|
*/ |
63
|
|
|
public function testCustomResponse($format) |
64
|
|
|
{ |
65
|
|
|
try { |
66
|
|
|
// Generate URI |
67
|
|
|
$uri = static::$router->generate('test_custom_response', ['templateName' => 'simple', '_format' => $format]); |
68
|
|
|
|
69
|
|
|
// Generate source |
70
|
|
|
static::$client->request('GET', $uri); |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @var $response Response |
74
|
|
|
*/ |
75
|
|
|
$response = static::$client->getResponse(); |
76
|
|
|
|
77
|
|
|
static::assertNotNull($response, 'Response does not exist'); |
78
|
|
|
static::assertEquals('attachment; filename="foobar.bin"', $response->headers->get('content-disposition'), 'Unexpected or missing header "Content-Disposition"'); |
79
|
|
|
static::assertEquals('max-age=600, private', $response->headers->get('cache-control'), 'Unexpected or missing header "Cache-Control"'); |
80
|
|
|
} catch (Twig_Error_Runtime $e) { |
81
|
|
|
static::fail($e->getMessage()); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|