fix: make email readonly in personal data form to prevent user lockout
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\XmlParser\PersonalDataParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class PersonalDataParserTest extends TestCase
|
||||
{
|
||||
private PersonalDataParser $parser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parser = new PersonalDataParser();
|
||||
}
|
||||
|
||||
public function testParseReadsCommunicationOfASinglePerson(): void
|
||||
{
|
||||
$personalData = $this->parse($this->responseXml(['[email protected]']));
|
||||
|
||||
self::assertSame('[email protected]', $personalData->communication->email);
|
||||
}
|
||||
|
||||
/**
|
||||
* A BPN address carries its communication entries 1:N, and the e-mail there doubles as a login
|
||||
* identity. The parser only ever surfaces the first entry, so anything writing the parsed model
|
||||
* back to BPN replaces the whole set with that one value. Pinned here because the personal data
|
||||
* form used to do exactly that and locked out the person owning the second entry.
|
||||
*/
|
||||
public function testParseOnlySurfacesTheFirstOfSeveralCommunicationEntries(): void
|
||||
{
|
||||
$personalData = $this->parse($this->responseXml(['[email protected]', '[email protected]']));
|
||||
|
||||
self::assertSame('[email protected]', $personalData->communication->email);
|
||||
}
|
||||
|
||||
public function testParseLeavesEmailNullWithoutCommunicationEntry(): void
|
||||
{
|
||||
$personalData = $this->parse($this->responseXml([]));
|
||||
|
||||
self::assertNull($personalData->communication->email);
|
||||
}
|
||||
|
||||
private function parse(string $xml): \App\BusProNet\Model\PersonalData
|
||||
{
|
||||
return $this->parser->parse(new Crawler($xml));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $emails
|
||||
*/
|
||||
private function responseXml(array $emails): string
|
||||
{
|
||||
$communication = '';
|
||||
|
||||
foreach ($emails as $email) {
|
||||
$communication .= sprintf(
|
||||
'<kommunikation><email>%s</email><telefonmobil>0170 1234567</telefonmobil></kommunikation>',
|
||||
$email,
|
||||
);
|
||||
}
|
||||
|
||||
return <<<XML
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<antwort>
|
||||
<idadresse>4711</idadresse>
|
||||
<idperson>815</idperson>
|
||||
<adressdaten>
|
||||
<vorname>Mia</vorname>
|
||||
<name>Muster</name>
|
||||
<geschlecht>w</geschlecht>
|
||||
<nationalitaet>d</nationalitaet>
|
||||
<anschrift>
|
||||
<strasse>Musterweg 1</strasse>
|
||||
<plz>12345</plz>
|
||||
<ort>Musterstadt</ort>
|
||||
<land>D</land>
|
||||
</anschrift>
|
||||
{$communication}
|
||||
</adressdaten>
|
||||
</antwort>
|
||||
XML;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user