|
1
|
|
|
<?php |
|
2
|
|
|
namespace OnurbTest\Bundle\ExcelBundle\Controller; |
|
3
|
|
|
|
|
4
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
5
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
6
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
7
|
|
|
|
|
8
|
|
|
class FakeControllerTest extends WebTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testStreamAction() |
|
11
|
|
|
{ |
|
12
|
|
|
$client = static::createClient(); |
|
13
|
|
|
$client->request(Request::METHOD_GET, '/fake/stream'); |
|
14
|
|
|
$client->getResponse()->sendContent(); |
|
15
|
|
|
$content = ob_get_contents(); |
|
16
|
|
|
ob_clean(); |
|
17
|
|
|
$this->assertEquals( |
|
18
|
|
|
Response::HTTP_OK, |
|
19
|
|
|
$client->getResponse()->getStatusCode(), |
|
20
|
|
|
$client->getResponse()->getContent() |
|
21
|
|
|
); |
|
22
|
|
|
$this->assertStringStartsWith( |
|
23
|
|
|
'attachment;filename=', |
|
24
|
|
|
$client->getResponse()->headers->get('content-disposition') |
|
25
|
|
|
); |
|
26
|
|
|
$this->assertNotEmpty($content, 'Response should not be empty'); |
|
27
|
|
|
$this->assertNotNull($content, 'Response should not be null'); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testSaveAction() |
|
31
|
|
|
{ |
|
32
|
|
|
$client = static::createClient(); |
|
33
|
|
|
$client->request(Request::METHOD_GET, '/fake/store'); |
|
34
|
|
|
$this->assertEquals( |
|
35
|
|
|
Response::HTTP_CREATED, |
|
36
|
|
|
$client->getResponse()->getStatusCode(), |
|
37
|
|
|
$client->getResponse()->getContent() |
|
38
|
|
|
); |
|
39
|
|
|
$content = $client->getResponse()->getContent(); |
|
40
|
|
|
$this->assertStringEndsWith('.xls', $content); |
|
41
|
|
|
$this->assertFileExists($content, sprintf('file %s should exist', $content)); |
|
42
|
|
|
|
|
43
|
|
|
$this->cleanFile($content); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function testSaveWithDrawingAction() |
|
47
|
|
|
{ |
|
48
|
|
|
$client = static::createClient(); |
|
49
|
|
|
$client->request(Request::METHOD_GET, '/fake/drawing'); |
|
50
|
|
|
$this->assertEquals( |
|
51
|
|
|
Response::HTTP_CREATED, |
|
52
|
|
|
$client->getResponse()->getStatusCode(), |
|
53
|
|
|
$client->getResponse()->getContent() |
|
54
|
|
|
); |
|
55
|
|
|
$content = $client->getResponse()->getContent(); |
|
56
|
|
|
$this->assertStringEndsWith('.xls', $content); |
|
57
|
|
|
$this->assertFileExists($content, sprintf('file %s should exist', $content)); |
|
58
|
|
|
|
|
59
|
|
|
$this->cleanFile($content); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testReaderAction() |
|
63
|
|
|
{ |
|
64
|
|
|
$client = static::createClient(); |
|
65
|
|
|
$client->request(Request::METHOD_GET, '/fake/reader'); |
|
66
|
|
|
$client->getResponse()->sendContent(); |
|
67
|
|
|
$content = ob_get_contents(); |
|
68
|
|
|
ob_clean(); |
|
69
|
|
|
$this->assertEquals( |
|
70
|
|
|
Response::HTTP_OK, |
|
71
|
|
|
$client->getResponse()->getStatusCode(), |
|
72
|
|
|
$client->getResponse()->getContent() |
|
73
|
|
|
); |
|
74
|
|
|
$this->assertEquals('Hello world!', $client->getResponse()->getContent()); |
|
75
|
|
|
$this->assertNotEmpty($content, 'Response should not be empty'); |
|
76
|
|
|
$this->assertNotNull($content, 'Response should not be null'); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
public function testReadAndSaveAction() |
|
80
|
|
|
{ |
|
81
|
|
|
$client = static::createClient(); |
|
82
|
|
|
$client->request(Request::METHOD_GET, '/fake/read'); |
|
83
|
|
|
$this->assertEquals( |
|
84
|
|
|
Response::HTTP_CREATED, |
|
85
|
|
|
$client->getResponse()->getStatusCode(), |
|
86
|
|
|
$client->getResponse()->getContent() |
|
87
|
|
|
); |
|
88
|
|
|
$content = $client->getResponse()->getContent(); |
|
89
|
|
|
$this->assertStringEndsWith('.xls', $content); |
|
90
|
|
|
$this->assertFileExists($content, sprintf('file %s should exist', $content)); |
|
91
|
|
|
|
|
92
|
|
|
$this->cleanFile($content); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
|
|
96
|
|
|
private function cleanFile($file) |
|
97
|
|
|
{ |
|
98
|
|
|
if (file_exists($file)) { |
|
99
|
|
|
unlink($file); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
|