From 668cf9d29276cd5ffe80a803970be2946e2f5cf3 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 19 Jun 2024 13:05:45 +0200 Subject: [PATCH] Fixed: Dont sync member when member is manual --- app/Form/Fields/NamiField.php | 2 +- tests/Feature/Form/FormRegisterActionTest.php | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/Form/Fields/NamiField.php b/app/Form/Fields/NamiField.php index 244ca7c8..bce954bd 100644 --- a/app/Form/Fields/NamiField.php +++ b/app/Form/Fields/NamiField.php @@ -107,7 +107,7 @@ class NamiField extends Field public function afterRegistration(Form $form, Participant $participant, array $input): void { foreach ($input[$this->key] as $memberData) { - $member = Member::firstWhere(['mitgliedsnr' => $memberData['id']]); + $member = $memberData['id'] ? Member::firstWhere(['mitgliedsnr' => $memberData['id']]) : null; $data = []; foreach (FieldCollection::fromRequest($form, $memberData) as $field) { $data[$field->key] = $field->namiType === null || $member === null diff --git a/tests/Feature/Form/FormRegisterActionTest.php b/tests/Feature/Form/FormRegisterActionTest.php index 0d192b52..f968252a 100644 --- a/tests/Feature/Form/FormRegisterActionTest.php +++ b/tests/Feature/Form/FormRegisterActionTest.php @@ -575,17 +575,20 @@ class FormRegisterActionTest extends FormTestCase public function testItAddsMemberForNonNami(): void { $this->login()->loginNami(); + $this->createMember(['mitgliedsnr' => null]); $form = Form::factory()->fields([ $this->namiField('members'), $this->textField('gender')->namiType(NamiType::GENDER)->required(false), + $this->textField('vorname')->namiType(NamiType::FIRSTNAME)->required(false), $this->textField('other')->required(false), ]) ->create(); - $this->register($form, ['other' => '::string::', 'members' => [['id' => null, 'gender' => 'Herr', 'other' => 'othervalue']]]) + $this->register($form, ['other' => '::string::', 'vorname' => 'LA', 'members' => [['id' => null, 'vorname' => 'BBB', 'gender' => 'Herr', 'other' => 'othervalue']]]) ->assertOk(); $this->assertEquals('othervalue', $form->participants->get(1)->data['other']); $this->assertEquals('Herr', $form->participants->get(1)->data['gender']); + $this->assertEquals('BBB', $form->participants->get(1)->data['vorname']); } public function testItValidatesNamiTypeFieldsForNonMembers(): void