create(['name' => 'Ideengremium']); $role->grants()->create(['ability' => 'ideas.manage']); $this->board = User::factory()->withRoles([$role])->create(); $this->author = User::factory()->create(); $this->idea = Idea::query()->create(['title' => 'Chef X ist unfähig', 'body' => 'Beleidigung', 'author_id' => $this->author->id]); } public function test_reports_notify_the_board_once_and_hide_after_three(): void { Notification::fake(); [$a, $b, $c] = User::factory()->count(3)->create()->all(); $this->actingAs($this->author)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'spam'])->assertStatus(422); $this->actingAs($a)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'offensive', 'note' => 'Namentlich'])->assertSessionHas('status'); $this->actingAs($a)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'offensive']); $this->actingAs($b)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'personal']); $this->assertSame(2, IdeaReport::query()->count()); $this->assertNull($this->idea->fresh()->hidden_at); Notification::assertSentToTimes($this->board, PortalNotification::class, 1); $this->actingAs($c)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'offensive']); $this->assertNotNull($this->idea->fresh()->hidden_at); // Ausgeblendet: andere sehen nichts, die einreichende Person und das Gremium schon $this->actingAs($a)->get("/ideen/{$this->idea->id}")->assertNotFound(); $this->actingAs($a)->get('/ideen')->assertInertia(fn (Assert $p) => $p->has('ideas', 0)); $this->actingAs($this->author)->get("/ideen/{$this->idea->id}")->assertInertia(fn (Assert $p) => $p->where('idea.hidden', true)->where('idea.reports', [])); $this->actingAs($this->board)->get("/ideen/{$this->idea->id}")->assertInertia(fn (Assert $p) => $p ->has('idea.reports', 3)->where('idea.reports.0.note', 'Namentlich')->missing('idea.reports.0.user')); } public function test_board_keeps_or_removes(): void { $a = User::factory()->create(); $this->actingAs($a)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'spam']); $this->actingAs($a)->put("/ideen/{$this->idea->id}/meldungen", ['action' => 'keep'])->assertForbidden(); $this->actingAs($this->board)->put("/ideen/{$this->idea->id}/meldungen", ['action' => 'keep'])->assertRedirect(); $this->assertNotNull(IdeaReport::query()->first()->resolved_at); $this->actingAs($this->board)->put("/ideen/{$this->idea->id}/meldungen", ['action' => 'remove'])->assertRedirect('/ideen'); $this->assertNull(Idea::query()->find($this->idea->id)); } public function test_hidden_comments_show_no_text_to_others(): void { $writer = User::factory()->create(); $comment = $this->idea->comments()->create(['user_id' => $writer->id, 'body' => 'Gemeiner Kommentar']); $others = User::factory()->count(3)->create(); foreach ($others as $user) { $this->actingAs($user)->post("/ideen/{$this->idea->id}/melden", ['reason' => 'offensive', 'comment_id' => $comment->id]); } $this->assertNotNull($comment->fresh()->hidden_at); $this->assertNull($this->idea->fresh()->hidden_at); $this->actingAs($others[0])->get("/ideen/{$this->idea->id}")->assertInertia(fn (Assert $p) => $p->where('idea.comment_list.0.body', null)->where('idea.comment_list.0.reported', true)); $this->actingAs($writer)->get("/ideen/{$this->idea->id}")->assertInertia(fn (Assert $p) => $p->where('idea.comment_list.0.body', 'Gemeiner Kommentar')); $this->actingAs($this->board)->put("/ideen/{$this->idea->id}/meldungen", ['action' => 'remove', 'comment_id' => $comment->id]); $this->assertSame(0, $this->idea->fresh()->comments_count); } }