132 lines
4.3 KiB
PHP
132 lines
4.3 KiB
PHP
<?php
|
|
|
|
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;
|
|
|
|
class CrmAttributesResponseParserTest extends TestCase
|
|
{
|
|
private CrmAttributesResponseParser $parser;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->parser = new CrmAttributesResponseParser();
|
|
}
|
|
|
|
public function testParseAssignsGroupsManagerRoleWhenSelected(): void
|
|
{
|
|
$roles = $this->parseRoles($this->selectionXml(1477, true));
|
|
|
|
self::assertContains('ROLE_GROUPS_MANAGER', $roles);
|
|
self::assertNotContains('ROLE_GROUPS_ADMIN', $roles);
|
|
}
|
|
|
|
public function testParseAssignsGroupsAdminRoleWhenSelected(): void
|
|
{
|
|
$roles = $this->parseRoles($this->selectionXml(1478, true));
|
|
|
|
self::assertContains('ROLE_GROUPS_ADMIN', $roles);
|
|
self::assertNotContains('ROLE_GROUPS_MANAGER', $roles);
|
|
}
|
|
|
|
public function testParseAssignsNoGroupsRolesWhenNotSelected(): void
|
|
{
|
|
$roles = $this->parseRoles($this->selectionXml(1477, false));
|
|
|
|
self::assertNotContains('ROLE_GROUPS_MANAGER', $roles);
|
|
self::assertNotContains('ROLE_GROUPS_ADMIN', $roles);
|
|
self::assertSame(['ROLE_CUSTOMER'], $roles);
|
|
}
|
|
|
|
public function testParseStillAssignsExistingAdminManagerTeamerRoles(): void
|
|
{
|
|
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="KUNDENDATEN" />
|
|
<selektionsmerkmale>
|
|
<selektionsgruppe id="1" bezeichnung="Rollen">
|
|
<selektion id="1292" bezeichnung="Admin" aenderbar="0" auswahl="True" />
|
|
<selektion id="1293" bezeichnung="Manager" aenderbar="0" auswahl="True" />
|
|
<selektion id="1070" bezeichnung="Teamer" aenderbar="0" auswahl="True" />
|
|
</selektionsgruppe>
|
|
</selektionsmerkmale>
|
|
<crmaktionen></crmaktionen>
|
|
</ergebnis>';
|
|
|
|
$roles = $this->parseRoles($xmlContent);
|
|
|
|
self::assertContains('ROLE_ADMIN', $roles);
|
|
self::assertContains('ROLE_MANAGER', $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[]
|
|
*/
|
|
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);
|
|
}
|
|
|
|
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
|
|
{
|
|
return sprintf('<?xml version="1.0" encoding="utf-8"?>
|
|
<ergebnis>
|
|
<satz typ="KUNDENDATEN" />
|
|
<selektionsmerkmale>
|
|
<selektionsgruppe id="1" bezeichnung="Rollen">
|
|
<selektion id="%d" bezeichnung="Gruppenreisen" aenderbar="0" auswahl="%s" />
|
|
</selektionsgruppe>
|
|
</selektionsmerkmale>
|
|
<crmaktionen></crmaktionen>
|
|
</ergebnis>', $id, $selected ? 'True' : 'False');
|
|
}
|
|
}
|