Loheide-eu-mitarbeiterplatt.../tests/Feature/Profile/CoverTest.php
Friederich Loheide 05b4b79cb3
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m47s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m8s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 4m6s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m25s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m23s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m39s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m40s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m8s
Titelbild im Profil, durchsuchbare Baum-Auswahl im IT-Ticket (0.20.1)
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-27 05:20:19 +00:00

74 lines
2.8 KiB
PHP

<?php
namespace Tests\Feature\Profile;
use App\Models\User;
use App\Support\Theme\Theme;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
class CoverTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('uploads');
}
public function test_cover_is_stored_cropped_and_shown_in_profile_and_greeting(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post('/profil/titelbild', ['cover' => UploadedFile::fake()->image('berge.jpg', 2400, 1600)])
->assertRedirect()
->assertSessionHasNoErrors();
$user->refresh();
$this->assertStringStartsWith("covers/{$user->id}/", $user->cover_path);
[$width, $height] = getimagesizefromstring(Storage::disk('uploads')->get($user->cover_path));
$this->assertSame([1600, 500], [$width, $height]);
$this->get("/personen/{$user->id}")->assertInertia(fn (Assert $page) => $page
->where('person.cover_url', $user->coverUrl())
->where('auth.user.cover_url', $user->coverUrl()));
// Neues Bild ersetzt das alte, Entfernen räumt auf
$old = $user->cover_path;
$this->post('/profil/titelbild', ['cover' => UploadedFile::fake()->image('see.png', 1800, 900)])->assertSessionHasNoErrors();
Storage::disk('uploads')->assertMissing($old);
$current = $user->fresh()->cover_path;
$this->delete('/profil/titelbild')->assertRedirect();
Storage::disk('uploads')->assertMissing($current);
$this->assertNull($user->fresh()->cover_path);
}
public function test_only_images_are_accepted(): void
{
$this->actingAs(User::factory()->create())
->post('/profil/titelbild', ['cover' => UploadedFile::fake()->create('lebenslauf.pdf', 100, 'application/pdf')])
->assertSessionHasErrors('cover');
}
public function test_default_cover_and_overlay_come_from_the_appearance(): void
{
$theme = app(Theme::class);
$theme->saveDraft(['profile_cover' => 'theme/titel.webp', 'profile_cover_overlay' => 55]);
app()->call([$theme, 'publish']);
$this->actingAs(User::factory()->create())->get('/')->assertInertia(fn (Assert $page) => $page
->where('branding.profile_cover.image_url', Storage::disk('uploads')->url('theme/titel.webp'))
->where('branding.profile_cover.overlay', 0.55));
// Ungültige Werte fallen auf den Standard zurück
$this->assertSame(70, Theme::normalize(['profile_cover_overlay' => 13])['profile_cover_overlay']);
$this->assertNull(Theme::normalize(['profile_cover' => '../.env'])['profile_cover']);
}
}