Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Add "Change password" feature test
Browse files Browse the repository at this point in the history
  • Loading branch information
Lenophie committed Nov 7, 2018
1 parent f4a0d26 commit e7a5ad8
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
3 changes: 2 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [0.16.0] - Unreleased
## [0.16.0] - 2018-11-07

### Added

Expand All @@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* Feature tests
* Account deletion
* Email change
* Password change

### Changed

Expand Down
2 changes: 1 addition & 1 deletion resources/views/auth/passwords/change.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<div class="field">
<div class=control">
<button type="submit" class="button is-link">
<button type="submit" class="button is-link" id="confirm-change-password">
{{__('Modify my password')}}
</button>
</div>
Expand Down
57 changes: 57 additions & 0 deletions tests/Browser/Features/ChangePasswordTest.php
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));
}
}
41 changes: 41 additions & 0 deletions tests/Browser/Pages/ChangePasswordPage.php
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'
];
}
}

0 comments on commit e7a5ad8

Please sign in to comment.