@@ 36-57 (lines=22) @@ | ||
33 | ); |
|
34 | } |
|
35 | ||
36 | public function testOnKernelRequest() |
|
37 | { |
|
38 | $request = new Request(); |
|
39 | $request->setMethod('HEAD'); |
|
40 | ||
41 | $requestMatcher = $this->getRequestMatcher($request, true); |
|
42 | $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'); |
|
43 | $hashGenerator->shouldReceive('generateHash')->andReturn('hash'); |
|
44 | ||
45 | $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash'); |
|
46 | $event = $this->getKernelRequestEvent($request); |
|
47 | ||
48 | $userContextSubscriber->onKernelRequest($event); |
|
49 | ||
50 | $response = $event->getResponse(); |
|
51 | ||
52 | $this->assertNotNull($response); |
|
53 | $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
54 | $this->assertEquals('hash', $response->headers->get('X-Hash')); |
|
55 | $this->assertNull($response->headers->get('Vary')); |
|
56 | $this->assertEquals('max-age=0, no-cache, private', $response->headers->get('Cache-Control')); |
|
57 | } |
|
58 | ||
59 | public function testOnKernelRequestNonMaster() |
|
60 | { |
|
@@ 76-97 (lines=22) @@ | ||
73 | $this->assertNull($event->getResponse()); |
|
74 | } |
|
75 | ||
76 | public function testOnKernelRequestCached() |
|
77 | { |
|
78 | $request = new Request(); |
|
79 | $request->setMethod('HEAD'); |
|
80 | ||
81 | $requestMatcher = $this->getRequestMatcher($request, true); |
|
82 | $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'); |
|
83 | $hashGenerator->shouldReceive('generateHash')->andReturn('hash'); |
|
84 | ||
85 | $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash', 30); |
|
86 | $event = $this->getKernelRequestEvent($request); |
|
87 | ||
88 | $userContextSubscriber->onKernelRequest($event); |
|
89 | ||
90 | $response = $event->getResponse(); |
|
91 | ||
92 | $this->assertNotNull($response); |
|
93 | $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response); |
|
94 | $this->assertEquals('hash', $response->headers->get('X-Hash')); |
|
95 | $this->assertEquals('X-SessionId', $response->headers->get('Vary')); |
|
96 | $this->assertEquals('max-age=30, public', $response->headers->get('Cache-Control')); |
|
97 | } |
|
98 | ||
99 | public function testOnKernelRequestNotMatched() |
|
100 | { |