create(); $this->actingAs($user) ->post('/profil/bild', ['avatar' => UploadedFile::fake()->image('foto.jpg', 800, 600)]) ->assertRedirect() ->assertSessionHasNoErrors(); $user->refresh(); $this->assertStringStartsWith("avatars/{$user->id}/", $user->avatar_path); Storage::disk('uploads')->assertExists("{$user->avatar_path}-96.webp"); Storage::disk('uploads')->assertExists("{$user->avatar_path}-256.webp"); [$width, $height] = getimagesizefromstring(Storage::disk('uploads')->get("{$user->avatar_path}-256.webp")); $this->assertSame([256, 256], [$width, $height]); $this->assertStringEndsWith("{$user->avatar_path}-96.webp", $user->avatarUrl(96)); } public function test_old_avatar_is_replaced_and_removed(): void { $user = User::factory()->create(); $this->actingAs($user)->post('/profil/bild', ['avatar' => UploadedFile::fake()->image('a.png', 300, 300)]); $old = $user->fresh()->avatar_path; $this->actingAs($user)->post('/profil/bild', ['avatar' => UploadedFile::fake()->image('b.png', 300, 300)]); $new = $user->fresh()->avatar_path; $this->assertNotSame($old, $new); Storage::disk('uploads')->assertMissing("{$old}-256.webp"); Storage::disk('uploads')->assertExists("{$new}-256.webp"); } public function test_avatar_can_be_removed(): void { $user = User::factory()->create(); $this->actingAs($user)->post('/profil/bild', ['avatar' => UploadedFile::fake()->image('a.png', 300, 300)]); $path = $user->fresh()->avatar_path; $this->actingAs($user)->delete('/profil/bild')->assertRedirect(); $this->assertNull($user->fresh()->avatar_path); Storage::disk('uploads')->assertMissing("{$path}-96.webp"); } public function test_only_images_are_accepted(): void { $user = User::factory()->create(); $this->actingAs($user) ->post('/profil/bild', ['avatar' => UploadedFile::fake()->create('lebenslauf.pdf', 100, 'application/pdf')]) ->assertSessionHasErrors('avatar'); $this->assertNull($user->fresh()->avatar_path); } }