This repository has been archived by the owner on Jan 13, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
101 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Tests\Browser; | ||
|
||
use App\User; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Illuminate\Support\Facades\Hash; | ||
use Laravel\Dusk\Browser; | ||
use Tests\Browser\Pages\AccountPage; | ||
use Tests\Browser\Pages\ChangePasswordPage; | ||
use Tests\Browser\Pages\HomePage; | ||
use Tests\Browser\Pages\PagesFromHomeEnum; | ||
use Tests\DuskTestCase; | ||
|
||
class ChangePasswordTest extends DuskTestCase | ||
{ | ||
use WithFaker; | ||
|
||
private $user; | ||
private $userPassword; | ||
|
||
protected function setUp() { | ||
Parent::setUp(); | ||
$userPassword = $this->faker->unique()->password; | ||
$this->userPassword = $userPassword; | ||
$this->user = factory(User::class)->create([ | ||
'password' => bcrypt($userPassword) | ||
]); | ||
} | ||
|
||
protected function tearDown() { | ||
$this->user->delete(); | ||
} | ||
|
||
public function testChangePassword() { | ||
$newPassword = $this->faker->unique()->password; | ||
|
||
// Go to the personal space and change account email | ||
$this->browse(function (Browser $browser) use ($newPassword) { | ||
$browser->loginAs($this->user) | ||
->visit(new HomePage()) | ||
->navigateTo(PagesFromHomeEnum::ACCOUNT) | ||
->on(new AccountPage()) | ||
->navigateToModifyPasswordPage() | ||
->on(new ChangePasswordPage()) | ||
->type('oldPassword', $this->userPassword) | ||
->type('newPassword', $newPassword) | ||
->type('newPassword_confirmation', $newPassword) | ||
->click('@changePasswordConfirmationButton') | ||
->assertPathIs('/'); | ||
}); | ||
|
||
// Check password change in the database | ||
$passwordHashInDB = User::where('id', $this->user->id)->first()->password; | ||
$this->assertTrue(Hash::check($newPassword, $passwordHashInDB)); | ||
} | ||
} |
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,41 @@ | ||
<?php | ||
|
||
namespace Tests\Browser\Pages; | ||
|
||
use Laravel\Dusk\Browser; | ||
|
||
class ChangePasswordPage extends Page | ||
{ | ||
/** | ||
* Get the URL for the page. | ||
* | ||
* @return string | ||
*/ | ||
public function url() | ||
{ | ||
return '/password/change'; | ||
} | ||
|
||
/** | ||
* Assert that the browser is on the page. | ||
* | ||
* @param Browser $browser | ||
* @return void | ||
*/ | ||
public function assert(Browser $browser) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Get the element shortcuts for the page. | ||
* | ||
* @return array | ||
*/ | ||
public function elements() | ||
{ | ||
return [ | ||
'@changePasswordConfirmationButton' => '#confirm-change-password' | ||
]; | ||
} | ||
} |