Globale Live-Suche, Kontaktkarten-Personensuche, neue Beitragsansicht, Termine mit Seitenleiste, Demo-Inhalte, Plugin-Upload-Fix
Some checks failed
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m24s
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m26s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m41s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 3m46s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m31s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m16s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m18s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m14s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-26 19:07:13 +00:00
parent 9b06e65802
commit b276e1c6d0
211 changed files with 3580 additions and 1072 deletions

View file

@ -0,0 +1,158 @@
<?php
namespace Tests\Feature;
use App\Filament\Pages\DemoContent as DemoContentPage;
use App\Models\DashboardTile;
use App\Models\User;
use App\Support\Demo\DemoContent;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
use Inhaus\Plugins\Downloads\Models\Download;
use Inhaus\Plugins\Downloads\Models\DownloadVersion;
use Inhaus\Plugins\Events\Models\Event;
use Inhaus\Plugins\Gemeinsam\Models\Entry;
use Inhaus\Plugins\News\Models\NewsCategory;
use Inhaus\Plugins\News\Models\NewsPost;
use Inhaus\Plugins\Pages\Models\Page;
use Inhaus\Plugins\Qm\Models\QmEntry;
use Inhaus\Plugins\Qm\Models\QmFile;
use Inhaus\Plugins\Qm\Models\QmFolder;
use Livewire\Livewire;
use RuntimeException;
use Tests\TestCase;
class DemoContentTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
Storage::fake('uploads');
Storage::fake('local');
Http::fake(['picsum.photos/*' => Http::response(UploadedFile::fake()->image('foto.jpg', 32, 18)->getContent(), 200, ['Content-Type' => 'image/jpeg'])]);
}
public function test_install_creates_tracked_content_and_remove_deletes_it(): void
{
$admin = User::factory()->admin()->create();
NewsCategory::query()->create(['name' => 'Unternehmen', 'slug' => 'unternehmen']);
$demo = app(DemoContent::class);
$result = $demo->install($admin);
$this->assertSame([], $result['warnings']);
$this->assertTrue($demo->isInstalled());
$this->assertSame(16, $result['counts']['Personen']);
$this->assertSame(16, User::query()->where('email', 'like', '%@demo.inhaus.invalid')->count());
$this->assertNotNull(User::query()->where('email', 'thomas.albers@demo.inhaus.invalid')->value('manager_id'));
$this->assertSame(16, NewsPost::query()->published()->count());
$this->assertSame(3, NewsPost::query()->where('is_featured', true)->count());
$post = NewsPost::query()->whereNotNull('cover_path')->firstOrFail();
Storage::disk('uploads')->assertExists($post->cover_path);
$this->assertStringContainsString('-thumb.webp', $post->coverUrl('thumb'));
$this->assertStringContainsString('<blockquote>', NewsPost::query()->where('slug', 'gemeinsam-zukunft-gestalten-unsere-strategie-2030')->value('body_html'));
$this->assertSame(8, Event::query()->upcoming()->count());
$this->assertSame(4, Page::query()->whereNotNull('content')->count());
$this->assertNotEmpty(Page::query()->where('path', 'mitarbeitervertretung')->firstOrFail()->content['blocks']);
$this->assertSame(6, Download::query()->count());
$version = DownloadVersion::query()->firstOrFail();
$this->assertStringStartsWith('%PDF-1.4', Storage::disk('local')->get($version->path));
$this->assertSame(5, QmFolder::query()->count());
$this->assertSame(10, QmEntry::query()->count());
$this->assertNotEmpty(app(Settings::class)->get('qm.home.intro'));
$qmFile = QmFile::query()->firstOrFail();
Storage::disk('local')->assertExists($qmFile->path);
$this->assertSame('ok', $qmFile->text_status);
$this->assertStringContainsString('Geltungsbereich', (string) $qmFile->text);
$this->assertSame(6, Entry::query()->count());
$this->assertSame(1, DashboardTile::query()->count());
$this->assertCount(10, app(Settings::class)->get('portal.quick_links'));
// Zweites Anlegen wird abgelehnt.
try {
$demo->install($admin);
$this->fail('Zweites Anlegen hätte abgelehnt werden müssen.');
} catch (RuntimeException $e) {
$this->assertStringContainsString('bereits angelegt', $e->getMessage());
}
// Ein Beitrag wurde inzwischen von Hand gelöscht – Entfernen bleibt fehlerfrei.
$post->delete();
$removed = $demo->remove();
$this->assertSame([], $removed['warnings']);
$this->assertFalse($demo->isInstalled());
$this->assertSame(0, User::query()->where('email', 'like', '%@demo.inhaus.invalid')->count());
$this->assertTrue(User::query()->whereKey($admin->id)->exists());
$this->assertSame(0, NewsPost::query()->count());
$this->assertSame(['unternehmen'], NewsCategory::query()->pluck('slug')->all());
$this->assertSame(0, Event::query()->count());
$this->assertSame(0, Page::query()->count());
$this->assertSame(0, Download::query()->count());
$this->assertSame(0, QmFolder::query()->count());
$this->assertSame(0, QmEntry::query()->count());
$this->assertSame(0, Entry::query()->count());
$this->assertSame(0, DashboardTile::query()->count());
$this->assertNull(app(Settings::class)->get('portal.quick_links'));
$this->assertNull(app(Settings::class)->get('qm.home.intro'));
$this->assertSame([], Storage::disk('uploads')->allFiles());
$this->assertSame([], Storage::disk('local')->allFiles());
// Doppeltes Entfernen schadet nicht.
$this->assertSame(['records' => 0, 'files' => 0, 'warnings' => []], $demo->remove());
}
public function test_existing_quick_links_are_kept_and_restored(): void
{
$links = [['label' => 'Intranet alt', 'url' => 'https://example.org', 'icon' => 'link', 'new_tab' => true]];
app(Settings::class)->set('portal.quick_links', $links);
$demo = app(DemoContent::class);
$demo->install(User::factory()->admin()->create());
$this->assertSame($links, app(Settings::class)->get('portal.quick_links'));
$demo->remove();
$this->assertSame($links, app(Settings::class)->get('portal.quick_links'));
}
public function test_images_fall_back_to_placeholders_without_network(): void
{
Http::fake(['picsum.photos/*' => Http::response('nicht gefunden', 404)]);
app(DemoContent::class)->install(User::factory()->admin()->create());
$path = Event::query()->whereNotNull('image_path')->value('image_path');
Storage::disk('uploads')->assertExists($path);
$this->assertSame('image/jpeg', getimagesizefromstring(Storage::disk('uploads')->get($path))['mime']);
}
public function test_admin_page_installs_and_removes_and_is_forbidden_for_others(): void
{
$this->actingAs(User::factory()->create())->get('/admin/demo-inhalte')->assertForbidden();
$admin = User::factory()->admin()->create();
$this->actingAs($admin)->get('/admin/demo-inhalte')->assertOk()
->assertSee('Keine Demo-Inhalte angelegt.')
->assertSee('Demo-Inhalte anlegen');
Livewire::test(DemoContentPage::class)->call('install')->assertNotified('Demo-Inhalte angelegt');
$this->assertTrue(app(DemoContent::class)->isInstalled());
$this->get('/admin/demo-inhalte')->assertOk()->assertSee('Demo-Inhalte entfernen')->assertSee('Personen');
Livewire::test(DemoContentPage::class)->call('remove')->assertNotified('Demo-Inhalte entfernt');
$this->assertFalse(app(DemoContent::class)->isInstalled());
}
}

