create(['name' => 'Küche']); $role->grants()->create(['ability' => 'speiseplan.manage']); $this->kitchen = User::factory()->withRoles([$role])->create(); } protected function tearDown(): void { Carbon::setTestNow(); parent::tearDown(); } private function upload(string $week): void { $this->actingAs($this->kitchen)->post('/speiseplan/wochen', ['week' => $week, 'image' => UploadedFile::fake()->image('plan.jpg', 1240, 1754)])->assertSessionHasNoErrors(); } public function test_weeks_ahead_current_and_next_week_are_shown(): void { $this->upload('2026-10-01'); // irgendein Tag → Montag 28.09. $this->upload('2026-10-05'); $this->upload('2026-10-19'); // drei Wochen im Voraus $this->assertSame(['2026-09-28', '2026-10-05', '2026-10-19'], Week::query()->orderBy('week_start')->pluck('week_start')->map->toDateString()->all()); $this->actingAs(User::factory()->create())->get('/speiseplan')->assertOk()->assertInertia(fn (Assert $p) => $p ->component('speiseplan::Index') ->where('weeks.0.title', 'Diese Woche') ->where('weeks.0.plan.week', 40) ->where('weeks.0.plan.width', 1240) ->where('weeks.1.plan.week', 41) ->where('canManage', false) ->where('manage', null)); $this->get(Week::query()->first()->present()['image_url'])->assertOk(); } public function test_uploading_again_replaces_the_week(): void { $this->upload('2026-09-28'); $old = Week::query()->sole()->path; $this->upload('2026-09-29'); $this->assertSame(1, Week::query()->count()); Storage::disk('local')->assertMissing($old); } public function test_only_images_are_stored_and_only_the_kitchen_uploads(): void { $this->actingAs($this->kitchen)->post('/speiseplan/wochen', ['week' => '2026-09-28', 'image' => UploadedFile::fake()->create('plan.pdf', 10, 'application/pdf')])->assertSessionHasErrors('image'); $this->actingAs(User::factory()->create())->post('/speiseplan/wochen', ['week' => '2026-09-28', 'image' => UploadedFile::fake()->image('p.jpg')])->assertForbidden(); } public function test_allergen_pdf_and_print_view(): void { $this->upload('2026-09-28'); $this->actingAs($this->kitchen)->post('/speiseplan/allergene', ['file' => UploadedFile::fake()->create('Allergene.pdf', 20, 'application/pdf')])->assertSessionHasNoErrors(); $user = User::factory()->create(); $this->actingAs($user)->get('/speiseplan')->assertInertia(fn (Assert $p) => $p->where('allergens.name', 'Allergene.pdf')); $this->get('/speiseplan/allergene')->assertOk()->assertHeader('Content-Type', 'application/pdf'); $this->get('/speiseplan/druck')->assertOk()->assertInertia(fn (Assert $p) => $p->component('speiseplan::Print')->has('plans', 1)); } public function test_old_weeks_are_deleted_after_two_weeks(): void { foreach (['2026-09-07', '2026-09-14', '2026-09-21', '2026-09-28'] as $week) { $this->upload($week); } $this->assertSame(1, SpeiseplanPlugin::purge()); $this->assertSame(['2026-09-14', '2026-09-21', '2026-09-28'], Week::query()->orderBy('week_start')->pluck('week_start')->map->toDateString()->all()); } }