feat: api endpoints and xml sync for contingents data

This commit is contained in:
Björn Fromme
2026-04-22 11:23:52 +02:00
parent a1f68ec11d
commit 9b84893d88
50 changed files with 2567 additions and 221 deletions
@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
namespace App\Tests\BusProNet\XmlParser;
use App\BusProNet\XmlParser\ContingentParser;
use PHPUnit\Framework\TestCase;
class ContingentParserTest extends TestCase
{
private ContingentParser $parser;
protected function setUp(): void
{
$this->parser = new ContingentParser();
}
public function testParseBuildsRoomTypesAndRowsWithLinksAndControlRoom(): void
{
$xml = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<hotelzimmer>
<unterbringungen>
<unterbringung idbuspro="10" code="DZ" zimmerbezeichnung="Double Room" pax_max="2" />
<unterbringung idbuspro="11" code="BelKal" zimmerbezeichnung="Control" pax_max="1" />
<unterbringung idbuspro="12" code="PDGS" zimmerbezeichnung="Pseudo" pax_max="1" />
<unterbringung idbuspro="13" code="EZ" zimmerbezeichnung="Single Room" pax_max="1" idbuspro_kontingent_aus="10" />
</unterbringungen>
<kapazitaeten>
<kapazitaet termin="24.02.2026">
<zimmerliste>
<zimmer idbuspro="10" kontingent="3" frei="1" status="" abpreis="100,00" abpreis_naechte="2" abpreis_verlaengerung="15,00" abpreis_verlaengerung_naechte="1" />
<zimmer idbuspro="11" kontingent="1" frei="1" status="A" abpreis="0" abpreis_naechte="0" abpreis_verlaengerung="0" abpreis_verlaengerung_naechte="0" />
</zimmerliste>
</kapazitaet>
</kapazitaeten>
</hotelzimmer>
XML;
$result = $this->parser->parse($xml);
$this->assertArrayHasKey('roomTypes', $result);
$this->assertArrayHasKey('rows', $result);
$this->assertCount(3, $result['roomTypes']); // PDGS skipped
$this->assertCount(3, $result['rows']);
$rowsByCode = [];
foreach ($result['rows'] as $row) {
$rowsByCode[$row['roomCode']] = $row;
}
$this->assertSame('OK', $rowsByCode['DZ']['status']);
$this->assertSame(6, $rowsByCode['DZ']['pax']);
$this->assertSame(2, $rowsByCode['DZ']['available']);
$this->assertSame(100.0, $rowsByCode['DZ']['minPrice']);
$this->assertSame(2, $rowsByCode['DZ']['minNights']);
$this->assertSame(15.0, $rowsByCode['DZ']['additionalNightMinPrice']);
$this->assertSame(1, $rowsByCode['DZ']['additionalNightMinNights']);
$this->assertFalse($rowsByCode['DZ']['isControlRoom']);
// Linked room uses DZ contingent node but its own pax
$this->assertSame('Single Room', $rowsByCode['EZ']['roomLabel']);
$this->assertSame(3, $rowsByCode['EZ']['pax']);
$this->assertSame(1, $rowsByCode['EZ']['available']);
$this->assertSame('ON_REQUEST', $rowsByCode['BelKal']['status']);
$this->assertSame(0, $rowsByCode['BelKal']['pax']);
$this->assertSame(0, $rowsByCode['BelKal']['available']);
$this->assertTrue($rowsByCode['BelKal']['isControlRoom']);
}
public function testParseHandlesZeroValuesAndBlockedStatus(): void
{
$xml = <<<'XML'
<?xml version="1.0" encoding="utf-8"?>
<hotelzimmer>
<unterbringungen>
<unterbringung idbuspro="20" code="DZ" zimmerbezeichnung="Double Room" pax_max="2" />
</unterbringungen>
<kapazitaeten>
<kapazitaet termin="25.02.2026">
<zimmerliste>
<zimmer idbuspro="20" kontingent="0" frei="0" status="S" abpreis="0" abpreis_naechte="0" abpreis_verlaengerung="0" abpreis_verlaengerung_naechte="0" />
</zimmerliste>
</kapazitaet>
</kapazitaeten>
</hotelzimmer>
XML;
$result = $this->parser->parse($xml);
$row = $result['rows'][0];
$this->assertSame('BLOCKED', $row['status']);
$this->assertSame(0, $row['pax']);
$this->assertSame(0, $row['available']);
$this->assertSame(0.0, $row['minPrice']);
$this->assertSame(0, $row['minNights']);
$this->assertSame(0.0, $row['additionalNightMinPrice']);
$this->assertSame(0, $row['additionalNightMinNights']);
}
}