View file

@ -382,12 +382,21 @@ class PluginSystemTest extends TestCase
Livewire::test(Plugins::class)
->set('archive', UploadedFile::fake()->createWithContent('plugin.zip', file_get_contents($zip)))
->call('upload')
->call('installArchive')
->assertHasNoErrors();
$this->assertFileExists($this->dir.'/custom/seite-hochgeladen/plugin.json');
}
public function test_upload_form_does_not_use_livewires_reserved_upload_method(): void
{
// $wire.upload() ist Livewires eigene Datei-Upload-Funktion – ein gleichnamiger
// Formular-Handler wird im Browser nie aufgerufen.
$view = file_get_contents(resource_path('views/filament/pages/plugins.blade.php'));
$this->assertStringNotContainsString('wire:submit="upload"', $view);
$this->assertFalse(method_exists(Plugins::class, 'upload'));
}
private function zipDirectory(string $source, string $prefix): string
{
$zip = $this->dir.'/'.basename($source).'-'.bin2hex(random_bytes(2)).'.zip';

View file

@ -0,0 +1,85 @@
<?php
namespace Tests\Feature\Search;
use App\Models\User;
use App\Search\GlobalSearch;
use App\Support\ContactCards;
use App\Support\Permissions\Audiences;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
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 GlobalSearchTest extends TestCase
{
use RefreshDatabase;
public function test_live_search_finds_visible_news_and_events_but_no_people(): void
{
$user = User::factory()->create(['department' => 'Werkstatt']);
User::factory()->create(['first_name' => 'Sommer', 'last_name' => 'Fest']);
NewsPost::factory()->create(['title' => 'Sommerfest 2026: Jetzt anmelden', 'body' => '<p>Musik und Essen</p>']);
NewsPost::factory()->draft()->create(['title' => 'Sommerfest intern (Entwurf)']);
$care = NewsCategory::query()->create(['name' => 'Pflege intern', 'slug' => 'pflege-intern']);
Audiences::sync('news_category', $care->id, ['department' => ['Pflege']]);
NewsPost::factory()->create(['title' => 'Sommerfest nur für die Pflege', 'category_id' => $care->id]);
Event::factory()->create(['title' => 'Sommerfest am See', 'is_published' => true, 'starts_at' => now()->addWeek()]);
$groups = collect($this->actingAs($user)->getJson('/suche/live?q=sommerfest')->assertOk()->json('groups'))->keyBy('key');
$this->assertSame(['Sommerfest 2026: Jetzt anmelden'], array_column($groups['news']['items'], 'title'));
$this->assertSame(['Sommerfest am See'], array_column($groups['events']['items'], 'title'));
$this->assertArrayNotHasKey('people', $groups->all());
}
public function test_all_terms_must_match_and_short_queries_return_nothing(): void
{
$user = User::factory()->create();
NewsPost::factory()->create(['title' => 'Neue Software für die Dienstplanung', 'body' => '<p>Ab Juni</p>']);
NewsPost::factory()->create(['title' => 'Neue Kantine', 'body' => '<p>Ab Juni</p>']);
$groups = $this->actingAs($user)->getJson('/suche/live?q='.urlencode('neue dienstplanung'))->json('groups');
$this->assertSame(['Neue Software für die Dienstplanung'], array_column($groups[0]['items'], 'title'));
$this->actingAs($user)->getJson('/suche/live?q=n')->assertJson(['groups' => []]);
}
public function test_results_page_and_broken_source_does_not_break_search(): void
{
app(GlobalSearch::class)->add('kaputt', 'Kaputt', 'bug', fn () => throw new \RuntimeException('weg'));
NewsPost::factory()->create(['title' => 'Blühwiese am Standort']);
$this->actingAs(User::factory()->create())->get('/suche?q=blühwiese')->assertOk()->assertInertia(fn (Assert $page) => $page
->component('Search/Index')
->where('query', 'blühwiese')
->has('groups', 1)
->where('groups.0.items.0.title', 'Blühwiese am Standort'));
}
public function test_excerpt_centers_on_the_match(): void
{
$text = str_repeat('Füllwort ', 60).'Hier steht der Treffer Dienstplan im Text. '.str_repeat('Ende ', 40);
$excerpt = GlobalSearch::excerpt("<p>{$text}</p>", 'dienstplan');
$this->assertStringStartsWith('… ', $excerpt);
$this->assertStringContainsString('Treffer Dienstplan', $excerpt);
}
public function test_people_cards_show_the_configured_fields(): void
{
app(Settings::class)->set(ContactCards::PEOPLE_SEARCH_FIELDS, ['email', 'phone']);
User::factory()->create(['first_name' => 'Friederich', 'last_name' => 'Loheide', 'job_title' => 'Leitung', 'department' => 'IT', 'phone' => '05482 72-295', 'email' => 'f.loheide@example.com']);
User::factory()->inactive()->create(['first_name' => 'Alt', 'last_name' => 'Loheide']);
$data = $this->actingAs(User::factory()->create())->getJson('/personen/karten?q=loheide')->assertOk()->json();
$this->assertSame(1, $data['total']);
$this->assertSame('Leitung · IT', $data['people'][0]['subtitle']);
$this->assertSame(['email', 'phone'], array_column($data['people'][0]['fields'], 'key'));
$this->assertSame('phone', $data['people'][0]['fields'][1]['type']);
}
}