fix: collect hotel codes from every CRM selection group
This commit is contained in:
@@ -29,7 +29,7 @@ class CrmAttributesResponseParser
|
|||||||
|
|
||||||
$result
|
$result
|
||||||
->filterXPath('//selektionsmerkmale/selektionsgruppe')
|
->filterXPath('//selektionsmerkmale/selektionsgruppe')
|
||||||
->each(function (Crawler $node) use (&$groups, &$roles) {
|
->each(function (Crawler $node) use (&$groups, &$roles, &$hotelCodes) {
|
||||||
$group = new CrmSelectionGroup();
|
$group = new CrmSelectionGroup();
|
||||||
$group->id = (int) $node->attr('id');
|
$group->id = (int) $node->attr('id');
|
||||||
$group->label = $node->attr('bezeichnung');
|
$group->label = $node->attr('bezeichnung');
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Tests\BusProNet\XmlParser;
|
namespace App\Tests\BusProNet\XmlParser;
|
||||||
|
|
||||||
|
use App\BusProNet\Model\CrmAttributes;
|
||||||
use App\BusProNet\XmlParser\CrmAttributesResponseParser;
|
use App\BusProNet\XmlParser\CrmAttributesResponseParser;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Symfony\Component\DomCrawler\Crawler;
|
use Symfony\Component\DomCrawler\Crawler;
|
||||||
@@ -64,15 +65,54 @@ class CrmAttributesResponseParserTest extends TestCase
|
|||||||
self::assertContains('ROLE_TEAMER', $roles);
|
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[]
|
* @return string[]
|
||||||
*/
|
*/
|
||||||
private function parseRoles(string $xmlContent): array
|
private function parseRoles(string $xmlContent): array
|
||||||
|
{
|
||||||
|
return $this->parse($xmlContent)->roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function parse(string $xmlContent): CrmAttributes
|
||||||
{
|
{
|
||||||
$crawler = new Crawler($xmlContent);
|
$crawler = new Crawler($xmlContent);
|
||||||
$resultNode = $crawler->filterXPath('//ergebnis');
|
$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 '<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<ergebnis>
|
||||||
|
<satz typ="KUNDENDATEN" />
|
||||||
|
<selektionsmerkmale>
|
||||||
|
<selektionsgruppe id="1" bezeichnung="Rollen">
|
||||||
|
<selektion id="2001" bezeichnung="Hausleitung DKS" aenderbar="0" auswahl="True" />
|
||||||
|
<selektion id="2002" bezeichnung="Hausleitung XYZ" aenderbar="0" auswahl="False" />
|
||||||
|
</selektionsgruppe>
|
||||||
|
<selektionsgruppe id="2" bezeichnung="Häuser">
|
||||||
|
<selektion id="2003" bezeichnung="Hausleitung ASB" aenderbar="0" auswahl="True" />
|
||||||
|
</selektionsgruppe>
|
||||||
|
</selektionsmerkmale>
|
||||||
|
<crmaktionen></crmaktionen>
|
||||||
|
</ergebnis>';
|
||||||
}
|
}
|
||||||
|
|
||||||
private function selectionXml(int $id, bool $selected): string
|
private function selectionXml(int $id, bool $selected): string
|
||||||
|
|||||||
Reference in New Issue
Block a user