-
Notifications
You must be signed in to change notification settings - Fork 41
/
LoginTest.php
65 lines (49 loc) · 1.75 KB
/
LoginTest.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
<?php
namespace MagicLink\Test\Actions;
use Illuminate\Support\Facades\Auth;
use MagicLink\Actions\LoginAction;
use MagicLink\MagicLink;
use MagicLink\Test\TestCase;
use MagicLink\Test\TestSupport\CustomAutenticable;
use MagicLink\Test\TestSupport\CustomUserProvider;
use MagicLink\Test\TestSupport\User;
class LoginTest extends TestCase
{
public function test_auth()
{
$magiclink = MagicLink::create(new LoginAction(User::first()));
$this->get($magiclink->url)
->assertStatus(302)
->assertRedirect('/');
$this->assertAuthenticatedAs(User::first());
}
public function test_auth_custom()
{
Auth::provider('custom_provider', function ($app, array $config) {
return new CustomUserProvider();
});
config()->set('auth.providers.custom', [
'driver' => 'custom_provider',
]);
config()->set('auth.guards.web.provider', 'custom');
$magiclink = MagicLink::create(new LoginAction(new CustomAutenticable('user_1')));
$this->get($magiclink->url)
->assertStatus(302)
->assertRedirect('/');
$this->assertAuthenticatedAs(new CustomAutenticable('user_1'));
}
public function test_auth_with_remember_me()
{
$action = new LoginAction(User::first());
$action->remember();
$magiclink = MagicLink::create($action);
$data = $this->get($magiclink->url)
->assertStatus(302)
->assertRedirect('/');
$cookieRememberMe = array_values(array_filter(
$data->headers->getCookies(),
fn ($cookie) => str_starts_with($cookie->getName(), 'remember_web_')
))[0] ?? null;
$this->assertNotNull($cookieRememberMe);
}
}