Loheide-eu-mitarbeiterplatt.../tests/Feature/Gemeinsam/GemeinsamTest.php
Friederich Loheide b50d089946
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Failing after 3m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Failing after 3m27s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Failing after 3m0s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Failing after 2m56s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 4m4s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 4m1s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 3m41s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 3m39s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m10s
QM-Texterkennung: Imagick nur mit Ghostscript als verfügbar melden
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 16:38:17 +00:00

92 lines
4.5 KiB
PHP

<?php
namespace Tests\Feature\Gemeinsam;
use App\Models\Role;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Birthdays\Models\Birthday;
use Inhaus\Plugins\Gemeinsam\Models\Entry;
use Tests\TestCase;
class GemeinsamTest extends TestCase
{
use RefreshDatabase;
private User $hr;
protected function setUp(): void
{
parent::setUp();
Carbon::setTestNow('2026-10-05 10:00');
$role = Role::query()->create(['name' => 'Personalabteilung']);
$role->grants()->create(['ability' => 'gemeinsam.manage']);
$this->hr = User::factory()->withRoles([$role])->create();
}
protected function tearDown(): void
{
Carbon::setTestNow();
parent::tearDown();
}
public function test_hr_maintains_all_sections_and_everyone_sees_the_month(): void
{
$new = User::factory()->create(['first_name' => 'Nora', 'last_name' => 'Neu', 'department' => 'Pflege', 'location' => 'Hamburg']);
$this->actingAs($this->hr);
$this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'user_id' => $new->id, 'date' => '2026-10-01'])->assertSessionHasNoErrors();
$this->post('/gemeinsam/eintraege', ['section' => 'transfer', 'name' => 'Tim Wechsel', 'from' => 'Werkstatt Nord', 'to' => 'Verwaltung', 'date' => '2026-10-15'])->assertSessionHasNoErrors();
$this->post('/gemeinsam/eintraege', ['section' => 'jubilee', 'name' => 'Jutta Jubel', 'label' => '25 Jahre', 'date' => '2026-10-20'])->assertSessionHasNoErrors();
$this->post('/gemeinsam/eintraege', ['section' => 'farewell', 'name' => 'Rolf Ruhestand', 'label' => 'Ruhestand', 'date' => '2026-10-31'])->assertSessionHasNoErrors();
$this->post('/gemeinsam/eintraege', ['section' => 'memoriam', 'name' => 'Gerda Gedenk', 'born_on' => '1958-03-12', 'date' => '2026-09-28', 'text' => 'Wir werden sie vermissen.'])->assertSessionHasNoErrors();
$this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'date' => '2026-10-01'])->assertSessionHasErrors('name');
$this->actingAs(User::factory()->create())->get('/gemeinsam')->assertOk()->assertInertia(fn (Assert $p) => $p
->component('gemeinsam::Index')
->where('month', '2026-10')
->where('canManage', false)
->where('sections.0.key', 'welcome')
->where('sections.0.entries.0.name', 'Nora Neu')
->where('sections.0.entries.0.department', 'Pflege', 'aus dem Profil')
->where('sections.1.entries.0.to', 'Verwaltung')
->where('sections.3.entries.0.label', '25 Jahre')
->where('sections.5.entries', []));
// Gedenken im September
$this->get('/gemeinsam?monat=2026-09')->assertInertia(fn (Assert $p) => $p
->where('sections.5.entries.0.name', 'Gerda Gedenk')
->where('sections.5.entries.0.born_on', '1958-03-12'));
}
public function test_birthdays_come_from_the_birthday_plugin(): void
{
$anna = User::factory()->create(['first_name' => 'Anna', 'last_name' => 'Oktober']);
Birthday::query()->create(['user_id' => $anna->id, 'month' => 10, 'day' => 14]);
Birthday::query()->create(['user_id' => User::factory()->inactive()->create()->id, 'month' => 10, 'day' => 2]);
Birthday::query()->create(['user_id' => User::factory()->create()->id, 'month' => 11, 'day' => 2]);
$this->actingAs(User::factory()->create())->get('/gemeinsam')->assertInertia(fn (Assert $p) => $p
->where('sections.2.key', 'birthdays')
->where('sections.2.automatic', true)
->has('sections.2.entries', 1)
->where('sections.2.entries.0.name', 'Anna Oktober')
->where('sections.2.entries.0.date', '2026-10-14'));
}
public function test_only_hr_can_change_entries(): void
{
$entry = Entry::query()->create(['section' => 'welcome', 'name' => 'X', 'date' => '2026-10-01']);
$this->actingAs(User::factory()->create());
$this->post('/gemeinsam/eintraege', ['section' => 'welcome', 'name' => 'Y', 'date' => '2026-10-01'])->assertForbidden();
$this->delete("/gemeinsam/eintraege/{$entry->id}")->assertForbidden();
$this->actingAs($this->hr)->put("/gemeinsam/eintraege/{$entry->id}", ['section' => 'welcome', 'name' => 'X Neu', 'date' => '2026-11-01'])->assertRedirect('/gemeinsam?monat=2026-11');
$this->delete("/gemeinsam/eintraege/{$entry->id}");
$this->assertSame(0, Entry::query()->count());
}
}