count(2)->create(); NewsPost::factory()->draft()->create(); NewsPost::factory()->scheduled()->create(); $this->actingAs(User::factory()->create()) ->get('/neuigkeiten') ->assertOk() ->assertInertia(fn (Assert $page) => $page->component('news::Index')->where('posts.meta.total', 2)); } public function test_posts_can_be_filtered_by_category(): void { $mav = NewsCategory::factory()->create(['name' => 'MAV', 'slug' => 'mav']); NewsPost::factory()->create(['category_id' => $mav->id]); NewsPost::factory()->count(2)->create(); $this->actingAs(User::factory()->create()) ->get('/neuigkeiten?kategorie=mav') ->assertInertia(fn (Assert $page) => $page ->where('posts.meta.total', 1) ->where('posts.data.0.category.name', 'MAV') ->where('activeCategory', 'mav')); } public function test_published_post_is_shown_with_author(): void { $author = User::factory()->create(['first_name' => 'Grete', 'last_name' => 'Müller']); $post = NewsPost::factory()->create(['author_id' => $author->id, 'title' => 'Sommerfest 2026']); $this->assertSame('sommerfest-2026', $post->slug); $this->actingAs(User::factory()->create()) ->get('/neuigkeiten/sommerfest-2026') ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('news::Show') ->where('post.title', 'Sommerfest 2026') ->where('post.author.name', 'Grete Müller')); } public function test_drafts_and_scheduled_posts_are_not_reachable(): void { $draft = NewsPost::factory()->draft()->create(); $scheduled = NewsPost::factory()->scheduled()->create(); $user = User::factory()->create(); $this->actingAs($user)->get("/neuigkeiten/{$draft->slug}")->assertNotFound(); $this->actingAs($user)->get("/neuigkeiten/{$scheduled->slug}")->assertNotFound(); } public function test_slugs_are_unique(): void { $a = NewsPost::factory()->create(['title' => 'Neuigkeit']); $b = NewsPost::factory()->create(['title' => 'Neuigkeit']); $this->assertSame('neuigkeit', $a->slug); $this->assertSame('neuigkeit-2', $b->slug); } public function test_body_is_sanitized_when_saved(): void { $post = NewsPost::factory()->create([ 'body' => '

Hallo Welt

Link', ]); $this->assertStringContainsString('Welt', $post->body_html); $this->assertStringNotContainsString('script', $post->body_html); $this->assertStringNotContainsString('onclick', $post->body_html); $this->assertStringNotContainsString('javascript:', $post->body_html); $this->assertStringNotContainsString('iframe', $post->body_html); } public function test_reading_time_is_calculated(): void { $post = NewsPost::factory()->create(['body' => '

'.str_repeat('Wort ', 450).'

']); $this->assertSame(3, $post->reading_minutes); } public function test_cover_variants_are_created_and_removed(): void { Storage::fake('uploads'); Storage::disk('uploads')->put('news/cover.jpg', UploadedFile::fake()->image('cover.jpg', 2000, 1200)->getContent()); $post = NewsPost::factory()->create(['cover_path' => 'news/cover.jpg']); Storage::disk('uploads')->assertExists('news/cover-thumb.webp'); Storage::disk('uploads')->assertExists('news/cover-large.webp'); $this->assertStringEndsWith('news/cover-thumb.webp', $post->coverUrl('thumb')); $post->delete(); Storage::disk('uploads')->assertMissing('news/cover.jpg'); Storage::disk('uploads')->assertMissing('news/cover-thumb.webp'); } public function test_large_photos_fit_into_shared_hosting_memory_limit(): void { Storage::fake('uploads'); // Testbild (12 Megapixel wie ein Handyfoto) mit großzügigem Limit erzeugen … ini_set('memory_limit', '512M'); Storage::disk('uploads')->put('news/handyfoto.jpg', UploadedFile::fake()->image('handyfoto.jpg', 4000, 3000)->getContent()); gc_collect_cycles(); // … dann wie auf typischem Shared Hosting mit 128 MB verarbeiten. Der Test-Prozess // selbst belegt schon Speicher (viele Tests in einem Lauf), daher 128 MB zusätzlich dazu. $limit = memory_get_usage(true) + 128 * 1024 * 1024; $this->assertNotFalse(ini_set('memory_limit', (string) $limit)); NewsPost::factory()->create(['cover_path' => 'news/handyfoto.jpg']); Storage::disk('uploads')->assertExists('news/handyfoto-large.webp'); Storage::disk('uploads')->assertExists('news/handyfoto-thumb.webp'); ini_set('memory_limit', '512M'); } public function test_dashboard_shows_featured_and_latest_news(): void { Storage::fake('uploads'); Storage::disk('uploads')->put('news/a.jpg', UploadedFile::fake()->image('a.jpg', 800, 450)->getContent()); $featured = NewsPost::factory()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']); NewsPost::factory()->count(5)->create(); NewsPost::factory()->draft()->create(['is_featured' => true, 'cover_path' => 'news/a.jpg']); $response = $this->actingAs(User::factory()->create())->get('/'); $hero = $this->dashboardWidget($response, 'news.hero')['posts']; $this->assertCount(1, $hero); $this->assertSame($featured->id, $hero[0]['id']); $this->assertCount(4, $this->dashboardWidget($response, 'news.latest')['posts']); $this->assertCount(1, $this->dashboardWidget($response, 'news.areas')['posts']); } }