From 6af8044f7c80c44ef2d188e76690d095e4a28741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 12 Aug 2026 17:41:19 +0200 Subject: [PATCH] fix: collect hotel codes from every CRM selection group --- .../XmlParser/CrmAttributesResponseParser.php | 2 +- .../CrmAttributesResponseParserTest.php | 42 ++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/BusProNet/XmlParser/CrmAttributesResponseParser.php b/src/BusProNet/XmlParser/CrmAttributesResponseParser.php index 9af0ab1..18d4ce6 100644 --- a/src/BusProNet/XmlParser/CrmAttributesResponseParser.php +++ b/src/BusProNet/XmlParser/CrmAttributesResponseParser.php @@ -29,7 +29,7 @@ class CrmAttributesResponseParser $result ->filterXPath('//selektionsmerkmale/selektionsgruppe') - ->each(function (Crawler $node) use (&$groups, &$roles) { + ->each(function (Crawler $node) use (&$groups, &$roles, &$hotelCodes) { $group = new CrmSelectionGroup(); $group->id = (int) $node->attr('id'); $group->label = $node->attr('bezeichnung'); diff --git a/tests/BusProNet/XmlParser/CrmAttributesResponseParserTest.php b/tests/BusProNet/XmlParser/CrmAttributesResponseParserTest.php index 27edf30..f76297a 100644 --- a/tests/BusProNet/XmlParser/CrmAttributesResponseParserTest.php +++ b/tests/BusProNet/XmlParser/CrmAttributesResponseParserTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace App\Tests\BusProNet\XmlParser; +use App\BusProNet\Model\CrmAttributes; use App\BusProNet\XmlParser\CrmAttributesResponseParser; use PHPUnit\Framework\TestCase; use Symfony\Component\DomCrawler\Crawler; @@ -64,15 +65,54 @@ class CrmAttributesResponseParserTest extends TestCase self::assertContains('ROLE_TEAMER', $roles); } + public function testParseCollectsTheHotelCodesOfEveryHausleitungSelection(): void + { + $attributes = $this->parse($this->hausleitungXml()); + + self::assertSame(['ROLE_HOUSE_MANAGER'], $attributes->roles); + self::assertSame(['DKS', 'ASB'], $attributes->hotelCodes); + } + + public function testParseAddsTheDefaultHotelCodeForAdmins(): void + { + $attributes = $this->parse($this->selectionXml(1292, true)); + + self::assertSame(['SSL'], $attributes->hotelCodes); + } + /** * @return string[] */ private function parseRoles(string $xmlContent): array + { + return $this->parse($xmlContent)->roles; + } + + private function parse(string $xmlContent): CrmAttributes { $crawler = new Crawler($xmlContent); $resultNode = $crawler->filterXPath('//ergebnis'); - return $this->parser->parse($resultNode)->roles; + return $this->parser->parse($resultNode); + } + + private function hausleitungXml(): string + { + // Two groups, so the codes have to survive both closure levels of parse(). + return ' + + + + + + + + + + + + +'; } private function selectionXml(int $id, bool $selected): string