Loheide-eu-mitarbeiterplatt.../tests/Feature/News/MustReadTest.php
Friederich Loheide 443599b739
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 8m42s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 7m39s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 12m30s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 17m0s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 13m43s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 24m25s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 11m16s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 3m39s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 10m40s
Pflichtlektüre für Neuigkeiten (0.59.0)
Beiträge mit Lesebestätigung (namentlich), Frist, Aufgabe und Feed-Hinweis;
Auswertung für die Redaktion (bestätigt von / wer fehlt).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-01 15:16:16 +00:00

63 lines
2.9 KiB
PHP

<?php
namespace Tests\Feature\News;
use App\Models\Role;
use App\Models\User;
use App\Tasks\Tasks;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\News\Models\NewsPost;
use Tests\TestCase;
class MustReadTest extends TestCase
{
use RefreshDatabase;
public function test_readers_confirm_must_read_and_editors_see_who_is_missing(): void
{
$role = Role::query()->create(['name' => 'Redaktion']);
$role->grants()->create(['ability' => 'news.manage']);
$editor = User::factory()->withRoles([$role])->create();
$post = NewsPost::factory()->create(['title' => 'Ruhezeiten im Nachtdienst', 'published_at' => now()->subHour(), 'must_read' => true, 'must_read_until' => now()->addDays(3)]);
$reader = User::factory()->create();
// Aufgabe mit Frist
$task = collect(app(Tasks::class)->forUser($reader))->firstWhere('title', '„Ruhezeiten im Nachtdienst“ lesen und bestätigen');
$this->assertNotNull($task);
$this->assertSame(now()->addDays(3)->toDateString(), $task['due']);
$this->actingAs($reader)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
->where('mustRead.acknowledged_at', null)->where('mustReadReport', null));
$this->actingAs($reader)->post("/neuigkeiten/{$post->slug}/gelesen")->assertSessionHas('status');
$this->assertNull(collect(app(Tasks::class)->forUser($reader))->firstWhere('key', 'news'));
$this->actingAs($editor)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
->where('mustReadReport.confirmed', 1)
->where('mustReadReport.missing', fn ($missing) => collect($missing)->contains($editor->name) && ! collect($missing)->contains($reader->name)));
}
public function test_ordinary_posts_cannot_be_confirmed(): void
{
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
$this->actingAs(User::factory()->create())->post("/neuigkeiten/{$post->slug}/gelesen")->assertNotFound();
}
public function test_editor_marks_a_post_as_must_read(): void
{
$role = Role::query()->create(['name' => 'Redaktion']);
$role->grants()->create(['ability' => 'news.manage']);
$editor = User::factory()->withRoles([$role])->create();
$this->actingAs($editor)->post('/redaktion/neuigkeiten', [
'title' => 'Neue Hygieneregeln', 'teaser' => 'Bitte lesen', 'content' => json_encode(['blocks' => []]),
'must_read' => '1', 'must_read_until' => now()->addWeek()->toDateString(), 'action' => 'publish',
])->assertSessionHasNoErrors();
$post = NewsPost::query()->where('title', 'Neue Hygieneregeln')->firstOrFail();
$this->assertTrue($post->must_read);
$this->assertSame(now()->addWeek()->toDateString(), $post->must_read_until->toDateString());
}
}