Files
fewo-stommer/tests/Feature/WebsiteContentTest.php
T
Lars StommerandClaude Opus 5.5 bb7eb62782 Inhaltsverwaltung: Bilder, Webseiten-Texte, Ausstattung, FAQ, Hinweis-Banner
- Bilder mit automatischen WebP-Webgrößen (640/1280/2048 px), Sortierung per Drag & Drop, Mehrfach-Upload, Import-Befehl photos:import
- Webseiten-Texte als feste, bearbeitbare Bausteine (config/content.php), Rich-Text bereinigt ausgegeben
- Ausstattung und FAQ aus der bisherigen Webseite übernommen
- Rolle Inhalte hat Zugriff auf alle Webseiten-Bereiche

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 10:19:51 +02:00

107 lines
4.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Enums\PhotoCategory;
use App\Enums\UserRole;
use App\Filament\Pages\EditContent;
use App\Filament\Resources\Amenities\AmenityResource;
use App\Filament\Resources\Faqs\FaqResource;
use App\Filament\Resources\Notices\NoticeResource;
use App\Filament\Resources\Photos\Pages\ListPhotos;
use App\Filament\Resources\Photos\PhotoResource;
use App\Filament\Resources\Properties\PropertyResource;
use App\Models\Amenity;
use App\Models\Notice;
use App\Models\Photo;
use App\Models\User;
use App\Support\Content;
use Carbon\CarbonImmutable;
use Database\Seeders\PropertySeeder;
use Database\Seeders\WebsiteContentSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
use Livewire\Livewire;
use Tests\TestCase;
class WebsiteContentTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('public');
$this->seed([PropertySeeder::class, WebsiteContentSeeder::class]);
$this->actingAs(User::factory()->role(UserRole::Content)->create());
}
public function test_content_editor_sees_website_areas_but_not_bookings(): void
{
foreach ([PhotoResource::class, AmenityResource::class, FaqResource::class, NoticeResource::class] as $resource) {
$this->get($resource::getUrl('index'))->assertOk();
}
$this->get(EditContent::getUrl())->assertOk()->assertSee('Webseiten-Texte');
$this->get(PropertyResource::getUrl('index'))->assertForbidden();
}
public function test_texts_fall_back_to_defaults_and_can_be_saved(): void
{
$this->assertSame('Ihr Zuhause zwischen Garten und Meer', Content::get('home.hero.title'));
Livewire::test(EditContent::class)
->set('data.home__hero__title', 'Willkommen an der Ostsee')
->set('data.legal__imprint', '<p>Angaben gemäß § 5 DDG</p><script>alert(1)</script>')
->call('save')
->assertNotified('Texte gespeichert');
$this->assertSame('Willkommen an der Ostsee', Content::get('home.hero.title'));
$this->assertStringContainsString('§ 5 DDG', (string) Content::html('legal.imprint'));
$this->assertStringNotContainsString('<script>', (string) Content::html('legal.imprint'));
}
public function test_uploaded_photos_get_webp_web_sizes(): void
{
$photo = Photo::factory()->create();
$photo->addMedia(UploadedFile::fake()->image('terrasse.jpg', 3000, 2000))->toMediaCollection(Photo::COLLECTION);
$media = $photo->fresh()->getFirstMedia(Photo::COLLECTION);
foreach (array_keys(Photo::WIDTHS) as $conversion) {
$this->assertTrue($media->hasGeneratedConversion($conversion), "conversion {$conversion}");
$this->assertStringEndsWith('.webp', $photo->url($conversion));
}
$this->assertStringContainsString('2048w', $photo->srcset());
}
public function test_several_photos_are_uploaded_at_once(): void
{
Livewire::test(ListPhotos::class)
->callAction('bulkUpload', [
'files' => [UploadedFile::fake()->image('wohn-zimmer.jpg', 1600, 1000), UploadedFile::fake()->image('kueche.jpg', 1600, 1000)],
'category' => PhotoCategory::Apartment->value,
])
->assertNotified('2 Bilder hochgeladen');
$this->assertSame(['Wohn zimmer', 'Kueche'], Photo::orderBy('sort_order')->pluck('alt_text')->all());
}
public function test_notices_are_visible_only_within_their_dates(): void
{
$this->travelTo(CarbonImmutable::parse('2026-11-10'));
Notice::factory()->create(['text' => 'aktuell', 'starts_on' => '2026-11-01', 'ends_on' => '2026-11-15']);
Notice::factory()->create(['text' => 'vorbei', 'ends_on' => '2026-11-09']);
Notice::factory()->create(['text' => 'inaktiv', 'is_active' => false]);
Notice::factory()->create(['text' => 'dauerhaft']);
$this->assertEqualsCanonicalizing(['aktuell', 'dauerhaft'], Notice::visible()->pluck('text')->all());
}
public function test_amenities_from_the_old_website_are_seeded(): void
{
$this->assertGreaterThan(20, Amenity::count());
$this->assertSame(6, Amenity::where('is_highlight', true)->count());
}
}