-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize email address before saving (#2934)
* normalize email before saving * fix copy/paste error * Run php-cs-fixer
- Loading branch information
1 parent
f064e56
commit 14329d9
Showing
6 changed files
with
100 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,22 @@ public function testUserCannotSignUpWithDuplicateEmail(): void | |
}); | ||
} | ||
|
||
public function testEmailIsNormalizedUponRegistration(): void | ||
{ | ||
$this->browse(function (Browser $browser) { | ||
$browser->visit('/register') | ||
->assertGuest() | ||
->type('name', 'E. Mel') | ||
->type('email', '[email protected]') | ||
->type('password', 'my password') | ||
->type('password_confirmation', 'my password') | ||
->press('Sign up') | ||
->assertAuthenticated() | ||
->visit('/my-account') | ||
->assertInputValue('email', '[email protected]'); | ||
}); | ||
} | ||
|
||
public function testUserCanChangeLanguage(): void | ||
{ | ||
User::factory()->create([ | ||
|
@@ -169,6 +185,24 @@ public function testUserCanChangeEmail(): void | |
}); | ||
} | ||
|
||
public function testEmailIsNormalizedUponChanging(): void | ||
{ | ||
User::factory()->withEmail('[email protected]')->create(); | ||
|
||
$this->browse( | ||
fn(Browser $browser) => $browser | ||
->loginAs('[email protected]') | ||
->assertAuthenticated() | ||
->visit('/my-account') | ||
->type('email', '[email protected]') | ||
->press('Save') | ||
// The login should be invalid if the email didn't normalize. | ||
// In that case, we wouldn't be able to see these. | ||
->assertSee('Account updated successfully') | ||
->assertInputValue('email', '[email protected]'), | ||
); | ||
} | ||
|
||
public function testUserCanDisconnectFacebookAndGoogleIDWithPassword(): void | ||
{ | ||
User::factory()->create([ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -134,4 +134,26 @@ public function testCreatedAtIsOverrideable(): void | |
), | ||
); | ||
} | ||
|
||
public function testEmailIsNormalizedBeforeSaving(): void | ||
{ | ||
$user = User::factory()->admin()->create(); | ||
|
||
$this | ||
->withBasicAuth($user->getApiKey(), $user->getApiSecret()) | ||
->postJson('/api/users', [ | ||
'name' => 'E. Mel', | ||
'email' => '[email protected]', | ||
]) | ||
->assertCreated() | ||
->assertJson( | ||
fn(AssertableJson $json) => $json | ||
->has( | ||
'data', | ||
fn(AssertableJson $json) => $json | ||
->where('email', '[email protected]') | ||
->etc(), | ||
), | ||
); | ||
} | ||
} |