Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 6m52s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 6m46s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 7m6s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 7m2s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 6m29s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 6m31s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 5m54s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 5m58s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m17s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
76 lines
3.4 KiB
PHP
76 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Glossar;
|
|
|
|
use App\Models\Role;
|
|
use App\Models\User;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Inertia\Testing\AssertableInertia as Assert;
|
|
use Inhaus\Plugins\Glossar\Models\GlossaryEntry;
|
|
use Tests\TestCase;
|
|
|
|
class GlossarTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
private User $editor;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$role = Role::query()->create(['name' => 'Glossar']);
|
|
$role->grants()->create(['ability' => 'glossary.manage']);
|
|
$this->editor = User::factory()->withRoles([$role])->create();
|
|
}
|
|
|
|
public function test_entries_are_sorted_alphabetically_with_umlauts_and_numbers(): void
|
|
{
|
|
foreach (['Zeiterfassung', 'Überstunden', 'Arbeitszeit', '24-Stunden-Dienst', 'Ärztlicher Dienst', 'Budget'] as $term) {
|
|
GlossaryEntry::query()->create(['term' => $term]);
|
|
}
|
|
|
|
$this->actingAs(User::factory()->create())->get('/glossar')->assertOk()->assertInertia(fn (Assert $page) => $page
|
|
->component('glossar::Index')
|
|
->where('canManage', false)
|
|
->where('entries', fn ($entries) => collect($entries)->pluck('term')->all() === ['24-Stunden-Dienst', 'Arbeitszeit', 'Ärztlicher Dienst', 'Budget', 'Überstunden', 'Zeiterfassung']
|
|
&& collect($entries)->pluck('letter')->all() === ['#', 'A', 'A', 'B', 'U', 'Z']));
|
|
}
|
|
|
|
public function test_editors_maintain_entries_in_the_portal(): void
|
|
{
|
|
$this->actingAs($this->editor)->get('/glossar')->assertInertia(fn (Assert $page) => $page->where('canManage', true));
|
|
$this->assertFalse($this->editor->canAccessAdmin(), 'Glossar pflegen braucht kein Backend');
|
|
|
|
$this->post('/glossar', [
|
|
'term' => 'Dienstvereinbarung', 'aliases' => 'DV',
|
|
'description' => '<p>Vereinbarung zwischen <strong>MAV</strong> und Dienstgeber<script>alert(1)</script></p>',
|
|
'link_url' => 'javascript:alert(1)',
|
|
])->assertRedirect()->assertSessionHasNoErrors();
|
|
|
|
$entry = GlossaryEntry::query()->sole();
|
|
$this->assertSame('D', $entry->letter);
|
|
$this->assertStringContainsString('<strong>MAV</strong>', $entry->description);
|
|
$this->assertStringNotContainsString('script', $entry->description);
|
|
$this->assertNull($entry->link_url);
|
|
|
|
$this->post('/glossar', ['term' => 'dienstvereinbarung'])->assertSessionHasErrors(['term' => 'Diesen Begriff gibt es schon im Glossar.']);
|
|
|
|
$this->put("/glossar/{$entry->id}", ['term' => 'Dienstvereinbarung', 'link_url' => '/seiten/mav', 'link_label' => 'Zur MAV'])->assertSessionHasNoErrors();
|
|
$this->assertSame('/seiten/mav', $entry->fresh()->link_url);
|
|
|
|
$this->delete("/glossar/{$entry->id}")->assertRedirect();
|
|
$this->assertSame(0, GlossaryEntry::query()->count());
|
|
}
|
|
|
|
public function test_others_cannot_edit_and_entries_are_found_in_the_global_search(): void
|
|
{
|
|
$entry = GlossaryEntry::query()->create(['term' => 'Rufbereitschaft', 'description' => '<p>Erreichbar außerhalb der Dienstzeit</p>']);
|
|
$user = User::factory()->create();
|
|
|
|
$this->actingAs($user)->post('/glossar', ['term' => 'x'])->assertForbidden();
|
|
$this->actingAs($user)->delete("/glossar/{$entry->id}")->assertForbidden();
|
|
|
|
$this->getJson('/suche/live?q=Rufbereit')->assertOk()->assertJsonFragment(['url' => '/glossar#begriff-'.$entry->id]);
|
|
}
|
|
}
|