Completed
Pull Request — master (#260)
by Bogdan
12:39 queued 10:51
created

JpegResponseTest::testSetDifferentFileName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
namespace Knp\Bundle\SnappyBundle\Tests\Snappy\Response;
3
4
use Knp\Bundle\SnappyBundle\Snappy\Response\JpegResponse;
5
use PHPUnit\Framework\TestCase;
6
7
class JpegResponseTest extends TestCase
8
{
9
    public function testDefaultParameters()
10
    {
11
        $response = new JpegResponse('some_binary_output');
12
13
        $this->assertSame(200, $response->getStatusCode());
14
        $this->assertSame('some_binary_output', $response->getContent());
15
        $this->assertSame('image/jpg', $response->headers->get('Content-Type'));
16
        $this->assertSame('inline; filename=output.jpg', str_replace('"', '', $response->headers->get('Content-Disposition')));
17
    }
18
19
    public function testSetDifferentMimeType()
20
    {
21
        $response = new JpegResponse('some_binary_output', 'test.jpg', '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.jpg';
29
        $response = new JpegResponse('some_binary_output', $fileName);
30
        $fileNameFromDispositionRegex = '/.*filename=([^"]+)/';
31
32
        $this->assertSame(1, preg_match($fileNameFromDispositionRegex, str_replace('"', '', $response->headers->get('Content-Disposition')), $matches), 1);
33
34
        $this->assertSame($fileName, $matches[1]);
35
    }
36
}
37