-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathAuthCest.php
61 lines (47 loc) · 1.49 KB
/
AuthCest.php
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
<?php
class AuthCest
{
private $userAttributes;
public function __construct()
{
$this->userAttributes= [
'email' => 'john@doe.com',
'password' => Hash::make('password'),
'created_at' => new DateTime(),
'updated_at' => new DateTime(),
];
}
public function loginUsingUserRecord(FunctionalTester $I)
{
$I->dontSeeAuthentication();
$user = User::create($this->userAttributes);
$I->amLoggedAs($user);
$I->amOnPage(PostsPage::$url);
$I->seeCurrentUrlEquals(PostsPage::$url);
$I->seeAuthentication();
$I->logout();
$I->dontSeeAuthentication();
}
public function loginUsingCredentials(FunctionalTester $I)
{
$I->dontSeeAuthentication();
$I->haveRecord('users', $this->userAttributes);
$I->amLoggedAs(['email' => 'john@doe.com', 'password' => 'password']);
$I->amOnPage(PostsPage::$url);
$I->seeCurrentUrlEquals(PostsPage::$url);
$I->seeAuthentication();
$I->logout();
$I->dontSeeAuthentication();
}
public function requireAuthenticationForRoute(FunctionalTester $I)
{
$I->haveEnabledFilters();
$I->amOnPage('/secure');
$I->seeCurrentUrlEquals('/auth/login');
$I->see('Login');
$I->amLoggedAs(User::create($this->userAttributes));
$I->amOnPage('/secure');
$I->seeResponseCodeIs(200);
$I->see('Hello World');
}
}