Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 3m36s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 3m32s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 4m1s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 3m54s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 5m16s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 5m15s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 4m38s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 4m33s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m15s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
93 lines
4.7 KiB
PHP
93 lines
4.7 KiB
PHP
<?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_search_page_without_query_opens_empty(): void
|
|
{
|
|
// Lupe im Kopf (Handy) führt ohne Suchbegriff auf die Seite
|
|
$this->actingAs(User::factory()->create())->get('/suche')->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->component('Search/Index')->where('query', '')->where('groups', []));
|
|
$this->actingAs(User::factory()->create())->getJson('/suche/live')->assertOk()->assertJson(['groups' => []]);
|
|
}
|
|
|
|
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']);
|
|
}
|
|
}
|