Feste Profilfelder in Formularen, Geburtstage, anpassbare Startseite
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
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
- 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>
This commit is contained in:
parent
435960725d
commit
ee8dde93c0
262 changed files with 2385 additions and 692 deletions
118
tests/Feature/Birthdays/BirthdaysTest.php
Normal file
118
tests/Feature/Birthdays/BirthdaysTest.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?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));
|
||||
}
|
||||
}
|
||||
95
tests/Feature/DashboardCustomizationTest.php
Normal file
95
tests/Feature/DashboardCustomizationTest.php
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Filament\Pages\DashboardSettings;
|
||||
use App\Filament\Resources\DashboardTiles\Pages\ManageDashboardTiles;
|
||||
use App\Models\DashboardTile;
|
||||
use App\Models\User;
|
||||
use App\Support\Permissions\Audiences;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Livewire\Livewire;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DashboardCustomizationTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
private function keys(User $user, string $area): array
|
||||
{
|
||||
$widgets = $this->actingAs($user)->get('/')->viewData('page')['props']['widgets'];
|
||||
|
||||
return array_values(array_column(array_filter($widgets, fn ($w) => $w['area'] === $area), 'key'));
|
||||
}
|
||||
|
||||
public function test_admin_adds_an_image_tile_with_link(): void
|
||||
{
|
||||
Storage::fake('uploads');
|
||||
$admin = User::factory()->admin()->create();
|
||||
$this->actingAs($admin);
|
||||
|
||||
Livewire::test(ManageDashboardTiles::class)
|
||||
->callAction('create', [
|
||||
'name' => 'Betriebsrat-Banner',
|
||||
'type' => 'image',
|
||||
'area' => 'aside',
|
||||
'image_path' => UploadedFile::fake()->image('banner.jpg', 800, 600),
|
||||
'url' => 'intranet.example.org/aktion',
|
||||
'alt' => 'Aktion Gesundheit',
|
||||
'is_active' => true,
|
||||
])
|
||||
->assertHasNoActionErrors();
|
||||
|
||||
$tile = DashboardTile::query()->sole();
|
||||
$this->assertSame('https://intranet.example.org/aktion', $tile->url);
|
||||
|
||||
$props = $this->dashboardWidget($this->get('/'), $tile->widgetKey());
|
||||
$this->assertSame('image', $props['tile']['type']);
|
||||
$this->assertSame('Aktion Gesundheit', $props['tile']['alt']);
|
||||
$this->assertNotNull($props['tile']['image_url']);
|
||||
}
|
||||
|
||||
public function test_tiles_respect_period_and_audience(): void
|
||||
{
|
||||
$nurse = User::factory()->create(['department' => 'Pflege']);
|
||||
$clerk = User::factory()->create(['department' => 'Verwaltung']);
|
||||
|
||||
$notice = DashboardTile::query()->create(['name' => 'Hinweis', 'type' => 'notice', 'area' => 'top', 'title' => 'Heute Betriebsversammlung', 'body' => '<p>14 Uhr <script>x</script></p>', 'variant' => 'info']);
|
||||
$expired = DashboardTile::query()->create(['name' => 'Alt', 'type' => 'text', 'area' => 'aside', 'body' => 'x', 'ends_at' => now()->subDay()]);
|
||||
$inactive = DashboardTile::query()->create(['name' => 'Aus', 'type' => 'text', 'area' => 'aside', 'body' => 'x', 'is_active' => false]);
|
||||
Audiences::sync('dashboard_tile', $notice->id, ['department' => ['Pflege']]);
|
||||
|
||||
$this->assertSame(['tile.'.$notice->id], $this->keys($nurse, 'top'));
|
||||
$this->assertSame([], $this->keys($clerk, 'top'));
|
||||
$this->assertNotContains($expired->widgetKey(), $this->keys($nurse, 'aside'));
|
||||
$this->assertNotContains($inactive->widgetKey(), $this->keys($nurse, 'aside'));
|
||||
$this->assertStringNotContainsString('script', $notice->fresh()->body_html);
|
||||
}
|
||||
|
||||
public function test_admin_reorders_and_hides_tiles(): void
|
||||
{
|
||||
$admin = User::factory()->admin()->create();
|
||||
$tile = DashboardTile::query()->create(['name' => 'Banner', 'type' => 'text', 'area' => 'aside', 'body' => 'Hallo']);
|
||||
|
||||
$default = $this->keys($admin, 'aside');
|
||||
$this->assertSame('core.greeting', $default[0]);
|
||||
$this->assertSame($tile->widgetKey(), end($default), 'Neue eigene Kacheln stehen zunächst am Ende.');
|
||||
|
||||
$page = Livewire::actingAs($admin)->test(DashboardSettings::class);
|
||||
$aside = collect($page->get('data.aside'))->values();
|
||||
$this->assertContains('Eigene Kachel: Banner', $aside->pluck('label'));
|
||||
|
||||
// Eigene Kachel nach oben, „Personen finden“ ausblenden
|
||||
$reordered = $aside->sortBy(fn ($item) => $item['key'] === $tile->widgetKey() ? 0 : 1)->values()
|
||||
->map(fn ($item) => $item['key'] === 'core.people-search' ? [...$item, 'visible' => false] : $item)->all();
|
||||
$page->set('data.aside', $reordered)->call('save')->assertHasNoErrors();
|
||||
|
||||
$keys = $this->keys($admin, 'aside');
|
||||
$this->assertSame($tile->widgetKey(), $keys[0]);
|
||||
$this->assertNotContains('core.people-search', $keys);
|
||||
|
||||
$this->actingAs(User::factory()->create())->get('/admin/startseite')->assertForbidden();
|
||||
}
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Tests\Feature\Forms;
|
||||
|
||||
use App\Models\ProfileField;
|
||||
use App\Models\Role;
|
||||
use App\Models\User;
|
||||
use App\Notifications\PortalNotification;
|
||||
|
|
@ -339,4 +340,52 @@ class FormsTest extends TestCase
|
|||
Audiences::sync('form', $form->id, ['department' => ['Verwaltung']]);
|
||||
$this->assertSame([], $content->render($content->sanitize(['blocks' => [['type' => 'forms.form', 'data' => ['form' => (string) $form->id]]]]), $this->employee)['blocks']);
|
||||
}
|
||||
|
||||
public function test_locked_profile_fields_always_use_the_profile_value(): void
|
||||
{
|
||||
ProfileField::query()->create(['key' => 'personalnummer', 'label' => 'Personalnummer', 'editable' => false]);
|
||||
$this->employee->update(['custom_fields' => ['personalnummer' => 'P-4711'], 'location' => null]);
|
||||
|
||||
$form = Form::query()->create(['title' => 'Stammdaten', 'fields' => [
|
||||
['type' => 'text', 'data' => ['label' => 'Vorname', 'prefill' => 'first_name', 'locked' => true, 'required' => true]],
|
||||
['type' => 'text', 'data' => ['label' => 'Personalnummer', 'prefill' => 'custom.personalnummer', 'locked' => true, 'required' => true]],
|
||||
['type' => 'text', 'data' => ['label' => 'Standort', 'prefill' => 'location', 'locked' => true, 'required' => true]],
|
||||
['type' => 'text', 'data' => ['label' => 'Abteilung', 'prefill' => 'department']],
|
||||
]]);
|
||||
|
||||
$this->actingAs($this->employee)->get($form->url())->assertInertia(fn (Assert $p) => $p
|
||||
->where('form.fields.0.locked', true)
|
||||
->where('form.fields.1.locked', true)
|
||||
->where('form.prefill.personalnummer', 'P-4711')
|
||||
->missing('form.fields.3.locked'));
|
||||
|
||||
// Standort fehlt im Profil → Hinweis statt Einsendung.
|
||||
$this->post($form->url(), ['answers' => ['vorname' => 'Gefälscht', 'personalnummer' => 'X-0000']])
|
||||
->assertSessionHasErrors(['answers.standort' => 'Diese Angabe fehlt in Ihrem Profil. Bitte ergänzen Sie sie dort (Profil bearbeiten) oder wenden Sie sich an die Personalverwaltung.']);
|
||||
|
||||
$this->employee->update(['location' => 'Hamburg']);
|
||||
$this->post($form->url(), ['answers' => ['vorname' => 'Gefälscht', 'personalnummer' => 'X-0000', 'abteilung' => 'Selbst geändert']])->assertSessionHasNoErrors();
|
||||
|
||||
$submission = FormSubmission::query()->sole();
|
||||
$this->assertSame('Anna', $submission->display('vorname'), 'Manipulierte Eingaben werden durch den Profilwert ersetzt.');
|
||||
$this->assertSame('P-4711', $submission->display('personalnummer'));
|
||||
$this->assertSame('Hamburg', $submission->display('standort'));
|
||||
$this->assertSame('Selbst geändert', $submission->display('abteilung'), 'Nur vorbelegte Felder bleiben änderbar.');
|
||||
}
|
||||
|
||||
public function test_builder_keeps_lock_only_with_prefill(): void
|
||||
{
|
||||
$this->actingAs(User::factory()->admin()->create());
|
||||
$form = $this->trainingForm();
|
||||
|
||||
$saved = $this->putJson(route('forms.builder.update', $form), ['title' => 'x', 'fields' => [
|
||||
['type' => 'text', 'data' => ['label' => 'Vorname', 'prefill' => 'first_name', 'locked' => true]],
|
||||
['type' => 'text', 'data' => ['label' => 'Frei', 'locked' => true]],
|
||||
['type' => 'textarea', 'data' => ['label' => 'Text', 'prefill' => 'name', 'locked' => true]],
|
||||
]])->assertOk()->json('fields');
|
||||
|
||||
$this->assertTrue($saved[0]['data']['locked']);
|
||||
$this->assertArrayNotHasKey('locked', $saved[1]['data']);
|
||||
$this->assertArrayNotHasKey('locked', $saved[2]['data']);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,20 @@
|
|||
|
||||
namespace Tests;
|
||||
|
||||
use App\Plugins\PluginState;
|
||||
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
||||
use Illuminate\Testing\TestResponse;
|
||||
|
||||
abstract class TestCase extends BaseTestCase
|
||||
{
|
||||
public function createApplication()
|
||||
{
|
||||
// Optionale mitgelieferte Plugins (z. B. Geburtstage) in Tests mitladen.
|
||||
PluginState::$enableOptionalCorePlugins = true;
|
||||
|
||||
return parent::createApplication();
|
||||
}
|
||||
|
||||
/**
|
||||
* Props einer Startseiten-Kachel (oder null, wenn sie nicht angezeigt wird).
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue