Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 12m25s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 12m51s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 10m43s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 10m37s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 12m42s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 13m38s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 9m39s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 9m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 44s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m10s
- Ladefehler während eines Updates schalten keine Plugins mehr ab: Wartungsmodus merkt sich den Update-Zeitraum (+2 min Nachlauf), Plugin-Uploads markieren den Dateiaustausch ohne Wartungsmodus; guard/recoverFromCrash prüfen das, betroffene Plugins (mit disabled_at im Zeitraum) werden wieder eingeschaltet - Plugin-Oberflächen werden nach public/plugin-assets kopiert (Webserver statt PHP), bei Deaktivieren/Löschen/Neu-Hochladen entfernt; Route bleibt als Rückfall - RichTextEditor in SDK, Leichte-Sprache-Leiste und Glossar asynchron; fehlende Menü-Symbole kuratiert → kein Laden des kompletten Symbolsatzes - Inertia-Prefetch (hover, 10 s) für Menülinks und Neuigkeiten-Vorschauen; Prefetch zählt nicht als Lesen (Reach) Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
109 lines
5.6 KiB
PHP
109 lines
5.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\News;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\News\Models\NewsComment;
|
|
use Inhaus\Plugins\News\Models\NewsPost;
|
|
use Tests\TestCase;
|
|
|
|
class LikesAndReachTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_people_can_give_and_take_back_a_heart(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
|
|
|
$this->actingAs($user)->post("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
|
$this->actingAs($user)->post("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
|
$this->assertSame(1, DB::table('news_likes')->where('post_id', $post->id)->count());
|
|
|
|
$this->actingAs($user)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
|
|
->where('post.likes', 1)->where('post.liked', true)->where('reach', null));
|
|
|
|
$this->actingAs($user)->delete("/neuigkeiten/{$post->slug}/herz")->assertRedirect();
|
|
$this->assertSame(0, DB::table('news_likes')->count());
|
|
}
|
|
|
|
public function test_hidden_or_unpublished_posts_cannot_get_hearts(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$draft = NewsPost::factory()->create(['status' => NewsPost::DRAFT, 'published_at' => null]);
|
|
|
|
$this->actingAs($user)->post("/neuigkeiten/{$draft->slug}/herz")->assertNotFound();
|
|
}
|
|
|
|
public function test_reach_is_anonymous_and_only_for_editors(): void
|
|
{
|
|
$admin = User::factory()->admin()->create();
|
|
$readers = User::factory()->count(3)->create();
|
|
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
|
|
|
foreach ($readers as $reader) {
|
|
$this->actingAs($reader)->get("/neuigkeiten/{$post->slug}")->assertOk();
|
|
$this->actingAs($reader)->get("/neuigkeiten/{$post->slug}")->assertOk();
|
|
}
|
|
|
|
$this->actingAs($readers[0])->post("/neuigkeiten/{$post->slug}/herz");
|
|
|
|
// Gespeichert wird kein Personenbezug
|
|
$this->assertSame(3, DB::table('news_reads')->where('post_id', $post->id)->count());
|
|
$this->assertFalse(DB::table('news_reads')->whereIn('reader', $readers->pluck('id')->map(fn ($id) => (string) $id))->exists());
|
|
|
|
$this->actingAs($admin)->get("/neuigkeiten/{$post->slug}")->assertInertia(fn (Assert $page) => $page
|
|
->where('reach.readers', 4)
|
|
->where('reach.likes', 1)
|
|
->where('reach.likers', [$readers[0]->name])
|
|
->where('reach.share', 100));
|
|
}
|
|
|
|
public function test_hearts_via_the_api(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
|
$headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken];
|
|
|
|
$this->postJson("/api/v1/news/{$post->slug}/like", [], $headers)->assertOk()->assertJsonPath('data.likes', 1)->assertJsonPath('data.liked', true);
|
|
$this->getJson('/api/v1/news', $headers)->assertJsonPath('data.0.likes', 1)->assertJsonPath('data.0.liked', true);
|
|
$this->getJson("/api/v1/news/{$post->slug}", $headers)->assertJsonPath('data.liked', true);
|
|
$this->deleteJson("/api/v1/news/{$post->slug}/like", [], $headers)->assertOk()->assertJsonPath('data.likes', 0);
|
|
}
|
|
|
|
public function test_previews_show_hearts_and_comments_before_opening(): void
|
|
{
|
|
[$ada, $bob] = User::factory()->count(2)->create()->all();
|
|
$post = NewsPost::factory()->create(['published_at' => now()->subHour(), 'title' => 'Sommerfest']);
|
|
$quiet = NewsPost::factory()->create(['published_at' => now()->subHours(2), 'comments_enabled' => false]);
|
|
DB::table('news_likes')->insert([['post_id' => $post->id, 'user_id' => $ada->id, 'created_at' => now()], ['post_id' => $post->id, 'user_id' => $bob->id, 'created_at' => now()]]);
|
|
NewsComment::query()->create(['post_id' => $post->id, 'user_id' => $ada->id, 'body' => 'Super!']);
|
|
NewsComment::query()->create(['post_id' => $post->id, 'user_id' => $bob->id, 'body' => 'Bin dabei']);
|
|
NewsComment::query()->create(['post_id' => $post->id, 'user_id' => $bob->id, 'body' => 'Gelöscht'])->delete();
|
|
|
|
$this->actingAs($ada)->get('/neuigkeiten')->assertInertia(fn (Assert $page) => $page
|
|
->where('posts.data.0.likes', 2)->where('posts.data.0.liked', true)->where('posts.data.0.comments', 2)
|
|
->where('posts.data.1.comments', null));
|
|
|
|
// Startseite (Widget „Neuigkeiten“) und die App bekommen dieselben Zahlen
|
|
$this->actingAs($bob)->get('/')->assertOk()->assertSee('"comments":2', false);
|
|
$headers = ['Authorization' => 'Bearer '.$bob->createToken('App')->plainTextToken];
|
|
$this->getJson('/api/v1/news', $headers)->assertJsonPath('data.0.likes', 2)->assertJsonPath('data.0.comments', 2)->assertJsonPath('data.1.comments', null);
|
|
$this->assertSame($quiet->id, $this->getJson('/api/v1/news', $headers)->json('data.1.id'));
|
|
}
|
|
|
|
public function test_prefetching_a_post_does_not_count_as_reading(): void
|
|
{
|
|
$post = NewsPost::factory()->create(['published_at' => now()->subHour()]);
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->get("/neuigkeiten/{$post->slug}", ['Purpose' => 'prefetch'])->assertOk();
|
|
$this->assertSame(0, DB::table('news_reads')->count());
|
|
|
|
$this->actingAs($user)->get("/neuigkeiten/{$post->slug}")->assertOk();
|
|
$this->assertSame(1, DB::table('news_reads')->count());
|
|
}
|
|
}
|