Loheide-eu-mitarbeiterplatt.../tests/Feature/FeedTest.php
Friederich Loheide 8acc0cfd8b
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 15m6s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 15m58s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 15m42s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 15m21s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1h1m41s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1h2m13s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 23m20s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 23m33s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 1m17s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m57s
Feed in der Mitarbeiter-App (0.54.0)
Feed-Registry mit Anbietern (Neu im Team, Neuigkeiten, Termine, Umfragen),
Schnellaktionen je nach Rechten, Nachladen über /feed.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-30 14:27:23 +00:00

80 lines
3.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace Tests\Feature;
use App\Feed\Feed;
use App\Models\Role;
use App\Models\User;
use App\Plugins\PluginAccess;
use App\Support\Theme\Theme;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\News\Models\NewsPost;
use Tests\TestCase;
class FeedTest extends TestCase
{
use RefreshDatabase;
public function test_feed_mixes_news_and_new_colleagues_by_time_and_pages(): void
{
$author = User::factory()->create(['first_name' => 'Vanessa', 'last_name' => 'Meißner']);
$newcomer = User::factory()->create(['first_name' => 'Irmtraud', 'last_name' => 'Beckmann']);
foreach (range(1, 12) as $i) {
NewsPost::factory()->create(['title' => "Beitrag {$i}", 'author_id' => $author->id, 'published_at' => now()->subDays($i)]);
}
$viewer = User::factory()->create();
// Nur Irmtraud ist neu – alle anderen (auch von Fabriken angelegte) schon länger da
User::query()->whereKeyNot($newcomer->id)->update(['created_at' => now()->subYear()]);
$newcomer->forceFill(['created_at' => now()->subHours(3)])->save();
$page = app(Feed::class)->page($viewer, limit: 10);
$this->assertCount(10, $page['items']);
$this->assertSame('welcome', $page['items'][0]['kind']);
$this->assertSame('Irmtraud Beckmann ist neu im Team', $page['items'][0]['title']);
$this->assertSame('Beitrag 1', $page['items'][1]['title']);
$this->assertSame('Vanessa Meißner', $page['items'][1]['actor']['name']);
$this->assertNotNull($page['next']);
// Nächste Seite über die Schnittstelle
$this->actingAs($viewer)->getJson('/feed?vor='.urlencode($page['next']))
->assertOk()
->assertJsonPath('items.0.title', 'Beitrag 10')
->assertJsonCount(3, 'items')
->assertJsonPath('next', null);
}
public function test_blocked_plugins_stay_out_of_the_feed(): void
{
$clients = Role::query()->create(['name' => 'Klienten']);
NewsPost::factory()->create(['title' => 'Nur für Mitarbeitende', 'published_at' => now()->subHour()]);
app(PluginAccess::class)->exclude('news', [$clients->id]);
$client = User::factory()->withRoles([$clients])->create();
$this->assertNotContains('Nur für Mitarbeitende', array_column(app(Feed::class)->page($client)['items'], 'title'));
$this->assertContains('Nur für Mitarbeitende', array_column(app(Feed::class)->page(User::factory()->create())['items'], 'title'));
}
public function test_app_start_page_carries_feed_and_actions_by_right(): void
{
$theme = app(Theme::class);
$theme->saveDraft(['interface' => 'app']);
app()->call([$theme, 'publish']);
NewsPost::factory()->create(['title' => 'Sommerfest', 'published_at' => now()->subHour()]);
$this->actingAs(User::factory()->create())->get('/')->assertInertia(fn (Assert $page) => $page
->where('feed.items.0.title', 'Sommerfest')
->where('feedActions', fn ($actions) => ! collect($actions)->contains('label', 'Beitrag schreiben') && collect($actions)->contains('label', 'Problem melden')));
$role = Role::query()->create(['name' => 'Redaktion']);
$role->grants()->create(['ability' => 'news.manage']);
$this->actingAs(User::factory()->withRoles([$role])->create())->get('/')->assertInertia(fn (Assert $page) => $page
->where('feedActions.0.label', 'Beitrag schreiben'));
}
public function test_classic_start_page_has_no_feed(): void
{
$this->actingAs(User::factory()->create())->get('/')->assertInertia(fn (Assert $page) => $page->where('feed', null));
}
}