feat: prefer discounted transportation services
addresses #869axbjbz
This commit is contained in:
@@ -0,0 +1,163 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Model;
|
||||
|
||||
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 unavailable services are filtered out when filterAvailable is true.
|
||||
*/
|
||||
public function testUnavailableServicesFiltered(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
$availablePkw = new Service();
|
||||
$availablePkw->id = 1;
|
||||
$availablePkw->subType = 'PKW';
|
||||
$availablePkw->direction = 'HIN';
|
||||
$availablePkw->label = 'Eigene Anreise';
|
||||
$availablePkw->available = 10;
|
||||
|
||||
$unavailablePkw = new Service();
|
||||
$unavailablePkw->id = 2;
|
||||
$unavailablePkw->subType = 'PKW';
|
||||
$unavailablePkw->direction = 'HIN';
|
||||
$unavailablePkw->label = 'Eigene Anreise mit Rabatt';
|
||||
$unavailablePkw->available = 0;
|
||||
|
||||
$travel->transportationServices = [$availablePkw, $unavailablePkw];
|
||||
|
||||
$result = $travel->getTransportationServicesByDirection('HIN', true);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame($availablePkw, $result[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that services with null availability are included.
|
||||
*/
|
||||
public function testNullAvailabilityIncluded(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
$pkwWithNullAvailability = new Service();
|
||||
$pkwWithNullAvailability->id = 1;
|
||||
$pkwWithNullAvailability->subType = 'PKW';
|
||||
$pkwWithNullAvailability->direction = 'HIN';
|
||||
$pkwWithNullAvailability->label = 'Eigene Anreise';
|
||||
$pkwWithNullAvailability->available = null;
|
||||
|
||||
$travel->transportationServices = [$pkwWithNullAvailability];
|
||||
|
||||
$result = $travel->getTransportationServicesByDirection('HIN', true);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame($pkwWithNullAvailability, $result[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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user