fix: correct sort order of pickups and drop-offs
This commit is contained in:
@@ -208,4 +208,77 @@ class TravelParserTest extends TestCase
|
||||
|
||||
$this->assertNull($travel->status); // No status_hin node should result in null
|
||||
}
|
||||
|
||||
public function testGetPickupsAdjustsOvernightTimes(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<zustiege>
|
||||
<zustieg idbuspro="1" zeit="30.12.2029 18:00" preis="0,00" />
|
||||
<zustieg idbuspro="2" zeit="30.12.2029 20:30" preis="0,00" />
|
||||
<zustieg idbuspro="3" zeit="23:00" preis="0,00" />
|
||||
<zustieg idbuspro="4" zeit="01:00" preis="0,00" />
|
||||
</zustiege>';
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$defaultDate = new \DateTimeImmutable('2029-12-30');
|
||||
|
||||
$pickups = $this->parser->getPickups(
|
||||
$crawler->filterXPath('//zustiege/zustieg'),
|
||||
$defaultDate,
|
||||
true
|
||||
);
|
||||
|
||||
// Full-datetime entries keep their original date
|
||||
$this->assertSame('2029-12-30 18:00', $pickups[1]->time->format('Y-m-d H:i'));
|
||||
$this->assertSame('2029-12-30 20:30', $pickups[2]->time->format('Y-m-d H:i'));
|
||||
|
||||
// Time-only "23:00" is after latest full-datetime (20:30), so stays on same day
|
||||
$this->assertSame('2029-12-30 23:00', $pickups[3]->time->format('Y-m-d H:i'));
|
||||
|
||||
// Time-only "01:00" is before latest full-datetime (20:30), so gets +1 day
|
||||
$this->assertSame('2029-12-31 01:00', $pickups[4]->time->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testGetPickupsDoesNotAdjustWhenAllEntriesAreFullDatetime(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<zustiege>
|
||||
<zustieg idbuspro="1" zeit="30.12.2029 18:00" preis="0,00" />
|
||||
<zustieg idbuspro="2" zeit="30.12.2029 20:30" preis="0,00" />
|
||||
</zustiege>';
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$defaultDate = new \DateTimeImmutable('2029-12-30');
|
||||
|
||||
$pickups = $this->parser->getPickups(
|
||||
$crawler->filterXPath('//zustiege/zustieg'),
|
||||
$defaultDate,
|
||||
true
|
||||
);
|
||||
|
||||
$this->assertSame('2029-12-30 18:00', $pickups[1]->time->format('Y-m-d H:i'));
|
||||
$this->assertSame('2029-12-30 20:30', $pickups[2]->time->format('Y-m-d H:i'));
|
||||
}
|
||||
|
||||
public function testGetPickupsDoesNotAdjustWhenAllEntriesAreTimeOnly(): void
|
||||
{
|
||||
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
||||
<zustiege>
|
||||
<zustieg idbuspro="1" zeit="18:00" preis="0,00" />
|
||||
<zustieg idbuspro="2" zeit="01:00" preis="0,00" />
|
||||
</zustiege>';
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$defaultDate = new \DateTimeImmutable('2029-12-30');
|
||||
|
||||
$pickups = $this->parser->getPickups(
|
||||
$crawler->filterXPath('//zustiege/zustieg'),
|
||||
$defaultDate,
|
||||
true
|
||||
);
|
||||
|
||||
// No full-datetime reference entries, so no adjustment happens
|
||||
$this->assertSame('2029-12-30 18:00', $pickups[1]->time->format('Y-m-d H:i'));
|
||||
$this->assertSame('2029-12-30 01:00', $pickups[2]->time->format('Y-m-d H:i'));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user