Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a45c95f

Browse files
minor #44829 [HttpKernel] expand uninitialized session tests (xabbuh)
* commit '3d2fd7073e': expand uninitialized session tests
2 parents ed666d7 + 3d2fd70 commit a45c95f

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

src/Symfony/Component/HttpKernel/Tests/EventListener/SessionListenerTest.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function testResponseIsStillPublicIfSessionStartedAndHeaderPresent()
121121
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
122122
}
123123

124-
public function testUninitializedSession()
124+
public function testUninitializedSessionUsingInitializedSessionService()
125125
{
126126
$kernel = $this->createMock(HttpKernelInterface::class);
127127
$response = new Response();
@@ -142,6 +142,26 @@ public function testUninitializedSession()
142142
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
143143
}
144144

145+
public function testUninitializedSessionUsingSessionFromRequest()
146+
{
147+
$kernel = $this->createMock(HttpKernelInterface::class);
148+
$response = new Response();
149+
$response->setSharedMaxAge(60);
150+
$response->headers->set(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER, 'true');
151+
152+
$request = new Request();
153+
$request->setSession(new Session());
154+
155+
$listener = new SessionListener(new Container());
156+
$listener->onKernelResponse(new ResponseEvent($kernel, $request, HttpKernelInterface::MAIN_REQUEST, $response));
157+
$this->assertFalse($response->headers->has('Expires'));
158+
$this->assertTrue($response->headers->hasCacheControlDirective('public'));
159+
$this->assertFalse($response->headers->hasCacheControlDirective('private'));
160+
$this->assertFalse($response->headers->hasCacheControlDirective('must-revalidate'));
161+
$this->assertSame('60', $response->headers->getCacheControlDirective('s-maxage'));
162+
$this->assertFalse($response->headers->has(AbstractSessionListener::NO_AUTO_CACHE_CONTROL_HEADER));
163+
}
164+
145165
public function testUninitializedSessionWithoutInitializedSession()
146166
{
147167
$kernel = $this->createMock(HttpKernelInterface::class);

0 commit comments

Comments
 (0)