45 lines
1.1 KiB
PHP
45 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
|
|
test('user edit page requires authentication', function () {
|
|
$user = User::factory()->create();
|
|
|
|
$this->get("/user/{$user->id}/edit")->assertRedirect('/login');
|
|
});
|
|
|
|
test('authenticated users can view the user edit page', function () {
|
|
$actingUser = User::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this
|
|
->actingAs($actingUser)
|
|
->get("/user/{$user->id}/edit");
|
|
|
|
$response
|
|
->assertSuccessful()
|
|
->assertSee('Edit User')
|
|
->assertSee($user->name)
|
|
->assertSee($user->email);
|
|
});
|
|
|
|
test('authenticated users can update a user', function () {
|
|
$actingUser = User::factory()->create();
|
|
$user = User::factory()->create();
|
|
|
|
$response = $this
|
|
->actingAs($actingUser)
|
|
->patch("/user/{$user->id}", [
|
|
'name' => 'Updated User',
|
|
'email' => 'updated@example.com',
|
|
]);
|
|
|
|
$response
|
|
->assertRedirect("/user/{$user->id}/edit");
|
|
|
|
$user->refresh();
|
|
|
|
$this->assertSame('Updated User', $user->name);
|
|
$this->assertSame('updated@example.com', $user->email);
|
|
});
|