155 lines
4.7 KiB
PHP
155 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\BusProNet\Model;
|
|
|
|
use App\BusProNet\Model\CrmSelection;
|
|
use App\BusProNet\Model\CrmSelectionGroup;
|
|
use App\BusProNet\Model\Service;
|
|
use App\BusProNet\Model\Travel;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* Tests for Travel model transportation service retrieval.
|
|
*
|
|
* Note: Smart PKW filtering (discounted vs regular) is tested in
|
|
* ParticipantFieldOptionsProviderTest, as that filtering now happens
|
|
* at the field options provider level with per-booking availability context.
|
|
*/
|
|
class TravelTest extends TestCase
|
|
{
|
|
/**
|
|
* Test that transportation services are filtered by direction.
|
|
*/
|
|
public function testServicesFilteredByDirection(): void
|
|
{
|
|
$travel = new Travel();
|
|
|
|
$outboundPkw = new Service();
|
|
$outboundPkw->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<int> $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;
|
|
}
|
|
}
|