-
Notifications
You must be signed in to change notification settings - Fork 310
/
Copy pathVerifyEmailControllerTest.php
100 lines (82 loc) · 3.17 KB
/
VerifyEmailControllerTest.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
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
<?php
namespace Laravel\Fortify\Tests;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Facades\URL;
use Mockery;
class VerifyEmailControllerTest extends OrchestraTestCase
{
public function test_the_email_can_be_verified()
{
$url = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
[
'id' => 1,
'hash' => sha1('[email protected]'),
]
);
$user = Mockery::mock(Authenticatable::class);
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$user->shouldReceive('getEmailForVerification')->andReturn('[email protected]');
$user->shouldReceive('hasVerifiedEmail')->andReturn(false);
$user->shouldReceive('markEmailAsVerified')->once();
$response = $this->actingAs($user)
->withSession(['url.intended' => 'http://foo.com/bar'])
->get($url);
$response->assertRedirect('http://foo.com/bar');
}
public function test_redirected_if_email_is_already_verified()
{
$url = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
[
'id' => 1,
'hash' => sha1('[email protected]'),
]
);
$user = Mockery::mock(Authenticatable::class);
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$user->shouldReceive('getEmailForVerification')->andReturn('[email protected]');
$user->shouldReceive('hasVerifiedEmail')->andReturn(true);
$user->shouldReceive('markEmailAsVerified')->never();
$response = $this->actingAs($user)->get($url);
$response->assertStatus(302);
}
public function test_email_is_not_verified_if_id_does_not_match()
{
$url = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
[
'id' => 2,
'hash' => sha1('[email protected]'),
]
);
$user = Mockery::mock(Authenticatable::class);
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$user->shouldReceive('getEmailForVerification')->andReturn('[email protected]');
$response = $this->actingAs($user)->get($url);
$response->assertStatus(403);
}
public function test_email_is_not_verified_if_email_does_not_match()
{
$url = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
[
'id' => 1,
'hash' => sha1('[email protected]'),
]
);
$user = Mockery::mock(Authenticatable::class);
$user->shouldReceive('getKey')->andReturn(1);
$user->shouldReceive('getAuthIdentifier')->andReturn(1);
$user->shouldReceive('getEmailForVerification')->andReturn('[email protected]');
$response = $this->actingAs($user)->get($url);
$response->assertStatus(403);
}
}