diff --git a/app/Form/Enums/NamiType.php b/app/Form/Enums/NamiType.php index a5487997..09290cd2 100644 --- a/app/Form/Enums/NamiType.php +++ b/app/Form/Enums/NamiType.php @@ -18,6 +18,7 @@ enum NamiType: string case ADDRESS = 'Adresse'; case ZIP = 'PLZ'; case LOCATION = 'Ort'; + case GENDER = 'Geschlecht'; /** * @return array @@ -42,6 +43,7 @@ enum NamiType: string static::ZIP => $member->zip, static::LOCATION => $member->location, static::NICKNAME => $member->nickname, + static::GENDER => $member->gender?->name, }; } diff --git a/database/factories/Member/MemberFactory.php b/database/factories/Member/MemberFactory.php index a028c92f..24321cd4 100644 --- a/database/factories/Member/MemberFactory.php +++ b/database/factories/Member/MemberFactory.php @@ -3,7 +3,7 @@ namespace Database\Factories\Member; use App\Country; -use App\Fee; +use App\Gender; use App\Group; use App\Invoice\BillKind; use App\Member\Member; @@ -68,6 +68,16 @@ class MemberFactory extends Factory ]); } + public function male(): self + { + return $this->for(Gender::factory()->male()); + } + + public function female(): self + { + return $this->for(Gender::factory()->female()); + } + public function emailBillKind(): self { return $this->state([ diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index 74b25c6e..b116cc2f 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -10,6 +10,7 @@ use App\Group; use App\Group\Enums\Level; use App\Member\Member; use Carbon\Carbon; +use Database\Factories\Member\MemberFactory; use Generator; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Support\Facades\Mail; @@ -480,6 +481,19 @@ class FormRegisterActionTest extends FormTestCase NamiType::BIRTHDAY, '2023-06-06' ]; + + yield [ + [], + NamiType::GENDER, + 'Männlich', + fn (MemberFactory $factory) => $factory->male(), + ]; + + yield [ + ['gender_id' => null], + NamiType::GENDER, + '', + ]; } /** @@ -487,10 +501,10 @@ class FormRegisterActionTest extends FormTestCase * @param array $memberAttributes * @param mixed $participantValue */ - public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue): void + public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue, ?callable $factory = null): void { $this->login()->loginNami(); - $this->createMember(['mitgliedsnr' => '5505', ...$memberAttributes]); + $this->createMember(['mitgliedsnr' => '5505', ...$memberAttributes], $factory); $form = Form::factory()->fields([ $this->namiField('members'), $this->textField('other')->required(true)->namiType($type), @@ -666,9 +680,10 @@ class FormRegisterActionTest extends FormTestCase /** * @param array $attributes */ - protected function createMember(array $attributes): Member + protected function createMember(array $attributes, ?callable $factoryCallback = null): Member { - return Member::factory()->defaults()->create($attributes); + return call_user_func($factoryCallback ?: fn ($factory) => $factory, Member::factory()->defaults()) + ->create($attributes); } /**