Optimierung 5.3 (Teil 1): Contact::displayName()

Anzeigename eines Kontakts (Vor-/Nachname mit Fallback) als Model-Methode.
Ersetzt die identische Inline-Logik an 6 eindeutigen Relation-$contact-Stellen
(Admin: Benutzer-/PM-/Firmen-Detail; Kunde: Press-Kit-/PM-Detail).

Bewusst noch offen: Select-/toBase-Varianten ($contactOption/$contactResult/
$lookupContact, stdClass-Risiko) sowie web/release-detail (User-Frontend).

Test: ContactDisplayNameTest.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Kevin Adametz 2026-06-19 13:15:38 +00:00
parent 89842ac37f
commit 69395efa53
8 changed files with 38 additions and 6 deletions

View file

@ -0,0 +1,21 @@
<?php
use App\Models\Contact;
test('displayName joins first and last name', function () {
$contact = Contact::factory()->make(['first_name' => 'Erika', 'last_name' => 'Mustermann']);
expect($contact->displayName())->toBe('Erika Mustermann');
});
test('displayName trims a missing part', function () {
$contact = Contact::factory()->make(['first_name' => null, 'last_name' => 'Mustermann']);
expect($contact->displayName())->toBe('Mustermann');
});
test('displayName falls back when both names are empty', function () {
$contact = Contact::factory()->make(['first_name' => null, 'last_name' => null]);
expect($contact->displayName())->toBe(__('Kontakt ohne Name'));
});