Loheide-eu-mitarbeiterplatt.../tests/Feature/Birthdays/BirthdaysTest.php
Friederich Loheide ee8dde93c0
Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 2m18s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 2m21s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 2m40s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 2m34s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 3m8s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 3m6s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 2m43s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 2m47s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m1s
Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
- Formulare: Felder fest aus dem Profil (nicht änderbar, Server setzt den
  Profilwert ein), Hinweis bei fehlender Profilangabe
- Geburtstage (optionales Plugin, standardmäßig aus): Tag und Monat freiwillig
  im Profil, Kachel, Liste /geburtstage, Pagebuilder-Block, Glückwunsch am
  eigenen Geburtstag; Sichtbarkeit alle/Abteilung/Standort
- Startseite: Kacheln je Bereich sortieren und ausblenden; eigene Kacheln
  (Bild mit Link, Text, Hinweis) mit Zeitraum und Zielgruppe
- Kern: optionale mitgelieferte Plugins, Startseitenbereich „top“,
  Profilabschnitte für Plugins, Kachel-Bezeichnungen

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-26 09:51:19 +00:00

118 lines
5 KiB
PHP

<?php
namespace Tests\Feature\Birthdays;
use App\Models\User;
use App\Plugins\PluginManifest;
use App\Plugins\PluginState;
use App\Support\Settings;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Carbon;
use Inertia\Testing\AssertableInertia as Assert;
use Inhaus\Plugins\Birthdays\BirthdayList;
use Inhaus\Plugins\Birthdays\Models\Birthday;
use Tests\TestCase;
class BirthdaysTest extends TestCase
{
use RefreshDatabase;
private User $anna;
protected function setUp(): void
{
parent::setUp();
$this->travelTo(Carbon::create(2027, 3, 10, 9));
$this->anna = User::factory()->create(['first_name' => 'Anna', 'last_name' => 'Schmidt', 'department' => 'Pflege', 'location' => 'Hamburg']);
}
private function birthday(User $user, int $month, int $day): void
{
Birthday::query()->create(['user_id' => $user->id, 'month' => $month, 'day' => $day]);
}
public function test_plugin_is_optional_and_off_by_default(): void
{
$manifest = PluginManifest::fromDirectory(base_path('plugins-core/birthdays'), core: true);
$state = new PluginState(storage_path('framework/testing/plugins-'.uniqid().'.json'));
PluginState::$enableOptionalCorePlugins = false;
try {
$this->assertFalse($manifest->enabledByDefault);
$this->assertFalse($state->isEnabled($manifest));
$this->assertTrue($state->isEnabled(PluginManifest::fromDirectory(base_path('plugins-core/news'), core: true)));
$state->setEnabled('birthdays', true);
$this->assertTrue($state->isEnabled($manifest));
} finally {
PluginState::$enableOptionalCorePlugins = true;
}
}
public function test_people_opt_in_with_day_and_month_only(): void
{
$this->actingAs($this->anna)->get('/profil/bearbeiten')->assertInertia(fn (Assert $p) => $p
->where('sections.0.key', 'birthday')
->where('sections.0.props.birthday', null));
$this->put('/profil/geburtstag', ['day' => 31, 'month' => 4])->assertSessionHasErrors('day');
$this->put('/profil/geburtstag', ['day' => 29, 'month' => 2])->assertSessionHasNoErrors();
$this->put('/profil/geburtstag', ['day' => 12, 'month' => 3])->assertSessionHasNoErrors();
$this->assertSame(1, Birthday::query()->count());
$this->get('/profil/bearbeiten')->assertInertia(fn (Assert $p) => $p->where('sections.0.props.birthday', ['day' => 12, 'month' => 3]));
$this->delete('/profil/geburtstag');
$this->assertSame(0, Birthday::query()->count());
}
public function test_upcoming_birthdays_on_the_dashboard_and_list(): void
{
$ben = User::factory()->create(['first_name' => 'Ben', 'department' => 'Verwaltung']);
$cleo = User::factory()->create(['first_name' => 'Cleo', 'department' => 'Pflege']);
$gone = User::factory()->inactive()->create();
$this->birthday($ben, 3, 10); // heute
$this->birthday($cleo, 3, 14); // in 4 Tagen
$this->birthday($gone, 3, 11); // deaktiviert
$this->birthday(User::factory()->create(), 5, 1); // zu weit weg
$response = $this->actingAs($this->anna)->get('/');
$upcoming = $this->dashboardWidget($response, 'birthdays.upcoming')['birthdays'];
$this->assertSame([[$ben->id, true, '2027-03-10'], [$cleo->id, false, '2027-03-14']], array_map(fn ($b) => [$b['person']['id'], $b['today'], $b['date']], $upcoming));
$this->assertNull($this->dashboardWidget($response, 'birthdays.greeting'));
// Nur die eigene Abteilung
app(Settings::class)->set('birthdays.scope', 'department');
$this->assertSame([$cleo->id], array_map(fn ($b) => $b['person']['id'], app(BirthdayList::class)->upcoming($this->anna)));
$this->get('/geburtstage')->assertOk()->assertInertia(fn (Assert $p) => $p->component('birthdays::Index')->has('birthdays', 1)->where('registered', false));
}
public function test_birthday_person_is_congratulated(): void
{
$this->birthday($this->anna, 3, 10);
$response = $this->actingAs($this->anna)->get('/');
$this->assertSame(['name' => 'Anna'], $this->dashboardWidget($response, 'birthdays.greeting'));
app(Settings::class)->set('birthdays.greeting', false);
$this->assertNull($this->dashboardWidget($this->get('/'), 'birthdays.greeting'));
}
public function test_new_year_and_leap_day(): void
{
$this->travelTo(Carbon::create(2027, 12, 28));
$leap = User::factory()->create();
$newYear = User::factory()->create();
$this->birthday($newYear, 1, 2);
$this->birthday($leap, 2, 29);
$this->assertSame(['2028-01-02'], array_column(app(BirthdayList::class)->upcoming($this->anna, 7), 'date'));
// 2027 ist kein Schaltjahr: gefeiert wird am 28. Februar.
$this->travelTo(Carbon::create(2027, 2, 28, 8));
$this->assertTrue(app(BirthdayList::class)->isBirthdayToday($leap));
}
}