Profile fields and update tests

This commit is contained in:
PovilasKorop
2021-11-01 07:48:35 +02:00
parent 583796d502
commit 177b740701
3 changed files with 92 additions and 19 deletions
+44
View File
@@ -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'
]));
}
}