admin()->create(); $post = NewsPost::factory()->create(); $event = Event::factory()->create(); foreach (['/admin/neuigkeiten', '/admin/kategorien', '/admin/termine', '/admin/termine/neu', "/admin/termine/{$event->id}/bearbeiten"] as $url) { $this->actingAs($admin)->get($url)->assertOk(); $this->actingAs(User::factory()->create())->get($url)->assertForbidden(); } // Beiträge schreibt man im Baukasten-Editor des Portals – das Backend leitet dorthin $this->actingAs($admin)->get('/admin/neuigkeiten/neu')->assertRedirect(route('news.editor.create')); $this->actingAs($admin)->get("/admin/neuigkeiten/{$post->id}/bearbeiten")->assertRedirect(route('news.editor.edit', $post)); $this->actingAs(User::factory()->create())->get("/admin/neuigkeiten/{$post->id}/bearbeiten")->assertForbidden(); } public function test_admin_can_write_a_post(): void { $admin = User::factory()->admin()->create(); $category = NewsCategory::factory()->create(); $this->actingAs($admin); $this->post('/redaktion/neuigkeiten', [ 'title' => 'Neue Kantine eröffnet', 'teaser' => 'Ab Montag gibt es frisches Essen im Erdgeschoss.', 'category_id' => $category->id, 'content' => json_encode(['blocks' => [ ['type' => 'heading', 'data' => ['text' => 'Was es gibt']], ['type' => 'text', 'data' => ['html' => '
Suppe, Salat und zwei Hauptgerichte.
']], ]]), 'action' => 'publish', ])->assertSessionHasNoErrors(); $post = NewsPost::query()->firstOrFail(); $this->assertSame('neue-kantine-eroeffnet', $post->slug); $this->assertSame($admin->id, $post->author_id); $this->assertTrue($post->isPublished()); $this->assertSame(['heading', 'text'], array_column($post->content['blocks'], 'type')); $this->assertStringNotContainsString('script', json_encode($post->content)); $this->assertStringContainsString('zwei Hauptgerichte', $post->body, 'Text für Suche und Lesezeit'); $this->get("/neuigkeiten/{$post->slug}")->assertOk()->assertInertia(fn ($page) => $page ->where('post.body_html', null) ->where('content.blocks.1.data.html', fn ($html) => str_contains($html, 'zwei Hauptgerichte'))); } public function test_admin_can_create_an_event(): void { $this->actingAs(User::factory()->admin()->create()); Livewire::test(CreateEvent::class) ->fillForm([ 'title' => 'Sommerfest', 'starts_at' => now()->addWeek()->format('Y-m-d 14:00'), 'ends_at' => now()->addWeek()->format('Y-m-d 18:00'), 'location' => 'Garten', 'is_published' => true, ]) ->call('create') ->assertHasNoFormErrors(); $this->assertSame('Garten', Event::query()->firstOrFail()->location); } public function test_event_end_must_not_be_before_start(): void { $this->actingAs(User::factory()->admin()->create()); Livewire::test(CreateEvent::class) ->fillForm([ 'title' => 'Falsch herum', 'starts_at' => now()->addWeek()->format('Y-m-d 14:00'), 'ends_at' => now()->addWeek()->format('Y-m-d 10:00'), ]) ->call('create') ->assertHasFormErrors(['ends_at']); } }