-
Notifications
You must be signed in to change notification settings - Fork 63
/
Copy pathAuthCest.php
67 lines (49 loc) · 1.59 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
62
63
64
65
66
67
<?php
use App\User;
use Illuminate\Support\Facades\Hash;
use Page\Functional\PostsPage;
class AuthCest
{
private $userAttributes;
public function _before()
{
$this->userAttributes = [
'email' => '[email protected]',
'password' => Hash::make('password'),
'created_at' => new DateTime(),
'updated_at' => new DateTime(),
];
}
public function loginUsingUserRecord(FunctionalTester $I)
{
$I->amLoggedAs(User::create($this->userAttributes));
$I->amOnPage(PostsPage::$url);
$I->seeCurrentUrlEquals(PostsPage::$url);
$I->seeAuthentication();
// Login should persist between requests
$I->amOnPage(PostsPage::$url);
$I->seeAuthentication();
}
public function loginUsingCredentials(FunctionalTester $I)
{
$I->haveRecord('users', $this->userAttributes);
$I->amLoggedAs(['email' => '[email protected]', 'password' => 'password']);
$I->amOnPage(PostsPage::$url);
$I->seeCurrentUrlEquals(PostsPage::$url);
$I->seeAuthentication();
// Login should persist between requests
$I->amOnPage(PostsPage::$url);
$I->seeAuthentication();
}
public function secureRouteWithoutAuthenticatedUser(FunctionalTester $I)
{
$I->amOnPage('/secure');
$I->seeCurrentUrlEquals('/auth/login');
}
public function secureRouteWithAuthenticatedUser(FunctionalTester $I)
{
$I->amLoggedAs(User::create($this->userAttributes));
$I->amOnPage('/secure');
$I->see('Hello World');
}
}