JpegResponseTest::testDefaultParameters()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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