129 lines
4.0 KiB
PHP
129 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\XmlParser\ExtendedAvailabilitiesParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class ExtendedAvailabilitiesParserTest extends TestCase
|
|
{
|
|
private ExtendedAvailabilitiesParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->parser = new ExtendedAvailabilitiesParser();
|
|
}
|
|
|
|
public function testParsesServicesWithAllAttributes(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen>
|
|
<leistung id="101" status="Frei" frei="8" preis="29,90" termin="01.01.2030" bis="06.01.2030"
|
|
uhrzeit_von="09:00" hinweis="Bitte anmelden" altervon="10" alterbis="65" pflicht="True" />
|
|
</leistungen>
|
|
<reise status="Frei" buchungstatusmoeglich="FA" />
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$services = $response->getServices();
|
|
$this->assertArrayHasKey(101, $services);
|
|
|
|
$availability = $services[101];
|
|
$this->assertSame(101, $availability->serviceId);
|
|
$this->assertSame('Frei', $availability->status);
|
|
$this->assertSame(8, $availability->available);
|
|
$this->assertSame(29.90, $availability->price);
|
|
$this->assertSame('2030-01-01', $availability->dateFrom->format('Y-m-d'));
|
|
$this->assertSame('2030-01-06', $availability->dateTo->format('Y-m-d'));
|
|
$this->assertSame('09:00', $availability->timeFrom);
|
|
$this->assertSame('Bitte anmelden', $availability->description);
|
|
$this->assertSame(10, $availability->ageFrom);
|
|
$this->assertSame(65, $availability->ageTo);
|
|
$this->assertTrue($availability->mandatory);
|
|
}
|
|
|
|
public function testIgnoresEmptyAgeAndMandatoryAttributes(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen>
|
|
<leistung id="102" status="Frei" frei="0" preis="0,00" termin="01.01.2030" bis="06.01.2030"
|
|
altervon="" alterbis="" pflicht="" />
|
|
</leistungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$services = $response->getServices();
|
|
$this->assertArrayHasKey(102, $services);
|
|
|
|
$availability = $services[102];
|
|
$this->assertNull($availability->ageFrom);
|
|
$this->assertNull($availability->ageTo);
|
|
$this->assertNull($availability->mandatory);
|
|
}
|
|
|
|
public function testParsesTravelLevelMetadata(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen />
|
|
<reise status="Frei" buchungstatusmoeglich="FA" />
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$this->assertSame('Frei', $response->travelStatus);
|
|
$this->assertSame(['F', 'A'], $response->allowedBookingStatus);
|
|
}
|
|
|
|
public function testEmptyBuchungstatusmoeglichProducesNoStatusCodes(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen />
|
|
<reise status="Frei" buchungstatusmoeglich="" />
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$this->assertSame([], $response->allowedBookingStatus);
|
|
}
|
|
|
|
public function testMissingReiseNodeLeavesMetadataNullAndEmpty(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen />
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$this->assertNull($response->travelStatus);
|
|
$this->assertSame([], $response->allowedBookingStatus);
|
|
}
|
|
|
|
public function testEmptyServicesCollection(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen />
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xml);
|
|
$response = $this->parser->parseServices($crawler);
|
|
|
|
$this->assertSame([], $response->getServices());
|
|
}
|
|
}
|