Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 7m50s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 7m34s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 5m45s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 5m30s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 7m7s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 7m9s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 6m8s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 6m5s
CI / Bekannte Sicherheitslücken in Paketen (pull_request) Successful in 48s
CI / Build-Artefakte aktuell (pull_request) Successful in 1m5s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
133 lines
4.8 KiB
PHP
133 lines
4.8 KiB
PHP
<?php
|
||
|
||
namespace Tests\Feature\Profile;
|
||
|
||
use App\Models\Role;
|
||
use App\Models\User;
|
||
use App\Support\ProfileFields;
|
||
use App\Support\Settings;
|
||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
use Inertia\Testing\AssertableInertia as Assert;
|
||
use Tests\TestCase;
|
||
|
||
class ProfileTest extends TestCase
|
||
{
|
||
use RefreshDatabase;
|
||
|
||
public function test_dashboard_shares_header_data(): void
|
||
{
|
||
$user = User::factory()->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');
|
||
}
|
||
}
|