-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Session: emulates session.cache_limiter & session.cache_expire
- Loading branch information
Showing
2 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
|
||
test(function () { | ||
$factory = new Nette\Http\RequestFactory; | ||
$response = new Nette\Http\Response; | ||
$session = new Nette\Http\Session($factory->fromGlobals(), $response); | ||
|
||
$session->setOptions([ | ||
'cache_limiter' => 'public', | ||
'cache_expire' => '180', | ||
]); | ||
$session->start(); | ||
|
||
Assert::same( | ||
[ | ||
'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], | ||
'Expires' => [Nette\Http\Helpers::formatDate(time() + 180 * 60)], | ||
'Cache-Control' => ['public, max-age=10800'], | ||
'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], | ||
], | ||
$response->getHeaders() | ||
); | ||
|
||
$session->close(); | ||
}); | ||
|
||
|
||
test(function () { | ||
$factory = new Nette\Http\RequestFactory; | ||
$response = new Nette\Http\Response; | ||
$session = new Nette\Http\Session($factory->fromGlobals(), $response); | ||
|
||
$session->setOptions([ | ||
'cache_limiter' => 'private_no_expire', | ||
'cache_expire' => '180', | ||
]); | ||
$session->start(); | ||
|
||
Assert::same( | ||
[ | ||
'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], | ||
'Cache-Control' => ['private, max-age=10800'], | ||
'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], | ||
], | ||
$response->getHeaders() | ||
); | ||
|
||
$session->close(); | ||
}); | ||
|
||
|
||
test(function () { | ||
$factory = new Nette\Http\RequestFactory; | ||
$response = new Nette\Http\Response; | ||
$session = new Nette\Http\Session($factory->fromGlobals(), $response); | ||
|
||
$session->setOptions([ | ||
'cache_limiter' => 'private', | ||
'cache_expire' => '180', | ||
]); | ||
$session->start(); | ||
|
||
Assert::same( | ||
[ | ||
'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], | ||
'Expires' => ['Mon, 23 Jan 1978 10:00:00 GMT'], | ||
'Cache-Control' => ['private, max-age=10800'], | ||
'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], | ||
], | ||
$response->getHeaders() | ||
); | ||
|
||
$session->close(); | ||
}); | ||
|
||
|
||
test(function () { | ||
$factory = new Nette\Http\RequestFactory; | ||
$response = new Nette\Http\Response; | ||
$session = new Nette\Http\Session($factory->fromGlobals(), $response); | ||
|
||
$session->setOptions([ | ||
'cache_limiter' => 'nocache', | ||
]); | ||
$session->start(); | ||
|
||
Assert::same( | ||
[ | ||
'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], | ||
'Expires' => ['Mon, 23 Jan 1978 10:00:00 GMT'], | ||
'Cache-Control' => ['no-store, no-cache, must-revalidate'], | ||
'Pragma' => ['no-cache'], | ||
], | ||
$response->getHeaders() | ||
); | ||
|
||
$session->close(); | ||
}); |