User edit: add username to the form.
This commit is contained in:
parent
83f00ddebd
commit
c27a595408
4 changed files with 73 additions and 5 deletions
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Foundation\Testing\WithFaker;
|
||||
use Tests\TestCase;
|
||||
|
|
@ -28,18 +29,60 @@ class UserTest extends TestCase
|
|||
$response->assertRedirect(route('auth.login'));
|
||||
}
|
||||
|
||||
public function test_user_can_update()
|
||||
public function test_user_can_update_username()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->post(route('user.update'), [
|
||||
'username' => 'AnotherUsername',
|
||||
'current_password' => null,
|
||||
'password' => null,
|
||||
'password_confirmation' => null
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('user.index'));
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'username' => 'AnotherUsername',
|
||||
'password' => $user->password
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_user_can_update_password()
|
||||
{
|
||||
$fakeHash = '$2y$04$wiUTB.6ldFQ3TmxdSyizEubuKubDA45L/Bv0zlZ1.uoMcnm.ftIaK';
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
// Mock Hash::make() to return a fake password hash.
|
||||
Hash::shouldReceive('make')
|
||||
->once()
|
||||
->with('newpassword')
|
||||
->andReturn($fakeHash);
|
||||
|
||||
// Also have to mock Hash::check() as i can not get
|
||||
// partial mocks to work for facades.
|
||||
Hash::shouldReceive('check')
|
||||
->with('password', $user->password)
|
||||
->andReturn(true);
|
||||
|
||||
$response = $this->actingAs($user)
|
||||
->post(route('user.update'), [
|
||||
'username' => $user->username,
|
||||
'current_password' => 'password',
|
||||
'password' => 'newpassword',
|
||||
'password_confirmation' => 'newpassword'
|
||||
]);
|
||||
|
||||
$response->assertRedirect(route('user.index'));
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'id' => $user->id,
|
||||
'username' => $user->username,
|
||||
'password' => $fakeHash
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_guest_can_not_update()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue