|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +use Tester\Assert; |
| 6 | + |
| 7 | + |
| 8 | +require __DIR__ . '/../bootstrap.php'; |
| 9 | + |
| 10 | + |
| 11 | +test(function () { |
| 12 | + $factory = new Nette\Http\RequestFactory; |
| 13 | + $response = new Nette\Http\Response; |
| 14 | + $session = new Nette\Http\Session($factory->fromGlobals(), $response); |
| 15 | + |
| 16 | + $session->setOptions([ |
| 17 | + 'cache_limiter' => 'public', |
| 18 | + 'cache_expire' => '180', |
| 19 | + ]); |
| 20 | + $session->start(); |
| 21 | + |
| 22 | + Assert::same( |
| 23 | + [ |
| 24 | + 'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], |
| 25 | + 'Expires' => [Nette\Http\Helpers::formatDate(time() + 180 * 60)], |
| 26 | + 'Cache-Control' => ['public, max-age=10800'], |
| 27 | + 'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], |
| 28 | + ], |
| 29 | + $response->getHeaders() |
| 30 | + ); |
| 31 | + |
| 32 | + $session->close(); |
| 33 | +}); |
| 34 | + |
| 35 | + |
| 36 | +test(function () { |
| 37 | + $factory = new Nette\Http\RequestFactory; |
| 38 | + $response = new Nette\Http\Response; |
| 39 | + $session = new Nette\Http\Session($factory->fromGlobals(), $response); |
| 40 | + |
| 41 | + $session->setOptions([ |
| 42 | + 'cache_limiter' => 'private_no_expire', |
| 43 | + 'cache_expire' => '180', |
| 44 | + ]); |
| 45 | + $session->start(); |
| 46 | + |
| 47 | + Assert::same( |
| 48 | + [ |
| 49 | + 'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], |
| 50 | + 'Cache-Control' => ['private, max-age=10800'], |
| 51 | + 'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], |
| 52 | + ], |
| 53 | + $response->getHeaders() |
| 54 | + ); |
| 55 | + |
| 56 | + $session->close(); |
| 57 | +}); |
| 58 | + |
| 59 | + |
| 60 | +test(function () { |
| 61 | + $factory = new Nette\Http\RequestFactory; |
| 62 | + $response = new Nette\Http\Response; |
| 63 | + $session = new Nette\Http\Session($factory->fromGlobals(), $response); |
| 64 | + |
| 65 | + $session->setOptions([ |
| 66 | + 'cache_limiter' => 'private', |
| 67 | + 'cache_expire' => '180', |
| 68 | + ]); |
| 69 | + $session->start(); |
| 70 | + |
| 71 | + Assert::same( |
| 72 | + [ |
| 73 | + 'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], |
| 74 | + 'Expires' => ['Mon, 23 Jan 1978 10:00:00 GMT'], |
| 75 | + 'Cache-Control' => ['private, max-age=10800'], |
| 76 | + 'Last-Modified' => [Nette\Http\Helpers::formatDate(getlastmod())], |
| 77 | + ], |
| 78 | + $response->getHeaders() |
| 79 | + ); |
| 80 | + |
| 81 | + $session->close(); |
| 82 | +}); |
| 83 | + |
| 84 | + |
| 85 | +test(function () { |
| 86 | + $factory = new Nette\Http\RequestFactory; |
| 87 | + $response = new Nette\Http\Response; |
| 88 | + $session = new Nette\Http\Session($factory->fromGlobals(), $response); |
| 89 | + |
| 90 | + $session->setOptions([ |
| 91 | + 'cache_limiter' => 'nocache', |
| 92 | + ]); |
| 93 | + $session->start(); |
| 94 | + |
| 95 | + Assert::same( |
| 96 | + [ |
| 97 | + 'Set-Cookie' => ['PHPSESSID=' . $session->getId() . '; path=/; HttpOnly'], |
| 98 | + 'Expires' => ['Mon, 23 Jan 1978 10:00:00 GMT'], |
| 99 | + 'Cache-Control' => ['no-store, no-cache, must-revalidate'], |
| 100 | + 'Pragma' => ['no-cache'], |
| 101 | + ], |
| 102 | + $response->getHeaders() |
| 103 | + ); |
| 104 | + |
| 105 | + $session->close(); |
| 106 | +}); |
0 commit comments