Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m54s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m29s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m38s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m40s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m7s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m13s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m24s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
88 lines
3.5 KiB
PHP
88 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Profile;
|
|
|
|
use App\Filament\AvatarProviders\InitialsAvatarProvider;
|
|
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']);
|
|
}
|
|
|
|
public function test_avatar_placeholder_is_shared_with_portal_and_admin(): void
|
|
{
|
|
$theme = app(Theme::class);
|
|
$theme->saveDraft(['avatar_placeholder' => 'theme/platzhalter.png']);
|
|
app()->call([$theme, 'publish']);
|
|
|
|
$user = User::factory()->create();
|
|
$url = Storage::disk('uploads')->url('theme/platzhalter.png');
|
|
|
|
$this->actingAs($user)->get('/')->assertInertia(fn (Assert $page) => $page->where('branding.avatar_placeholder_url', $url));
|
|
$this->assertSame($url, app(InitialsAvatarProvider::class)->get($user));
|
|
}
|
|
}
|