Add email to NamiField
This commit is contained in:
parent
c844f2143a
commit
171dd51200
|
@ -12,6 +12,7 @@ enum NamiType: string
|
||||||
case BIRTHDAY = 'Geburtstag';
|
case BIRTHDAY = 'Geburtstag';
|
||||||
case REGION = 'Bezirk';
|
case REGION = 'Bezirk';
|
||||||
case STAMM = 'Stamm';
|
case STAMM = 'Stamm';
|
||||||
|
case EMAIL = 'E-Mail-Adresse';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<int, array{name: string, id: string}>
|
* @return array<int, array{name: string, id: string}>
|
||||||
|
@ -31,6 +32,7 @@ enum NamiType: string
|
||||||
static::BIRTHDAY => $member->birthday?->format('Y-m-d'),
|
static::BIRTHDAY => $member->birthday?->format('Y-m-d'),
|
||||||
static::REGION => $this->matchRegion($member),
|
static::REGION => $this->matchRegion($member),
|
||||||
static::STAMM => $this->matchGroup($member),
|
static::STAMM => $this->matchGroup($member),
|
||||||
|
static::EMAIL => $member->email,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@ use App\Member\Member;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Generator;
|
use Generator;
|
||||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
use Illuminate\Testing\TestResponse;
|
use Illuminate\Testing\TestResponse;
|
||||||
|
|
||||||
class FormRegisterActionTest extends FormTestCase
|
class FormRegisterActionTest extends FormTestCase
|
||||||
|
@ -265,35 +266,90 @@ class FormRegisterActionTest extends FormTestCase
|
||||||
->assertOk();
|
->assertOk();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------- NamiField Tests ---------------------------
|
public function testItSetsMitgliedsnrForMainMember(): void
|
||||||
// ***********************************************************************
|
|
||||||
public function testItAddsMembersViaNamiFromNamiField(): void
|
|
||||||
{
|
{
|
||||||
$this->login()->loginNami();
|
$this->login()->loginNami();
|
||||||
$this->createMember(['mitgliedsnr' => '5505', 'firstname' => 'Abc', 'birthday' => '2023-01-05']);
|
$this->createMember(['mitgliedsnr' => '9966']);
|
||||||
$this->createMember(['mitgliedsnr' => '5506', 'firstname' => 'Def', 'birthday' => '2023-01-06']);
|
|
||||||
$form = Form::factory()
|
$form = Form::factory()
|
||||||
->sections([FormtemplateSectionRequest::new()->fields([
|
->sections([FormtemplateSectionRequest::new()->fields([
|
||||||
$this->namiField('members'),
|
$this->textField('email')->namiType(NamiType::EMAIL),
|
||||||
$this->textField('firstname')->required(true)->namiType(NamiType::FIRSTNAME),
|
$this->textField('firstname')->namiType(NamiType::FIRSTNAME),
|
||||||
$this->dateField('birthday')->required(true)->namiType(NamiType::BIRTHDAY),
|
$this->textField('lastname')->namiType(NamiType::LASTNAME),
|
||||||
])])
|
])])
|
||||||
->create();
|
->create();
|
||||||
|
|
||||||
$this->register($form, ['firstname' => 'Aaaa', 'birthday' => '2021-04-05', 'members' => [['id' => '5505'], ['id' => '5506']]])
|
$this->register($form, ['email' => 'max@muster.de', 'firstname' => 'Max', 'lastname' => 'Muster'])->assertOk();
|
||||||
|
$this->assertEquals('9966', $form->participants->first()->mitgliedsnr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------------- NamiField Tests ---------------------------
|
||||||
|
// ***********************************************************************
|
||||||
|
public function testItAddsMitgliedsnrFromMembers(): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$this->createMember(['mitgliedsnr' => '5505']);
|
||||||
|
$this->createMember(['mitgliedsnr' => '5506']);
|
||||||
|
$form = Form::factory()
|
||||||
|
->sections([FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->namiField('members'),
|
||||||
|
])])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->register($form, ['members' => [['id' => '5505'], ['id' => '5506']]])
|
||||||
->assertOk();
|
->assertOk();
|
||||||
$this->assertCount(3, $form->participants()->get());
|
$this->assertCount(3, $form->participants()->get());
|
||||||
$this->assertEquals('Aaaa', $form->participants->get(0)->data['firstname']);
|
|
||||||
$this->assertEquals('Abc', $form->participants->get(1)->data['firstname']);
|
|
||||||
$this->assertEquals('Def', $form->participants->get(2)->data['firstname']);
|
|
||||||
$this->assertEquals('2021-04-05', $form->participants->get(0)->data['birthday']);
|
|
||||||
$this->assertEquals('2023-01-05', $form->participants->get(1)->data['birthday']);
|
|
||||||
$this->assertEquals('2023-01-06', $form->participants->get(2)->data['birthday']);
|
|
||||||
$this->assertEquals([['id' => '5505'], ['id' => '5506']], $form->participants->get(0)->data['members']);
|
$this->assertEquals([['id' => '5505'], ['id' => '5506']], $form->participants->get(0)->data['members']);
|
||||||
$this->assertEquals([], $form->participants->get(1)->data['members']);
|
$this->assertEquals([], $form->participants->get(1)->data['members']);
|
||||||
$this->assertEquals([], $form->participants->get(2)->data['members']);
|
$this->assertEquals([], $form->participants->get(2)->data['members']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function memberMatchingDataProvider(): Generator
|
||||||
|
{
|
||||||
|
yield [
|
||||||
|
['email' => 'max@muster.de'],
|
||||||
|
NamiType::EMAIL,
|
||||||
|
'max@muster.de',
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [
|
||||||
|
['firstname' => 'Philipp'],
|
||||||
|
NamiType::FIRSTNAME,
|
||||||
|
'Philipp'
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [
|
||||||
|
['lastname' => 'Muster'],
|
||||||
|
NamiType::LASTNAME,
|
||||||
|
'Muster'
|
||||||
|
];
|
||||||
|
|
||||||
|
yield [
|
||||||
|
['birthday' => '2023-06-06'],
|
||||||
|
NamiType::BIRTHDAY,
|
||||||
|
'2023-06-06'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider memberMatchingDataProvider
|
||||||
|
* @param array<string, string> $memberAttributes
|
||||||
|
* @param mixed $participantValue
|
||||||
|
*/
|
||||||
|
public function testItSynchsMemberAttributes(array $memberAttributes, NamiType $type, mixed $participantValue): void
|
||||||
|
{
|
||||||
|
$this->login()->loginNami();
|
||||||
|
$this->createMember(['mitgliedsnr' => '5505', ...$memberAttributes]);
|
||||||
|
$form = Form::factory()
|
||||||
|
->sections([FormtemplateSectionRequest::new()->fields([
|
||||||
|
$this->namiField('members'),
|
||||||
|
$this->textField('other')->required(true)->namiType($type),
|
||||||
|
])])
|
||||||
|
->create();
|
||||||
|
|
||||||
|
$this->register($form, ['other' => '::other::', 'members' => [['id' => '5505']]])->assertOk();
|
||||||
|
$this->assertEquals($participantValue, $form->participants->get(1)->data['other']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testItAddsOtherFieldsOfMember(): void
|
public function testItAddsOtherFieldsOfMember(): void
|
||||||
{
|
{
|
||||||
$this->login()->loginNami();
|
$this->login()->loginNami();
|
||||||
|
|
Loading…
Reference in New Issue