Files
GSB-Construction/tests/Feature/ProfileTest.php
Christopher Boyles 32c3e3af69
Some checks failed
Tests / PHP 8.3 (push) Has been cancelled
Tests / PHP 8.4 (push) Has been cancelled
Tests / PHP 8.5 (push) Has been cancelled
Team Roster Feature
2026-06-08 17:45:15 +08:00

109 lines
3.0 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ProfileTest extends TestCase
{
use RefreshDatabase;
public function test_profile_page_is_displayed(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->get('/profile');
$response->assertOk();
}
public function test_profile_information_can_be_updated(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => 'test@example.com',
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$user->refresh();
$this->assertSame('Test User', $user->name);
$this->assertSame('test@example.com', $user->email);
$this->assertNull($user->email_verified_at);
}
public function test_email_verification_status_is_unchanged_when_the_email_address_is_unchanged(): void
{
$user = User::factory()->create();
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => $user->email,
]);
$response
->assertSessionHasNoErrors()
->assertRedirect('/profile');
$this->assertNotNull($user->refresh()->email_verified_at);
}
public function test_profile_picture_upload_works_with_jpg(): void
{
$user = User::factory()->create();
\Illuminate\Support\Facades\Storage::fake('public');
$file = \Illuminate\Http\UploadedFile::fake()->image('avatar.jpg');
$response = $this
->actingAs($user)
->patch('/profile', [
'name' => 'Test User',
'email' => 'test@example.com',
'profile_picture' => $file,
]);
$response->assertSessionHasNoErrors()->assertRedirect('/profile');
$user->refresh();
$this->assertNotNull($user->profile_picture);
$this->assertStringContainsString('/storage/avatars/', $user->profile_picture);
$filename = str_replace('/storage/', '', $user->profile_picture);
\Illuminate\Support\Facades\Storage::disk('public')->assertExists($filename);
}
public function test_profile_picture_upload_rejects_non_jpg(): void
{
$user = User::factory()->create();
$file = \Illuminate\Http\UploadedFile::fake()->image('avatar.png');
$response = $this
->actingAs($user)
->from('/profile')
->patch('/profile', [
'name' => 'Test User',
'email' => 'test@example.com',
'profile_picture' => $file,
]);
$response->assertSessionHasErrors('profile_picture');
$this->assertNull($user->refresh()->profile_picture);
}
}