mirror of
https://github.com/10h30/Test-Laravel-Auth-Basics.git
synced 2026-07-19 22:54:01 +09:00
Profile fields and update tests
This commit is contained in:
@@ -4,6 +4,7 @@ namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Tests\TestCase;
|
||||
|
||||
class AuthenticationTest extends TestCase
|
||||
@@ -34,4 +35,47 @@ class AuthenticationTest extends TestCase
|
||||
$response = $this->actingAs($user)->get('/');
|
||||
$this->assertStringContainsString('href="/profile"', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_profile_fields_are_visible()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$response = $this->actingAs($user)->get('/profile');
|
||||
$this->assertStringContainsString('value="'.$user->name.'"', $response->getContent());
|
||||
$this->assertStringContainsString('value="'.$user->email.'"', $response->getContent());
|
||||
}
|
||||
|
||||
public function test_profile_name_email_update_successful()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$newData = [
|
||||
'name' => 'New name',
|
||||
'email' => 'new@email.com'
|
||||
];
|
||||
$this->actingAs($user)->put('/profile', $newData);
|
||||
$this->assertDatabaseHas('users', $newData);
|
||||
|
||||
// Check if the user is still able to log in - password unchanged
|
||||
$this->assertTrue(Auth::attempt([
|
||||
'email' => $user->email,
|
||||
'password' => 'password'
|
||||
]));
|
||||
}
|
||||
|
||||
public function test_profile_password_update_successful()
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
$newData = [
|
||||
'name' => 'New name',
|
||||
'email' => 'new@email.com',
|
||||
'password' => 'newpassword',
|
||||
'password_confirmation' => 'newpassword'
|
||||
];
|
||||
$this->actingAs($user)->put('/profile', $newData);
|
||||
|
||||
// Check if the user is able to log in with the new password
|
||||
$this->assertTrue(Auth::attempt([
|
||||
'email' => $user->email,
|
||||
'password' => 'newpassword'
|
||||
]));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user