|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\BannerServer\Tests\Unit\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
10
|
|
|
use WMDE\BannerServer\Controller\DonationFinishedController; |
|
11
|
|
|
use PHPUnit\Framework\TestCase; |
|
12
|
|
|
|
|
13
|
|
|
class DonationFinishedControllerTest extends TestCase { |
|
14
|
|
|
|
|
15
|
|
|
public function test_given_no_category_then_no_cookie_is_set(): void { |
|
16
|
|
|
$controller = new DonationFinishedController( 'P1D' ); |
|
17
|
|
|
|
|
18
|
|
|
$response = $controller->index( new Request() ); |
|
19
|
|
|
|
|
20
|
|
|
$this->assertEmpty( $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
21
|
|
|
$this->assertNotSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function test_given_invalid_category_then_no_cookie_is_set(): void { |
|
25
|
|
|
$controller = new DonationFinishedController( 'P1D' ); |
|
26
|
|
|
|
|
27
|
|
|
$response = $controller->index( new Request( ['c' => ':break-my-yaml!'] ) ); |
|
28
|
|
|
|
|
29
|
|
|
$this->assertEmpty( $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
30
|
|
|
$this->assertNotSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function test_given_a_category_then_category_cookie_is_set(): void { |
|
34
|
|
|
$controller = new DonationFinishedController( 'P180D' ); |
|
35
|
|
|
|
|
36
|
|
|
$response = $controller->index( new Request( ['c' => 'fundraising,fundraising_next'] ) ); |
|
37
|
|
|
|
|
38
|
|
|
$this->assertSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
39
|
|
|
$firstCookie = $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT )[0]; |
|
40
|
|
|
$expectedDate =( new \DateTime() )->add( new \DateInterval( 'P180D' ) ); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertSame( 'fundraising,fundraising_next', $firstCookie->getValue() ); |
|
43
|
|
|
$this->assertEqualsWithDelta( $expectedDate->getTimestamp(), $firstCookie->getExpiresTime(), 5 ); |
|
44
|
|
|
$this->assertSame( 'text/html', $response->headers->get( 'content-type', '' ) ); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function test_given_image_content_type_zero_byte_image_is_returned(): void { |
|
48
|
|
|
$controller = new DonationFinishedController( 'P180D' ); |
|
49
|
|
|
|
|
50
|
|
|
$request = new Request( ['c' => 'fundraising,fundraising_next'] ); |
|
51
|
|
|
$request->headers->set( 'accept', 'image/gif,image/png,image/*' ); |
|
52
|
|
|
$response = $controller->index( $request ); |
|
53
|
|
|
|
|
54
|
|
|
$this->assertSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
55
|
|
|
$this->assertNotEmpty( $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
56
|
|
|
$this->assertSame( 'image/png', $response->headers->get( 'content-type', '' ) ); |
|
57
|
|
|
$this->assertSame( 0, strlen( $response->getContent() ) ); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|