76 lines
2.7 KiB
PHP
76 lines
2.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\Constants;
|
|
use App\BusProNet\XmlCrawlerFactory;
|
|
use App\BusProNet\XmlParser\AvailabilitiesParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
/**
|
|
* The service lines are taken from recorded VERFUEGBARKEIT responses (travels 12855 and 12833).
|
|
*/
|
|
class AvailabilitiesParserTest extends TestCase
|
|
{
|
|
private AvailabilitiesParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->parser = new AvailabilitiesParser();
|
|
}
|
|
|
|
public function testMapsLiveServiceStatusOntoExportVocabulary(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="VERFUEGBARKEIT"/>
|
|
<reise id="12855" status="frei" buchungstatusmoeglich="FOA"/>
|
|
<leistungen>
|
|
<leistung id="201200" bezeichnung="Begleitperson (gemäß Gruppenregelung)" art="SON" unterart="SON" status="buchbar" frei="3" preis="0,00" preisfaellig="Einmalig"/>
|
|
<leistung id="201590" bezeichnung="Begleitperson (gemäß Gruppenregelung)" art="SON" unterart="SON" status="ausgebucht" anfragemoeglich="J" frei="0" preis="0,00" preisfaellig="Einmalig"/>
|
|
</leistungen>
|
|
</ergebnis>';
|
|
|
|
$services = $this->parser->parseServices(XmlCrawlerFactory::create($xml))->getServices();
|
|
|
|
$this->assertSame(Constants::STATUS_AVAILABLE, $services[201200]->status);
|
|
$this->assertSame(3, $services[201200]->available);
|
|
$this->assertSame(Constants::STATUS_BLOCKED, $services[201590]->status);
|
|
$this->assertSame(0, $services[201590]->available);
|
|
}
|
|
|
|
public function testPassesExportVocabularyAndUnknownStatusThrough(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<leistungen>
|
|
<leistung id="1" status="Anfrage" frei="2" preis="0,00"/>
|
|
<leistung id="2" status="unbekannt" frei="2" preis="0,00"/>
|
|
<leistung id="3" frei="2" preis="0,00"/>
|
|
</leistungen>
|
|
</ergebnis>';
|
|
|
|
$services = $this->parser->parseServices(XmlCrawlerFactory::create($xml))->getServices();
|
|
|
|
$this->assertSame(Constants::STATUS_ON_REQUEST, $services[1]->status);
|
|
$this->assertSame('unbekannt', $services[2]->status);
|
|
$this->assertNull($services[3]->status);
|
|
}
|
|
|
|
public function testLeavesTravelLevelStatusUntouched(): void
|
|
{
|
|
$xml = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<reise id="12855" status="frei" buchungstatusmoeglich="FOA"/>
|
|
<leistungen/>
|
|
</ergebnis>';
|
|
|
|
$response = $this->parser->parseServices(XmlCrawlerFactory::create($xml));
|
|
|
|
$this->assertSame('frei', $response->travelStatus);
|
|
$this->assertSame(['F', 'O', 'A'], $response->allowedBookingStatus);
|
|
}
|
|
}
|