presseportale/tests/Feature/ContactDisplayNameTest.php
Kevin Adametz 178adb00e2 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>
2026-06-19 13:15:38 +00:00

21 lines
700 B
PHP

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