'DKS', 2002 => 'XYZ', 2003 => 'ASB', ]; private CrmAttributesResponseParser $parser; protected function setUp(): void { $this->parser = new CrmAttributesResponseParser(self::HOUSE_MANAGER_IDS); } 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::assertSame([], $roles, 'the parser reports what BusPro says and adds no fallback'); } public function testParseStillAssignsExistingAdminManagerTeamerRoles(): void { $xmlContent = ' '; $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 testParseIgnoresHausleitungSelectionsThatAreNotMapped(): void { // A house that is deliberately left out of bpn_crm_house_manager_ids claims nothing — // matching is by id, never by label. $parser = new CrmAttributesResponseParser([]); $attributes = $parser->parse(XmlCrawlerFactory::create($this->hausleitungXml())->filterXPath('//ergebnis')); self::assertSame([], $attributes->roles); self::assertSame([], $attributes->hotelCodes); } public function testParseAddsNoDefaultHotelCodeForAdmins(): void { // Hotel codes are synced on every login now, so a default would permanently grant a // house to every administrator. $attributes = $this->parse($this->selectionXml(1292, true)); self::assertSame(['ROLE_ADMIN'], $attributes->roles); self::assertSame([], $attributes->hotelCodes); } /** * @return string[] */ private function parseRoles(string $xmlContent): array { return $this->parse($xmlContent)->roles; } private function parse(string $xmlContent): CrmAttributes { $crawler = XmlCrawlerFactory::create($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 ' '; } private function selectionXml(int $id, bool $selected): string { return sprintf(' ', $id, $selected ? 'True' : 'False'); } }