Files
myep-team/tests/BusProNet/ResponseParserTest.php
T

60 lines
4.1 KiB
PHP

<?php
namespace App\Tests\BusProNet;
use App\BusProNet\Model\CrmAttributesResponse;
use App\BusProNet\Model\ProfileResponse;
use App\BusProNet\ResponseParser;
use PHPUnit\Framework\TestCase;
class ResponseParserTest extends TestCase
{
public function testParseUnsuccessfulResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="HINWEIS"><nr>853</nr><text>ID, EMail oder Passwort falsch</text></satz></ergebnis>';
$parser = $this->getParserInstance();
$response = $parser->parseXmlString($content);
$this->assertEquals(853, $response->getCode());
$this->assertEquals('ID, EMail oder Passwort falsch', $response->getMessage());
$this->assertFalse($response->isSuccessful());
}
public function testParseSuccessfulProfileResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="KUNDENKONTO"></satz><art>Adressdaten</art><idadresse>141747</idadresse><idperson>224526</idperson><adressdaten><name>Fromme</name><vorname>Björn</vorname><anrede>Herr</anrede><titel></titel><geschlecht>M</geschlecht><geburtsdatum>16.04.1972</geburtsdatum><nationalitaet>D</nationalitaet><anschrift><id>119447</id><strasse>Emilienstraße 57</strasse><plz>42853</plz><ort>Remscheid</ort><ortsteil></ortsteil><land>D</land></anschrift><kommunikation><telefonmobil></telefonmobil><email>[email protected]</email><newsletter>False</newsletter><telefonprivat>02191-4615837</telefonprivat></kommunikation></adressdaten></ergebnis>';
$parser = $this->getParserInstance();
$response = $parser->parseXmlString($content);
$this->assertInstanceOf(ProfileResponse::class, $response);
$this->assertNull($response->getCode());
$this->assertNull($response->getMessage());
$this->assertTrue($response->isSuccessful());
}
public function testParseSuccessfulCrmAttributesResponse(): void
{
$content = '<?xml version="1.0" encoding="utf-8"?><ergebnis><satz typ="KUNDENKONTO"></satz><art>SelektionCRM</art><idadresse>141747</idadresse><idperson>224526</idperson><selektionsmerkmale><selektionsgruppe id="6" bezeichnung="Gruppen - Art (NUR direkt dem GR-Kunden zuordnen)"><selektion id="1156" bezeichnung="Gruppen-Buchungsportal" aenderbar="False" auswahl="True"></selektion></selektionsgruppe><selektionsgruppe id="10" bezeichnung="TEAM"><selektion id="1070" bezeichnung="E&amp;P Teamer - allg. Merkmal" aenderbar="False" auswahl="True"></selektion></selektionsgruppe><selektionsgruppe id="83" bezeichnung="Interessen"><selektion id="1064" bezeichnung="Sportclub-Reisen" aenderbar="True" auswahl="False"></selektion><selektion id="1065" bezeichnung="Individual-Ferienwohnungen/Gasthöfe" aenderbar="True" auswahl="False"></selektion><selektion id="1066" bezeichnung="Kurztrips" aenderbar="True" auswahl="False"></selektion><selektion id="1067" bezeichnung="Eventreisen" aenderbar="True" auswahl="False"></selektion><selektion id="1068" bezeichnung="Gruppen-Angebote" aenderbar="True" auswahl="False"></selektion><selektion id="1069" bezeichnung="Firmen-Angebote" aenderbar="True" auswahl="False"></selektion></selektionsgruppe></selektionsmerkmale><crmaktionen><crmaktion id="428" code="18DDW40" bezeichnung="Deal Der Woche KW40-2018" aenderbar="False" auswahl="False"></crmaktion><crmaktion id="276" code="NOMAIL" bezeichnung="Ich möchte keine Werbung per Mail erhalten" aenderbar="True" auswahl="True"></crmaktion></crmaktionen></ergebnis>';
$parser = $this->getParserInstance();
$response = $parser->parseXmlString($content);
$this->assertInstanceOf(CrmAttributesResponse::class, $response);
$this->assertNull($response->getCode());
$this->assertNull($response->getMessage());
$this->assertTrue($response->isSuccessful());
$this->assertCount(3, $response->getAttributeGroups());
$this->assertTrue($response->isTeamer());
}
private function getParserInstance(): ResponseParser
{
return new ResponseParser([
'bpn_crm_id_admin' => 1292,
'bpn_crm_id_manager' => 1293,
'bpn_crm_id_teamer' => 1070,
]);
}
}