Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m49s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m19s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m29s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m39s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 9m38s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 9m25s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 7m57s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 8m4s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 46s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m9s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
92 lines
4.4 KiB
PHP
92 lines
4.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Ideen;
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use App\Notifications\PortalNotification;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\Ideen\Models\Idea;
|
|
use Inhaus\Plugins\Ideen\Models\IdeaReport;
|
|
use Tests\TestCase;
|
|
|
|
class ModerationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $board;
|
|
|
|
private User $author;
|
|
|
|
private Idea $idea;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$role = Role::query()->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);
|
|
}
|
|
}
|