Loheide-eu-mitarbeiterplatt.../tests/Feature/TasksTest.php
Friederich Loheide c11cf4e0c4
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 7m6s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 13s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 7m24s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 8m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m51s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 10m39s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 8m42s
Meine Aufgaben (0.53.0)
Tasks-Registry mit Anbietern aus QM, Umfragen und Redaktion; Kachel auf der
Startseite und Seite /aufgaben.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-29 19:42:53 +00:00

72 lines
3.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature;
use App\Models\Role;
use App\Models\User;
use App\Plugins\PluginAccess;
use App\Tasks\Tasks;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Umfragen\Models\Poll;
use Tests\TestCase;
class TasksTest extends TestCase
{
use RefreshDatabase;
public function test_open_poll_becomes_a_task_until_voted(): void
{
$role = Role::query()->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');
}
}