create(['first_name' => 'Ada', 'last_name' => 'Lovelace']); $this->actingAs($user) ->get('/') ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('Dashboard') ->where('auth.user.name', 'Ada Lovelace') ->where('auth.user.initials', 'AL') ->where('auth.user.avatar_url', null) ->where('auth.user.can_admin', false) ->has('branding.portal_name') ->has('branding.primary_color')); } public function test_profile_redirects_to_own_person_page(): void { $user = User::factory()->create(); $this->actingAs($user)->get('/profil')->assertRedirect("/personen/{$user->id}"); } public function test_colleague_profile_is_shown(): void { $colleague = User::factory()->create(['job_title' => 'Pflegedienstleitung']); $this->actingAs(User::factory()->create()) ->get("/personen/{$colleague->id}") ->assertOk() ->assertInertia(fn (Assert $page) => $page ->component('Profile/Show') ->where('person.job_title', 'Pflegedienstleitung') ->where('isOwnProfile', false)); } public function test_inactive_profiles_are_hidden(): void { $inactive = User::factory()->inactive()->create(); $this->actingAs(User::factory()->create()) ->get("/personen/{$inactive->id}") ->assertNotFound(); } public function test_own_profile_can_be_updated(): void { $user = User::factory()->create(['department' => 'IT', 'location' => 'Bremen', 'email' => 'alt@example.com']); $this->actingAs($user) ->put('/profil', [ 'first_name' => 'Grete', 'last_name' => 'Müller', 'email' => 'grete@example.com', 'job_title' => 'Mitarbeitervertretung', 'department' => 'MAV', 'location' => 'Hamburg', 'phone' => '040 123', 'mobile' => null, 'about' => 'Ansprechpartnerin für alle Fragen rund um die MAV.', ]) ->assertRedirect() ->assertSessionHasNoErrors(); $user->refresh(); $this->assertSame('Grete Müller', $user->name); $this->assertSame('Mitarbeitervertretung', $user->job_title); // Abteilung, Standort und E-Mail steuern Sichtbarkeit bzw. Anmeldung – nicht selbst änderbar $this->assertSame('IT', $user->department); $this->assertSame('Bremen', $user->location); $this->assertSame('alt@example.com', $user->email); // Freigabe durch die Administration: Abteilung und Standort, E-Mail weiterhin nicht app(Settings::class)->set(ProfileFields::SELF_EDIT_ORG, true); $this->put('/profil', ['first_name' => 'Grete', 'last_name' => 'Müller', 'department' => 'MAV', 'location' => 'Hamburg', 'email' => 'neu@example.com'])->assertSessionHasNoErrors(); $this->assertSame('MAV', $user->fresh()->department); $this->assertSame('alt@example.com', $user->fresh()->email); } public function test_profile_update_cannot_change_account_flags(): void { $user = User::factory()->create(); $this->actingAs($user)->put('/profil', [ 'first_name' => 'Eve', 'last_name' => 'Evil', 'email' => $user->email, 'is_active' => false, 'manual_roles' => [Role::administration()->id], ]); $user->refresh(); $this->assertFalse($user->isAdministrator()); $this->assertTrue($user->is_active); } public function test_email_must_be_unique(): void { User::factory()->create(['email' => 'vergeben@example.com']); $user = User::factory()->create(); $this->actingAs($user) ->put('/profil', ['first_name' => 'A', 'last_name' => 'B', 'email' => 'vergeben@example.com']) ->assertSessionHasErrors('email'); } public function test_theme_preference_is_saved_and_validated(): void { $user = User::factory()->create(); $this->actingAs($user)->put('/profil/darstellung', ['theme' => 'dark'])->assertRedirect(); $this->assertSame('dark', $user->fresh()->theme); $this->actingAs($user)->put('/profil/darstellung', ['theme' => 'pink'])->assertSessionHasErrors('theme'); } }