385 lines
17 KiB
PHP
385 lines
17 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\BusProNet\XmlParser;
|
|
|
|
use App\BusProNet\XmlParser\BookingResponseParser;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\DomCrawler\Crawler;
|
|
|
|
class BookingResponseParserTest extends TestCase
|
|
{
|
|
private BookingResponseParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->parser = new BookingResponseParser();
|
|
}
|
|
|
|
public function testParseBookingResponseWithPurchaseVoucher(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
</preise>
|
|
<gesamtpreis>755,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<kaufgutschein nummer="G1263" betrag="100,00"></kaufgutschein>
|
|
<restzahlung betrag="655,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(321530, $response->bookingNumber);
|
|
$this->assertEquals(755.0, $response->totalPrice);
|
|
|
|
// Verify purchase voucher is parsed
|
|
$this->assertNotNull($response->paymentTerms);
|
|
$this->assertCount(1, $response->paymentTerms->appliedPurchaseVouchers);
|
|
$this->assertEquals('G1263', $response->paymentTerms->appliedPurchaseVouchers[0]['nummer']);
|
|
$this->assertEquals(100.0, $response->paymentTerms->appliedPurchaseVouchers[0]['betrag']);
|
|
$this->assertEquals(100.0, $response->paymentTerms->getPurchaseVoucherDiscount());
|
|
$this->assertEquals(655.0, $response->paymentTerms->finalPaymentAmount);
|
|
}
|
|
|
|
public function testParseBookingResponseWithPromotionalVoucher(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
<preis position="2" art="AKTION" unterart="" bezeichnung="TESTERINO1" anzahl="1" zuordnung="1" preis="-100,00" gesamtpreis="-100,00"></preis>
|
|
</preise>
|
|
<gesamtpreis>615,20</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="615,20" termin="29.11.2025"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(615.2, $response->totalPrice);
|
|
|
|
// Verify price items include promotional voucher
|
|
$this->assertCount(2, $response->priceItems);
|
|
$voucherItem = $response->priceItems[1];
|
|
$this->assertEquals('AKTION', $voucherItem->type);
|
|
$this->assertEquals('TESTERINO1', $voucherItem->label);
|
|
$this->assertEquals(-100.0, $voucherItem->totalPrice);
|
|
|
|
// Verify voucher discount extraction
|
|
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
|
|
$this->assertCount(1, $voucherDiscounts);
|
|
$this->assertEquals(100.0, $response->getVoucherDiscountFromPrices());
|
|
$this->assertEquals(100.0, $response->getTotalVoucherDiscount());
|
|
}
|
|
|
|
public function testParseBookingResponseWithGoodwillVoucher(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
<preis position="2" art="KULANZGUTSCHEIN" unterart="" bezeichnung="Kulanzgutschein K1904" anzahl="1" zuordnung="1" preis="-679,00" gesamtpreis="-679,00"></preis>
|
|
</preise>
|
|
<gesamtpreis>0,00</gesamtpreis>
|
|
<zahlungsbedingungen></zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(0.0, $response->totalPrice);
|
|
|
|
// Verify goodwill voucher is parsed
|
|
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
|
|
$this->assertCount(1, $voucherDiscounts);
|
|
|
|
$goodwillVoucher = array_values($voucherDiscounts)[0];
|
|
$this->assertEquals('KULANZGUTSCHEIN', $goodwillVoucher->type);
|
|
$this->assertEquals('Kulanzgutschein K1904', $goodwillVoucher->label);
|
|
$this->assertEquals(-679.0, $goodwillVoucher->totalPrice);
|
|
|
|
$this->assertEquals(679.0, $response->getVoucherDiscountFromPrices());
|
|
$this->assertEquals(679.0, $response->getTotalVoucherDiscount());
|
|
}
|
|
|
|
public function testParseBookingResponseWithMultipleVouchers(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
<preis position="2" art="AKTION" unterart="" bezeichnung="PROMO10" anzahl="1" zuordnung="1" preis="-50,00" gesamtpreis="-50,00"></preis>
|
|
<preis position="3" art="KULANZGUTSCHEIN" unterart="" bezeichnung="Kulanzgutschein K123" anzahl="1" zuordnung="1" preis="-30,00" gesamtpreis="-30,00"></preis>
|
|
</preise>
|
|
<gesamtpreis>499,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<kaufgutschein nummer="G5678" betrag="100,00"></kaufgutschein>
|
|
<restzahlung betrag="399,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
// Verify all voucher types are parsed
|
|
$this->assertEquals(80.0, $response->getVoucherDiscountFromPrices()); // 50 + 30
|
|
$this->assertEquals(100.0, $response->getPurchaseVoucherDiscount());
|
|
$this->assertEquals(180.0, $response->getTotalVoucherDiscount()); // 50 + 30 + 100
|
|
|
|
// Verify price item vouchers
|
|
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
|
|
$this->assertCount(2, $voucherDiscounts);
|
|
}
|
|
|
|
public function testParseBookingResponseWithNoVouchers(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
</preise>
|
|
<gesamtpreis>679,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="679,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(679.0, $response->totalPrice);
|
|
|
|
// Verify no voucher discounts
|
|
$this->assertCount(0, $response->getVoucherDiscountsFromPrices());
|
|
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
|
|
$this->assertEquals(0.0, $response->getPurchaseVoucherDiscount());
|
|
$this->assertEquals(0.0, $response->getTotalVoucherDiscount());
|
|
}
|
|
|
|
public function testParseBookingResponseWithMultiplePurchaseVouchers(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
</preise>
|
|
<gesamtpreis>679,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<kaufgutschein nummer="G1111" betrag="50,00"></kaufgutschein>
|
|
<kaufgutschein nummer="G2222" betrag="75,00"></kaufgutschein>
|
|
<restzahlung betrag="554,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
// Verify multiple purchase vouchers are parsed
|
|
$this->assertNotNull($response->paymentTerms);
|
|
$this->assertCount(2, $response->paymentTerms->appliedPurchaseVouchers);
|
|
$this->assertEquals(125.0, $response->paymentTerms->getPurchaseVoucherDiscount()); // 50 + 75
|
|
$this->assertEquals(125.0, $response->getTotalVoucherDiscount());
|
|
}
|
|
|
|
public function testParseBookingResponseWithGruppenrabatt(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Doppelzimmer Dusche/WC" terminvon="27.03.2026" terminbis="29.03.2026" anzahl="6" zuordnung="1,2,3,4,5,6,7,8,9,10,11,12" preis="229,00" gesamtpreis="2748,00" />
|
|
<preis position="2" art="UNT" unterart="ZIM" bezeichnung="3er Zimmer Dusche/WC" terminvon="27.03.2026" terminbis="29.03.2026" anzahl="2" zuordnung="13,14,15,16,17,18" preis="219,00" gesamtpreis="1314,00" />
|
|
<preis position="3" art="ERM" unterart="GRU" bezeichnung="Gruppenrabatt" anzahl="1" preis="-90,00" gesamtpreis="-90,00" />
|
|
</preise>
|
|
<gesamtpreis>3972,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="3972,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(3972.0, $response->totalPrice);
|
|
|
|
// Verify Gruppenrabatt is NOT counted as voucher discount
|
|
$this->assertCount(0, $response->getVoucherDiscountsFromPrices());
|
|
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
|
|
|
|
// Verify Gruppenrabatt IS counted as API-applied discount
|
|
$apiAppliedDiscounts = $response->getApiAppliedDiscounts();
|
|
$this->assertCount(1, $apiAppliedDiscounts);
|
|
|
|
$gruppenrabatt = array_values($apiAppliedDiscounts)[0];
|
|
$this->assertEquals('ERM', $gruppenrabatt->type);
|
|
$this->assertEquals('GRU', $gruppenrabatt->subType);
|
|
$this->assertEquals('Gruppenrabatt', $gruppenrabatt->label);
|
|
$this->assertEquals(-90.0, $gruppenrabatt->totalPrice);
|
|
|
|
$this->assertEquals(90.0, $response->getApiAppliedDiscountTotal());
|
|
}
|
|
|
|
public function testParseBookingResponseWithGruppenrabattAndVouchers(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Doppelzimmer" preis="500,00" gesamtpreis="500,00" />
|
|
<preis position="2" art="AKTION" unterart="" bezeichnung="PROMO20" anzahl="1" zuordnung="1" preis="-20,00" gesamtpreis="-20,00" />
|
|
<preis position="3" art="ERM" unterart="GRU" bezeichnung="Gruppenrabatt" anzahl="1" preis="-50,00" gesamtpreis="-50,00" />
|
|
</preise>
|
|
<gesamtpreis>430,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="430,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
// Voucher discount should only include AKTION
|
|
$this->assertEquals(20.0, $response->getVoucherDiscountFromPrices());
|
|
|
|
// API-applied discount should only include ERM (Gruppenrabatt)
|
|
$this->assertEquals(50.0, $response->getApiAppliedDiscountTotal());
|
|
|
|
// Verify they are separate and don't overlap
|
|
$voucherDiscounts = $response->getVoucherDiscountsFromPrices();
|
|
$apiDiscounts = $response->getApiAppliedDiscounts();
|
|
|
|
$this->assertCount(1, $voucherDiscounts);
|
|
$this->assertCount(1, $apiDiscounts);
|
|
|
|
$this->assertEquals('AKTION', array_values($voucherDiscounts)[0]->type);
|
|
$this->assertEquals('ERM', array_values($apiDiscounts)[0]->type);
|
|
}
|
|
|
|
public function testParseBookingResponseWithNoApiAppliedDiscounts(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="UNT" unterart="ZIM" bezeichnung="Bett im Mehrbettzimmer" preis="679,00" gesamtpreis="679,00" />
|
|
</preise>
|
|
<gesamtpreis>679,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="679,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
// Verify no API-applied discounts
|
|
$this->assertCount(0, $response->getApiAppliedDiscounts());
|
|
$this->assertEquals(0.0, $response->getApiAppliedDiscountTotal());
|
|
}
|
|
|
|
public function testParseBookingResponseWithTransportationDiscountNotCountedAsApiApplied(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="BEF" unterart="PKW" bezeichnung="Eigene Anreise mit Rabatt" terminvon="20.03.2026" terminbis="20.03.2026" anzahl="5" zuordnung="1,2,3,4,5" preis="-30,00" gesamtpreis="-150,00" id="185481" />
|
|
<preis position="2" art="BEF" unterart="PKW" bezeichnung="Eigene Abreise" terminvon="22.03.2026" terminbis="22.03.2026" anzahl="5" zuordnung="1,2,3,4,5" preis="0,00" gesamtpreis="0,00" id="185497" />
|
|
<preis position="3" art="UNT" unterart="ZIM" bezeichnung="5er Zimmer Etagendusche/-WC" terminvon="20.03.2026" terminbis="22.03.2026" anzahl="1" zuordnung="1,2,3,4,5" preis="319,00" gesamtpreis="1595,00" />
|
|
<preis position="4" art="SON" unterart="SON" bezeichnung="Keycard-Pfand" terminvon="20.03.2026" terminbis="22.03.2026" anzahl="5" zuordnung="1,2,3,4,5" preis="5,40" gesamtpreis="27,00" id="185484" />
|
|
<preis position="5" art="SON" unterart="SPA" bezeichnung="Skipass 3 Tage" terminvon="20.03.2026" terminbis="22.03.2026" anzahl="3" zuordnung="1,4,5" preis="70,00" gesamtpreis="210,00" id="185486" />
|
|
</preise>
|
|
<gesamtpreis>1682,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="1682,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
$this->assertTrue($response->isInquiryValid());
|
|
$this->assertEquals(1682.0, $response->totalPrice);
|
|
|
|
// Transportation discount (BEF with negative price) should NOT be counted as API-applied discount
|
|
// because it's already handled by the local price calculator
|
|
$this->assertCount(0, $response->getApiAppliedDiscounts());
|
|
$this->assertEquals(0.0, $response->getApiAppliedDiscountTotal());
|
|
|
|
// Verify no voucher discounts either
|
|
$this->assertEquals(0.0, $response->getVoucherDiscountFromPrices());
|
|
}
|
|
|
|
public function testParseBookingResponseWithBothTransportationAndGruppenrabatt(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="BUCHUNG" />
|
|
<buchung>möglich</buchung>
|
|
<vorgang>321530</vorgang>
|
|
<preise>
|
|
<preis position="1" art="BEF" unterart="PKW" bezeichnung="Eigene Anreise mit Rabatt" anzahl="10" preis="-30,00" gesamtpreis="-300,00" />
|
|
<preis position="2" art="UNT" unterart="ZIM" bezeichnung="Doppelzimmer" anzahl="5" preis="400,00" gesamtpreis="2000,00" />
|
|
<preis position="3" art="ERM" unterart="GRU" bezeichnung="Gruppenrabatt" anzahl="1" preis="-100,00" gesamtpreis="-100,00" />
|
|
</preise>
|
|
<gesamtpreis>1600,00</gesamtpreis>
|
|
<zahlungsbedingungen>
|
|
<restzahlung betrag="1600,00" termin="02.12.2029"></restzahlung>
|
|
</zahlungsbedingungen>
|
|
</ergebnis>';
|
|
|
|
$crawler = new Crawler($xmlContent);
|
|
$response = $this->parser->parse($crawler->filter('ergebnis'));
|
|
|
|
// Only ERM (Gruppenrabatt) should be counted as API-applied discount
|
|
// BEF transportation discount should NOT be counted
|
|
$apiAppliedDiscounts = $response->getApiAppliedDiscounts();
|
|
$this->assertCount(1, $apiAppliedDiscounts);
|
|
|
|
$gruppenrabatt = array_values($apiAppliedDiscounts)[0];
|
|
$this->assertEquals('ERM', $gruppenrabatt->type);
|
|
$this->assertEquals(-100.0, $gruppenrabatt->totalPrice);
|
|
|
|
// Total API-applied discount should only include Gruppenrabatt (100), not transportation (300)
|
|
$this->assertEquals(100.0, $response->getApiAppliedDiscountTotal());
|
|
}
|
|
}
|