id = 1; $outboundPkw->subType = 'PKW'; $outboundPkw->direction = 'HIN'; $outboundPkw->label = 'Eigene Anreise'; $outboundPkw->available = 10; $inboundPkw = new Service(); $inboundPkw->id = 2; $inboundPkw->subType = 'PKW'; $inboundPkw->direction = 'RUECK'; $inboundPkw->label = 'Eigene Abreise'; $inboundPkw->available = 10; $travel->transportationServices = [$outboundPkw, $inboundPkw]; $outboundResult = $travel->getTransportationServicesByDirection('HIN'); $this->assertCount(1, $outboundResult); $this->assertSame($outboundPkw, $outboundResult[0]); $inboundResult = $travel->getTransportationServicesByDirection('RUECK'); $this->assertCount(1, $inboundResult); $this->assertSame($inboundPkw, $inboundResult[0]); } /** * Test that multiple PKW services are all returned (no smart filtering at Travel level). */ public function testMultiplePkwServicesAllReturned(): void { $travel = new Travel(); $regularPkw = new Service(); $regularPkw->id = 1; $regularPkw->subType = 'PKW'; $regularPkw->direction = 'HIN'; $regularPkw->label = 'Eigene Anreise'; $regularPkw->price = 0.0; $regularPkw->available = 96; $discountedPkw = new Service(); $discountedPkw->id = 2; $discountedPkw->subType = 'PKW'; $discountedPkw->direction = 'HIN'; $discountedPkw->label = 'Eigene Anreise mit Rabatt'; $discountedPkw->price = -30.0; $discountedPkw->available = 99; $travel->transportationServices = [$regularPkw, $discountedPkw]; $result = $travel->getTransportationServicesByDirection('HIN'); // Both PKW services should be returned (filtering happens at field options provider level) $this->assertCount(2, $result); } /** * Test that services are sorted by subType. */ public function testServicesSortedBySubType(): void { $travel = new Travel(); $pkwService = new Service(); $pkwService->id = 1; $pkwService->subType = 'PKW'; $pkwService->direction = 'HIN'; $pkwService->available = 10; $busService = new Service(); $busService->id = 2; $busService->subType = 'BUS'; $busService->direction = 'HIN'; $busService->available = 95; // Add in reverse order to test sorting $travel->transportationServices = [$pkwService, $busService]; $result = $travel->getTransportationServicesByDirection('HIN'); $this->assertCount(2, $result); // BUS comes before PKW alphabetically $this->assertSame('BUS', $result[0]->subType); $this->assertSame('PKW', $result[1]->subType); } public function testHasSelectionIdReturnsTrueWhenSelectionExists(): void { $travel = new Travel(); $travel->selectionGroups = [ 10 => $this->createSelectionGroup(10, [1473, 2001]), 11 => $this->createSelectionGroup(11, [3001]), ]; $this->assertTrue($travel->hasSelectionId(1473)); } public function testHasSelectionIdReturnsFalseWhenSelectionDoesNotExist(): void { $travel = new Travel(); $travel->selectionGroups = [ 10 => $this->createSelectionGroup(10, [2001]), 11 => $this->createSelectionGroup(11, [3001]), ]; $this->assertFalse($travel->hasSelectionId(1473)); } /** * @param list $selectionIds */ private function createSelectionGroup(int $groupId, array $selectionIds): CrmSelectionGroup { $group = new CrmSelectionGroup(); $group->id = $groupId; $group->selections = []; foreach ($selectionIds as $selectionId) { $selection = new CrmSelection(); $selection->id = $selectionId; $group->selections[] = $selection; } return $group; } }