|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare( strict_types = 1 ); |
|
4
|
|
|
|
|
5
|
|
|
namespace WMDE\BannerServer\Tests\Unit\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use DateInterval; |
|
8
|
|
|
use DateTime; |
|
9
|
|
|
use PHPUnit\Framework\Attributes\CoversClass; |
|
|
|
|
|
|
10
|
|
|
use PHPUnit\Framework\TestCase; |
|
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\ResponseHeaderBag; |
|
14
|
|
|
use WMDE\BannerServer\Controller\AbstractCookieController; |
|
15
|
|
|
use WMDE\BannerServer\Tests\Utils\TestCookieController; |
|
16
|
|
|
|
|
17
|
|
|
#[CoversClass( AbstractCookieController::class )] |
|
18
|
|
|
class CookieControllerTest extends TestCase { |
|
19
|
|
|
|
|
20
|
|
|
public function test_given_no_category_then_no_cookie_is_set(): void { |
|
21
|
|
|
$controller = new TestCookieController( 'P1D' ); |
|
22
|
|
|
|
|
23
|
|
|
$response = $controller->index( new Request() ); |
|
24
|
|
|
|
|
25
|
|
|
$this->assertCount( 0, $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
26
|
|
|
$this->assertNotSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function test_given_invalid_category_then_no_cookie_is_set(): void { |
|
30
|
|
|
$controller = new TestCookieController( 'P1D' ); |
|
31
|
|
|
|
|
32
|
|
|
$response = $controller->index( new Request( [ 'c' => ':break-my-yaml!' ] ) ); |
|
33
|
|
|
|
|
34
|
|
|
$this->assertCount( 0, $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
35
|
|
|
$this->assertNotSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
public function test_given_a_category_then_category_cookie_is_set(): void { |
|
39
|
|
|
$controller = new TestCookieController( 'P180D' ); |
|
40
|
|
|
|
|
41
|
|
|
$response = $controller->index( new Request( [ 'c' => 'fundraising,fundraising_next' ] ) ); |
|
42
|
|
|
|
|
43
|
|
|
$this->assertSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
44
|
|
|
$firstCookie = $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT )[0]; |
|
45
|
|
|
$expectedDate = ( new DateTime() )->add( new DateInterval( 'P180D' ) ); |
|
46
|
|
|
|
|
47
|
|
|
$this->assertSame( 'fundraising,fundraising_next', $firstCookie->getValue() ); |
|
48
|
|
|
$this->assertEqualsWithDelta( $expectedDate->getTimestamp(), $firstCookie->getExpiresTime(), 5 ); |
|
49
|
|
|
$this->assertSame( 'text/html', $response->headers->get( 'content-type', '' ) ); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function test_given_image_content_type_zero_byte_image_is_returned(): void { |
|
53
|
|
|
$controller = new TestCookieController( 'P180D' ); |
|
54
|
|
|
|
|
55
|
|
|
$request = new Request( [ 'c' => 'fundraising,fundraising_next' ] ); |
|
56
|
|
|
$request->headers->set( 'accept', 'image/gif,image/png,image/*' ); |
|
57
|
|
|
$response = $controller->index( $request ); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertSame( Response::HTTP_OK, $response->getStatusCode() ); |
|
60
|
|
|
$this->assertNotEmpty( $response->headers->getCookies( ResponseHeaderBag::COOKIES_FLAT ) ); |
|
61
|
|
|
$this->assertSame( 'image/png', $response->headers->get( 'content-type', '' ) ); |
|
62
|
|
|
$this->assertSame( '', $response->getContent() ); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths