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)); } }