-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSessionCest.php
More file actions
107 lines (92 loc) · 3.27 KB
/
Copy pathSessionCest.php
File metadata and controls
107 lines (92 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
namespace App\Tests\Functional;
use App\Entity\User;
use App\Tests\Support\FunctionalTester;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Http\Authenticator\Token\PostAuthenticationToken;
final class SessionCest
{
public function amLoggedInAs(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
$I->seeAuthentication();
/** @var TokenStorageInterface $tokenStorage */
$tokenStorage = $I->grabService('security.token_storage');
$I->assertNotNull($tokenStorage->getToken());
$I->see('You are in the Dashboard!');
}
public function amLoggedInWithToken(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$token = new PostAuthenticationToken($user, 'main', $user->getRoles());
$I->amLoggedInWithToken($token);
$I->amOnPage('/dashboard');
$I->seeAuthentication();
/** @var TokenStorageInterface $tokenStorage */
$tokenStorage = $I->grabService('security.token_storage');
$I->assertNotNull($tokenStorage->getToken());
$I->see('You are in the Dashboard!');
}
public function dontSeeInSession(FunctionalTester $I)
{
$I->amOnPage('/');
$I->dontSeeInSession('_security_main');
}
public function goToLogoutPath(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
$I->see('You are in the Dashboard!');
$I->goToLogoutPath();
$I->seeCurrentRouteIs('index');
$I->dontSeeAuthentication();
}
public function logoutProgrammatically(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/dashboard');
$I->see('You are in the Dashboard!');
$I->logoutProgrammatically();
$I->amOnPage('/dashboard');
$I->seeInCurrentUrl('login');
$I->dontSeeAuthentication();
}
public function seeInSession(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
$I->seeInSession('_security_main');
}
public function seeSessionHasValues(FunctionalTester $I)
{
$user = $I->grabEntityFromRepository(User::class, [
'email' => 'john_doe@gmail.com',
]);
$I->amLoggedInAs($user);
$I->amOnPage('/');
$I->seeSessionHasValues(['_security_main', '_security_main']);
}
public function assertSessionHasFlashMessage(FunctionalTester $I): void
{
$I->stopFollowingRedirects();
$I->amOnPage('/flash');
$I->assertSessionHasFlashMessage('success');
$I->assertSessionHasFlashMessage('success', 'Welcome back!');
}
}