wip: insurance booking in edit flow
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Tests\BusProNet\Model;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Service;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -69,4 +70,69 @@ class BookingTest extends TestCase
|
||||
$result = $booking->getSkiPassForParticipant(0);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetInsuranceForParticipantReturnsCorrectInsurance(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
|
||||
// Create insurance for participants 0 and 2
|
||||
$insurance1 = new Insurance();
|
||||
$insurance1->id = 100;
|
||||
$insurance1->label = 'Reiseschutz Platin';
|
||||
$insurance1->mapping = [0, 2];
|
||||
|
||||
// Create insurance for participant 1
|
||||
$insurance2 = new Insurance();
|
||||
$insurance2->id = 200;
|
||||
$insurance2->label = 'Reiseschutz Gold';
|
||||
$insurance2->mapping = [1];
|
||||
|
||||
$booking->insurances = [
|
||||
100 => $insurance1,
|
||||
200 => $insurance2,
|
||||
];
|
||||
|
||||
// Test: participant 0 should get insurance1
|
||||
$result = $booking->getInsuranceForParticipant(0);
|
||||
$this->assertSame($insurance1, $result);
|
||||
$this->assertEquals(100, $result->id);
|
||||
|
||||
// Test: participant 1 should get insurance2
|
||||
$result = $booking->getInsuranceForParticipant(1);
|
||||
$this->assertSame($insurance2, $result);
|
||||
$this->assertEquals(200, $result->id);
|
||||
|
||||
// Test: participant 2 should get insurance1
|
||||
$result = $booking->getInsuranceForParticipant(2);
|
||||
$this->assertSame($insurance1, $result);
|
||||
|
||||
// Test: participant 3 should get null (no insurance assigned)
|
||||
$result = $booking->getInsuranceForParticipant(3);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetInsuranceForParticipantReturnsNullWhenNoInsurances(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
$booking->insurances = [];
|
||||
|
||||
$result = $booking->getInsuranceForParticipant(0);
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testGetInsuranceForParticipantHandlesEmptyMapping(): void
|
||||
{
|
||||
$booking = new Booking();
|
||||
|
||||
// Create insurance with empty mapping
|
||||
$insurance = new Insurance();
|
||||
$insurance->id = 100;
|
||||
$insurance->label = 'Reiseschutz';
|
||||
$insurance->mapping = [];
|
||||
|
||||
$booking->insurances = [100 => $insurance];
|
||||
|
||||
$result = $booking->getInsuranceForParticipant(0);
|
||||
$this->assertNull($result, 'Should return null when mapping is empty');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\XmlParser\BookingInsurancesParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class BookingInsurancesParserTest extends TestCase
|
||||
{
|
||||
public function testParseInsurancesFromBookingXml(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<versicherungen>
|
||||
<versicherung idversicherung="177240" bezeichnung="Reiseschutz Platin Auto/Bahn/Bus (Europa)" anzahl="1"
|
||||
zuordnung="1" gesamtpreis="45,00" einzelpreis="45,00"></versicherung>
|
||||
</versicherungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$insurancesData = $crawler->filterXPath('//versicherungen/versicherung');
|
||||
|
||||
$parser = new BookingInsurancesParser();
|
||||
$insurances = $parser->parse($insurancesData);
|
||||
|
||||
$this->assertCount(1, $insurances);
|
||||
$this->assertArrayHasKey(177240, $insurances);
|
||||
|
||||
$insurance = $insurances[177240];
|
||||
$this->assertEquals(177240, $insurance->id);
|
||||
$this->assertEquals('Reiseschutz Platin Auto/Bahn/Bus (Europa)', $insurance->label);
|
||||
$this->assertEquals(45.0, $insurance->price);
|
||||
$this->assertEquals([0], $insurance->mapping); // zuordnung="1" maps to participant index 0
|
||||
$this->assertEquals([0 => 45.0], $insurance->individualPrice);
|
||||
}
|
||||
|
||||
public function testParseMultipleInsurances(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<versicherungen>
|
||||
<versicherung idversicherung="100" bezeichnung="Insurance A" anzahl="1"
|
||||
zuordnung="1" gesamtpreis="45,00" einzelpreis="45,00"></versicherung>
|
||||
<versicherung idversicherung="200" bezeichnung="Insurance B" anzahl="1"
|
||||
zuordnung="2" gesamtpreis="30,00" einzelpreis="30,00"></versicherung>
|
||||
</versicherungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$insurancesData = $crawler->filterXPath('//versicherungen/versicherung');
|
||||
|
||||
$parser = new BookingInsurancesParser();
|
||||
$insurances = $parser->parse($insurancesData);
|
||||
|
||||
$this->assertCount(2, $insurances);
|
||||
|
||||
// First insurance
|
||||
$insurance1 = $insurances[100];
|
||||
$this->assertEquals(100, $insurance1->id);
|
||||
$this->assertEquals('Insurance A', $insurance1->label);
|
||||
$this->assertEquals(45.0, $insurance1->price);
|
||||
$this->assertEquals([0], $insurance1->mapping); // zuordnung="1" maps to index 0
|
||||
$this->assertEquals([0 => 45.0], $insurance1->individualPrice);
|
||||
|
||||
// Second insurance
|
||||
$insurance2 = $insurances[200];
|
||||
$this->assertEquals(200, $insurance2->id);
|
||||
$this->assertEquals('Insurance B', $insurance2->label);
|
||||
$this->assertEquals(30.0, $insurance2->price);
|
||||
$this->assertEquals([1], $insurance2->mapping); // zuordnung="2" maps to index 1
|
||||
$this->assertEquals([1 => 30.0], $insurance2->individualPrice);
|
||||
}
|
||||
|
||||
public function testParseEmptyInsurancesReturnsEmptyArray(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<versicherungen>
|
||||
</versicherungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$crawler = new Crawler($xml);
|
||||
$insurancesData = $crawler->filterXPath('//versicherungen/versicherung');
|
||||
|
||||
$parser = new BookingInsurancesParser();
|
||||
$insurances = $parser->parse($insurancesData);
|
||||
|
||||
$this->assertCount(0, $insurances);
|
||||
$this->assertIsArray($insurances);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user