Passed
Push — master ( 02d42a...eb71ce )
by Albin
59s
created

PdfResponseTest::testSetDifferentFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
namespace Knp\Bundle\SnappyBundle\Tests\Snappy;
4
5
use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
6
7
class PdfResponseTest extends \PHPUnit_Framework_TestCase
8
{
9
    public function testDefaultParameters()
10
    {
11
        $response = new PdfResponse('some_binary_output');
12
13
        $this->assertSame(200, $response->getStatusCode());
14
        $this->assertSame('some_binary_output', $response->getContent());
15
        $this->assertSame('application/pdf', $response->headers->get('Content-Type'));
16
        $this->assertSame('attachment; filename="output.pdf"', $response->headers->get('Content-Disposition'));
17
    }
18
19
    public function testSetDifferentMimeType()
20
    {
21
        $response = new PdfResponse('some_binary_output', 'test.pdf', 'application/octet-stream');
22
23
        $this->assertSame('application/octet-stream', $response->headers->get('Content-Type'));
24
    }
25
26
    public function testSetDifferentFileName()
27
    {
28
        $fileName = 'test.pdf';
29
        $response = new PdfResponse('some_binary_output', $fileName);
30
        $fileNameFromDispositionRegex = '/.*filename="([^"]+)"/';
31
32
        $this->assertSame(1, preg_match($fileNameFromDispositionRegex, $response->headers->get('Content-Disposition'), $matches), 1);
33
34
        $this->assertSame($fileName, $matches[1]);
35
    }
36
}
37