1
0
Fork 0

User edit: add username to the form.

This commit is contained in:
Henrik Hautakoski 2021-07-04 18:21:30 +02:00
parent 83f00ddebd
commit c27a595408
4 changed files with 73 additions and 5 deletions

View file

@ -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()