feat: use normalized checkbox values in field handlers

This commit is contained in:
Björn Fromme
2026-02-23 09:31:19 +01:00
parent bd488211bd
commit 3996e02dd9
6 changed files with 69 additions and 4 deletions
@@ -37,6 +37,22 @@ class ParticipantParkingFieldHandlerTest extends TestCase
$this->assertTrue($this->handler->shouldProcess(['some' => 'data'], BookingDto::MODE_EDIT, 5));
}
/**
* @dataProvider normalizeCheckboxValueCheckedProvider
*/
public function testNormalizeCheckboxValueReturnsTrueWhenChecked(mixed $value): void
{
$this->assertTrue($this->invokeNormalizeCheckboxValue($value));
}
/**
* @dataProvider normalizeCheckboxValueUncheckedProvider
*/
public function testNormalizeCheckboxValueReturnsFalseWhenUnchecked(mixed $value): void
{
$this->assertFalse($this->invokeNormalizeCheckboxValue($value));
}
public function testProcessFieldWithoutParticipant(): void
{
$travel = new Travel();
@@ -241,6 +257,40 @@ class ParticipantParkingFieldHandlerTest extends TestCase
$this->assertNull($participant->parkingService);
}
/**
* @return array<string, array{mixed}>
*/
public static function normalizeCheckboxValueCheckedProvider(): array
{
return [
'true' => [true],
'int 1' => [1],
'string 1' => ['1'],
];
}
/**
* @return array<string, array{mixed}>
*/
public static function normalizeCheckboxValueUncheckedProvider(): array
{
return [
'false' => [false],
'int 0' => [0],
'string 0' => ['0'],
'empty string' => [''],
'null' => [null],
'non-numeric string' => ['off'],
];
}
private function invokeNormalizeCheckboxValue(mixed $value): bool
{
$reflection = new \ReflectionMethod($this->handler, 'normalizeCheckboxValue');
return $reflection->invoke($this->handler, $value);
}
private function createTransportationService(string $subType): Service
{
$service = new Service();