-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Daniel Kurowski
committed
Sep 30, 2022
1 parent
9a987d9
commit ba984f7
Showing
2 changed files
with
52 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,39 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Bridges\SecurityHttp\CookieStorage | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Nette\Bridges\SecurityHttp\CookieStorage; | ||
use Nette\Http\Request; | ||
use Nette\Http\Response; | ||
use Nette\Http\UrlScript; | ||
use Nette\Security\SimpleIdentity; | ||
use Nette\Utils\Random; | ||
use Tester\Assert; | ||
|
||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
$request = new Request(new UrlScript()); | ||
$response = new Response(); | ||
$storage = new CookieStorage($request, $response); | ||
|
||
$uid = Random::generate(15); | ||
|
||
// initially, there is nothing stored | ||
Assert::equal([false, null, null], $storage->getState()); | ||
|
||
// authenticate | ||
$storage->saveAuthentication(new SimpleIdentity($uid)); | ||
[$authenticated, $identity, $reason] = $storage->getState(); | ||
Assert::true($authenticated); | ||
Assert::equal($uid, $identity->getId()); | ||
Assert::null($reason); | ||
|
||
// clear authentication | ||
$storage->clearAuthentication(false); // clearIdentity parameter is ignored for cookie storage | ||
[$authenticated, $identity, $reason] = $storage->getState(); | ||
Assert::equal([false, null, null], $storage->getState()); |