feat: readonly room selection for single room types

This commit is contained in:
Björn Fromme
2025-10-16 09:36:04 +02:00
parent b1dbb15ad7
commit dc7ed0728a
3 changed files with 213 additions and 0 deletions
@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace App\Tests\Form\Service\Condition;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\RoomSelectionDto;
use App\Form\Service\Condition\SingleRoomTypeCondition;
use PHPUnit\Framework\TestCase;
class SingleRoomTypeConditionTest extends TestCase
{
private SingleRoomTypeCondition $condition;
protected function setUp(): void
{
$this->condition = new SingleRoomTypeCondition();
}
public function testReturnsFalseWhenNoRoomsSelected(): void
{
$bookingDto = $this->createBookingDto([]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertFalse($result, 'Condition should return false when no rooms are selected');
}
public function testReturnsTrueWhenExactlyOneRoomSelected(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 2],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertTrue($result, 'Condition should return true when exactly one room type is selected');
}
public function testReturnsFalseWhenTwoRoomsSelected(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 2],
['roomId' => 2, 'quantity' => 1],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertFalse($result, 'Condition should return false when two room types are selected');
}
public function testReturnsFalseWhenMultipleRoomsSelected(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 2],
['roomId' => 2, 'quantity' => 1],
['roomId' => 3, 'quantity' => 3],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertFalse($result, 'Condition should return false when multiple room types are selected');
}
public function testIgnoresRoomsWithZeroQuantity(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 2],
['roomId' => 2, 'quantity' => 0],
['roomId' => 3, 'quantity' => 0],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertTrue($result, 'Condition should ignore rooms with zero quantity');
}
public function testIgnoresRoomsWithNullQuantity(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 1],
['roomId' => 2, 'quantity' => null],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertTrue($result, 'Condition should ignore rooms with null quantity');
}
public function testReturnsFalseWhenAllRoomsHaveZeroQuantity(): void
{
$bookingDto = $this->createBookingDto([
['roomId' => 1, 'quantity' => 0],
['roomId' => 2, 'quantity' => 0],
]);
$result = $this->condition->evaluate($bookingDto, 0, []);
$this->assertFalse($result, 'Condition should return false when all rooms have zero quantity');
}
public function testGetDependentFieldsReturnsEmptyArray(): void
{
$result = $this->condition->getDependentFields();
$this->assertIsArray($result);
$this->assertEmpty($result, 'Single room type condition has no participant-level field dependencies');
}
public function testGetDescriptionReturnsString(): void
{
$result = $this->condition->getDescription();
$this->assertIsString($result);
$this->assertStringContainsString('readonly', $result);
$this->assertStringContainsString('one room type', $result);
}
/**
* Creates a BookingDto with specified room selections.
*
* @param array<int, array{roomId: int, quantity: int|null}> $rooms
*/
private function createBookingDto(array $rooms): BookingDto
{
$travel = new Travel();
$bookingDto = new BookingDto($travel, 1);
foreach ($rooms as $roomData) {
$roomSelection = new RoomSelectionDto();
$roomSelection->roomId = $roomData['roomId'];
$roomSelection->quantity = $roomData['quantity'];
$bookingDto->roomSelections[] = $roomSelection;
}
return $bookingDto;
}
}