Ideenbox-Moderation und Wochenüberblick per E-Mail (0.36.0)
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
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>
This commit is contained in:
parent
11c5ef5baf
commit
f9922f7308
172 changed files with 1524 additions and 363 deletions
113
tests/Feature/Digest/WeeklyDigestTest.php
Normal file
113
tests/Feature/Digest/WeeklyDigestTest.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature\Digest;
|
||||
|
||||
use App\Digest\Digest;
|
||||
use App\Mail\WeeklyDigest;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Illuminate\Support\Facades\URL;
|
||||
use Inertia\Testing\AssertableInertia as Assert;
|
||||
use Inhaus\Plugins\Events\Models\Event;
|
||||
use Inhaus\Plugins\News\Models\NewsCategory;
|
||||
use Inhaus\Plugins\News\Models\NewsPost;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WeeklyDigestTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function monday(int $hour): void
|
||||
{
|
||||
Carbon::setTestNow(Carbon::parse('2026-10-19 '.$hour.':05', config('app.timezone')));
|
||||
}
|
||||
|
||||
public function test_only_opted_in_people_get_it_on_the_configured_day(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$this->monday(6);
|
||||
$in = User::factory()->create(['weekly_digest' => true]);
|
||||
User::factory()->create(['weekly_digest' => false]);
|
||||
User::factory()->create(['weekly_digest' => true, 'is_active' => false]);
|
||||
NewsPost::factory()->create(['title' => 'Neues Dienstrad-Angebot', 'published_at' => now()->subDays(2)]);
|
||||
NewsPost::factory()->create(['title' => 'Uralt', 'published_at' => now()->subDays(20)]);
|
||||
|
||||
$this->assertSame(0, app(Digest::class)->sendDue()); // vor 7 Uhr
|
||||
$this->monday(7);
|
||||
$this->assertSame(1, app(Digest::class)->sendDue());
|
||||
$this->assertSame(0, app(Digest::class)->sendDue()); // nicht doppelt
|
||||
|
||||
Mail::assertQueued(WeeklyDigest::class, fn (WeeklyDigest $mail) => $mail->hasTo($in->email)
|
||||
&& collect($mail->sections)->firstWhere('key', 'news')['items'][0]['title'] === 'Neues Dienstrad-Angebot'
|
||||
&& count(collect($mail->sections)->firstWhere('key', 'news')['items']) === 1);
|
||||
Mail::assertQueuedCount(1);
|
||||
}
|
||||
|
||||
public function test_content_respects_visibility_and_empty_weeks_send_nothing(): void
|
||||
{
|
||||
Mail::fake();
|
||||
$this->monday(8);
|
||||
$pflege = Role::query()->create(['name' => 'Pflege']);
|
||||
$user = User::factory()->create(['weekly_digest' => true]);
|
||||
$secret = NewsCategory::factory()->create();
|
||||
Audiences::sync('news_category', $secret->id, ['role' => [(string) $pflege->id]]);
|
||||
NewsPost::factory()->create(['category_id' => $secret->id, 'published_at' => now()->subDay()]);
|
||||
|
||||
$this->assertSame(0, app(Digest::class)->sendDue());
|
||||
|
||||
Event::factory()->create(['title' => 'Sommerfest', 'starts_at' => now()->addDays(3), 'is_published' => true]);
|
||||
$user->forceFill(['digest_sent_at' => null])->save();
|
||||
$this->assertSame(1, app(Digest::class)->sendDue());
|
||||
|
||||
Mail::assertQueued(WeeklyDigest::class, fn ($mail) => collect($mail->sections)->pluck('key')->all() === ['events']);
|
||||
}
|
||||
|
||||
public function test_mail_renders_with_unsubscribe_header(): void
|
||||
{
|
||||
$user = User::factory()->create(['first_name' => 'Ada', 'weekly_digest' => true]);
|
||||
$mail = new WeeklyDigest($user, [['key' => 'news', 'label' => 'Neuigkeiten', 'items' => [['title' => 'Hallo Welt', 'url' => 'https://x.test/a', 'meta' => 'Heute']]]], now()->toImmutable()->subDays(7));
|
||||
|
||||
$mail->assertSeeInHtml('Hallo Ada');
|
||||
$mail->assertSeeInHtml('Hallo Welt');
|
||||
$mail->assertSeeInHtml('Abbestellen');
|
||||
$this->assertStringContainsString('One-Click', $mail->headers()->text['List-Unsubscribe-Post']);
|
||||
}
|
||||
|
||||
public function test_profile_toggle_and_signed_unsubscribe(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user)->get('/profil/bearbeiten')->assertInertia(fn (Assert $p) => $p->where('digest.enabled', false)->where('digest.schedule', 'montags ab 7 Uhr'));
|
||||
$this->actingAs($user)->put('/profil/wochenueberblick', ['enabled' => true])->assertRedirect();
|
||||
$this->assertTrue($user->fresh()->weekly_digest);
|
||||
|
||||
auth()->logout();
|
||||
$url = URL::signedRoute('digest.unsubscribe', ['user' => $user->id]);
|
||||
$this->get($url)->assertOk()->assertInertia(fn (Assert $p) => $p->component('DigestUnsubscribe')->where('done', false));
|
||||
$this->assertTrue($user->fresh()->weekly_digest); // Aufruf allein bestellt nicht ab
|
||||
$this->post($url)->assertOk();
|
||||
$this->assertFalse($user->fresh()->weekly_digest);
|
||||
|
||||
$other = User::factory()->create(['weekly_digest' => true]);
|
||||
$this->post(str_replace('/abbestellen/'.$user->id, '/abbestellen/'.$other->id, $url))->assertForbidden();
|
||||
$this->assertTrue($other->fresh()->weekly_digest);
|
||||
$this->post('/wochenueberblick/abbestellen/'.$user->id)->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_admin_can_turn_it_off_completely(): void
|
||||
{
|
||||
app(Settings::class)->set('digest.enabled', false);
|
||||
$user = User::factory()->create(['weekly_digest' => true]);
|
||||
|
||||
$this->actingAs($user)->get('/profil/bearbeiten')->assertInertia(fn (Assert $p) => $p->where('digest', null));
|
||||
$this->monday(9);
|
||||
$this->assertSame(0, app(Digest::class)->sendDue());
|
||||
|
||||
$this->actingAs(User::factory()->admin()->create())->get('/admin/wochenueberblick')->assertOk();
|
||||
}
|
||||
}
|
||||
92
tests/Feature/Ideen/ModerationTest.php
Normal file
92
tests/Feature/Ideen/ModerationTest.php
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
<?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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue