create(['name' => 'Kommunikation']); $role->grants()->create(['ability' => 'polls.manage']); $editor = User::factory()->withRoles([$role])->create(); $this->actingAs($editor)->post('/redaktion/umfragen', [ 'title' => 'Kantine', 'questions' => [['id' => 'essen', 'type' => 'single', 'label' => 'Wie schmeckt es?', 'options' => [['id' => 'gut', 'label' => 'Gut'], ['id' => 'geht', 'label' => 'Geht so']]]], 'results_visibility' => Poll::AFTER_VOTE, 'published' => true, ])->assertSessionHasNoErrors(); $poll = Poll::query()->latest('id')->firstOrFail(); $user = User::factory()->create(); $titles = array_column(app(Tasks::class)->forUser($user), 'title'); $this->assertContains('Umfrage: Kantine', $titles); // Startseite und Übersicht zeigen sie $widget = $this->dashboardWidget($this->actingAs($user)->get('/'), 'core.tasks'); $this->assertSame('Umfrage: Kantine', $widget['tasks'][0]['title']); $this->actingAs($user)->get('/aufgaben')->assertInertia(fn (Assert $page) => $page->component('Tasks/Index')->has('tasks', 1)); // Nach der Abstimmung ist sie erledigt – und die Kachel verschwindet $this->actingAs($user)->post("/umfragen/{$poll->id}/abstimmen", ['answers' => ['essen' => 'gut']])->assertSessionHasNoErrors(); $this->assertSame([], app(Tasks::class)->forUser($user)); $this->assertNull($this->dashboardWidget($this->actingAs($user)->get('/'), 'core.tasks')); } public function test_blocked_plugins_deliver_no_tasks_and_errors_are_isolated(): void { $clients = Role::query()->create(['name' => 'Klienten']); $client = User::factory()->withRoles([$clients])->create(); $tasks = app(Tasks::class); $tasks->add('umfragen', fn () => [['title' => 'Abstimmen', 'url' => '/umfragen/1']]); $tasks->add('kaputt', fn () => throw new \RuntimeException('weg')); $tasks->add('frist', fn () => [ ['title' => 'Später', 'url' => '/a', 'due' => now()->addDays(5)->toDateString()], ['title' => 'Überfällig', 'url' => '/b', 'due' => now()->subDay()->toDateString()], ['title' => 'Ohne Adresse'], ]); app(PluginAccess::class)->exclude('umfragen', [$clients->id]); $result = $tasks->forUser($client); $this->assertSame(['Überfällig', 'Später'], array_column($result, 'title')); $this->assertTrue($result[0]['overdue']); $this->assertContains('Abstimmen', array_column($tasks->forUser(User::factory()->create()), 'title')); } public function test_page_requires_login(): void { $this->get('/aufgaben')->assertRedirect('/login'); } }