-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow reset password to activate user if user activation enabled (#40)
Since the reset password flow involves an email being sent to the user to confirm the password reset, this should satisfy user activation as well as the same requirement is met. Refs: #35 (comment)
- Loading branch information
1 parent
1522c91
commit bf28200
Showing
5 changed files
with
95 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
<?php namespace Winter\User\Tests\Unit\Facades; | ||
<?php | ||
|
||
namespace Winter\User\Tests\Unit\Facades; | ||
|
||
use Auth; | ||
use Winter\User\Models\User; | ||
use Winter\User\Tests\UserPluginTestCase; | ||
|
||
class AuthFacadeTest extends UserPluginTestCase | ||
{ | ||
public function testRegisteringAUser() | ||
public function testCanRegisterAUser() | ||
{ | ||
// register a user | ||
$user = Auth::register([ | ||
|
@@ -19,14 +21,14 @@ public function testRegisteringAUser() | |
// our one user should be returned | ||
$this->assertEquals(1, User::count()); | ||
$this->assertInstanceOf('Winter\User\Models\User', $user); | ||
|
||
// and that user should have the following data | ||
$this->assertFalse($user->is_activated); | ||
$this->assertEquals('Some User', $user->name); | ||
$this->assertEquals('[email protected]', $user->email); | ||
} | ||
|
||
public function testRegisteringAUserWithAutoActivation() | ||
public function testCanRegisterAndAutomaticallyActivateAUser() | ||
{ | ||
// register a user with the auto-activate flag | ||
$user = Auth::register([ | ||
|
@@ -43,7 +45,7 @@ public function testRegisteringAUserWithAutoActivation() | |
$this->assertTrue(Auth::check()); | ||
} | ||
|
||
public function testRegisteringAGuest() | ||
public function testCanRegisterAGuest() | ||
{ | ||
// register a guest | ||
$guest = Auth::registerGuest(['email' => '[email protected]']); | ||
|
@@ -57,7 +59,7 @@ public function testRegisteringAGuest() | |
$this->assertEquals('[email protected]', $guest->email); | ||
} | ||
|
||
public function testLoginAndCheckingAuthentication() | ||
public function testCanLoginAndCheckAuthenticationAndActivation() | ||
{ | ||
// we should not be authenticated | ||
$this->assertFalse(Auth::check()); | ||
|
@@ -81,4 +83,4 @@ public function testLoginAndCheckingAuthentication() | |
// we should now be authenticated | ||
$this->assertTrue(Auth::check()); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Winter\User\Tests\Unit\Models; | ||
|
||
use Mockery; | ||
use Winter\User\Models\User; | ||
use Winter\User\Tests\UserPluginTestCase; | ||
|
||
class UserModelTest extends UserPluginTestCase | ||
{ | ||
public function testCanActivateUserOnPasswordResetIfUserActivationEnabled() | ||
{ | ||
$userMock = Mockery::mock(User::class)->makePartial(); | ||
$userMock->shouldReceive('isActivatedByUser')->andReturn(true); | ||
$userMock->shouldReceive('flushEventListeners')->andReturnNull(); | ||
|
||
$userMock->fill([ | ||
'name' => 'Some User', | ||
'email' => '[email protected]', | ||
'password' => 'changeme', | ||
]); | ||
$userMock->reset_password_code = '12345abcde'; | ||
$userMock->save(); | ||
|
||
// Attempt a password reset | ||
$this->assertTrue($userMock->attemptResetPassword('12345abcde', 'newpassword')); | ||
$this->assertTrue($userMock->is_activated); | ||
} | ||
|
||
public function testWontActivateUserOnPasswordResetIfUserActivationNotEnabled() | ||
{ | ||
$userMock = Mockery::mock(User::class)->makePartial(); | ||
$userMock->shouldReceive('isActivatedByUser')->andReturn(false); | ||
$userMock->shouldReceive('flushEventListeners')->andReturnNull(); | ||
|
||
$userMock->fill([ | ||
'name' => 'Some User', | ||
'email' => '[email protected]', | ||
'password' => 'changeme', | ||
]); | ||
$userMock->reset_password_code = '12345abcde'; | ||
$userMock->save(); | ||
|
||
// Attempt a password reset | ||
$this->assertTrue($userMock->attemptResetPassword('12345abcde', 'newpassword')); | ||
$this->assertFalse($userMock->is_activated); | ||
} | ||
} |