fix: anonymize the person ids, not the participant slot ids
This commit is contained in:
@@ -205,11 +205,127 @@ XML;
|
||||
$this->assertSame('170', $responseHeight);
|
||||
$this->assertSame('70', $responseWeight);
|
||||
$this->assertSame('42', $responseShoeSize);
|
||||
$this->assertSame('123456', $responseRootPersonId);
|
||||
$this->assertSame('654321', $responseRootAddressId);
|
||||
// The root ids identify the same person as the <adressdaten> block, so they must be
|
||||
// replaced too - and with that person's replacements, not fresh ones.
|
||||
$this->assertSame('700001', $responseRootPersonId);
|
||||
$this->assertSame('800001', $responseRootAddressId);
|
||||
$this->assertSame(1, $anonymizer->getLastIdentityCount());
|
||||
}
|
||||
|
||||
public function testAnonymizePreservesParticipantSlotIds(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<satz typ="KUNDENKONTO" />
|
||||
<art>Vorgang_Details</art>
|
||||
<status_teilnehmer>F/F/S</status_teilnehmer>
|
||||
<teilnehmerliste>
|
||||
<teilnehmer id="1">
|
||||
<name>Alpha</name>
|
||||
<vorname>Ada</vorname>
|
||||
<idadresseperson>111111</idadresseperson>
|
||||
</teilnehmer>
|
||||
<teilnehmer id="2">
|
||||
<name>Beta</name>
|
||||
<vorname>Ben</vorname>
|
||||
<idadresseperson>222222</idadresseperson>
|
||||
</teilnehmer>
|
||||
<teilnehmer id="3">
|
||||
<name>Gamma</name>
|
||||
<vorname>Cem</vorname>
|
||||
<idadresseperson>333333</idadresseperson>
|
||||
</teilnehmer>
|
||||
</teilnehmerliste>
|
||||
<ferienzielunterbringungen>
|
||||
<ferienzielunterbringung idzimmer="74" anzahl="3" zuordnung="1,2,3" einzelpreis="439,00/439,00/439,00" />
|
||||
</ferienzielunterbringungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$anonymizer = new BpnXmlAnonymizer();
|
||||
$result = $anonymizer->anonymize($xml);
|
||||
|
||||
$document = new \DOMDocument();
|
||||
$this->assertTrue($document->loadXML($result));
|
||||
|
||||
$xpath = new \DOMXPath($document);
|
||||
|
||||
// Names must be replaced - this is still an anonymizer.
|
||||
$this->assertNotSame('Alpha', trim((string) $xpath->evaluate('string(//teilnehmer[1]/name)')));
|
||||
|
||||
// Slot ids must survive: zuordnung, status_teilnehmer and einzelpreis all index
|
||||
// against them, so rewriting them would make the dump self-contradictory.
|
||||
$this->assertSame('1', trim((string) $xpath->evaluate('string(//teilnehmer[1]/@id)')));
|
||||
$this->assertSame('2', trim((string) $xpath->evaluate('string(//teilnehmer[2]/@id)')));
|
||||
$this->assertSame('3', trim((string) $xpath->evaluate('string(//teilnehmer[3]/@id)')));
|
||||
|
||||
$this->assertSame('1,2,3', trim((string) $xpath->evaluate('string(//ferienzielunterbringung/@zuordnung)')));
|
||||
$this->assertSame('F/F/S', trim((string) $xpath->evaluate('string(//status_teilnehmer)')));
|
||||
}
|
||||
|
||||
public function testAnonymizeReplacesPersonAndAddressIdsConsistently(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ergebnis>
|
||||
<satz typ="KUNDENKONTO" />
|
||||
<art>Vorgang_Details</art>
|
||||
<idadresse>162648</idadresse>
|
||||
<idperson>275987</idperson>
|
||||
<anmelder>
|
||||
<name>Alpha</name>
|
||||
<vorname>Ada</vorname>
|
||||
<idadresse>162648</idadresse>
|
||||
<idadresseperson>275987</idadresseperson>
|
||||
</anmelder>
|
||||
<teilnehmerliste>
|
||||
<teilnehmer id="1">
|
||||
<name>Alpha</name>
|
||||
<vorname>Ada</vorname>
|
||||
<idadresseperson>275987</idadresseperson>
|
||||
</teilnehmer>
|
||||
<teilnehmer id="2">
|
||||
<name>Beta</name>
|
||||
<vorname>Ben</vorname>
|
||||
<idadresseperson>413732</idadresseperson>
|
||||
</teilnehmer>
|
||||
</teilnehmerliste>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$anonymizer = new BpnXmlAnonymizer();
|
||||
$result = $anonymizer->anonymize($xml);
|
||||
|
||||
$this->assertStringNotContainsString('275987', $result);
|
||||
$this->assertStringNotContainsString('413732', $result);
|
||||
$this->assertStringNotContainsString('162648', $result);
|
||||
|
||||
$document = new \DOMDocument();
|
||||
$this->assertTrue($document->loadXML($result));
|
||||
|
||||
$xpath = new \DOMXPath($document);
|
||||
|
||||
$rootPersonId = trim((string) $xpath->evaluate('string(/ergebnis/idperson)'));
|
||||
$rootAddressId = trim((string) $xpath->evaluate('string(/ergebnis/idadresse)'));
|
||||
$applicantPersonId = trim((string) $xpath->evaluate('string(//anmelder/idadresseperson)'));
|
||||
$applicantAddressId = trim((string) $xpath->evaluate('string(//anmelder/idadresse)'));
|
||||
$firstPersonId = trim((string) $xpath->evaluate('string(//teilnehmer[1]/idadresseperson)'));
|
||||
$secondPersonId = trim((string) $xpath->evaluate('string(//teilnehmer[2]/idadresseperson)'));
|
||||
|
||||
// One source id maps to one replacement wherever it occurs, so the applicant stays
|
||||
// recognisable as participant 1 and as the owner of the root ids.
|
||||
$this->assertSame($applicantPersonId, $rootPersonId);
|
||||
$this->assertSame($applicantPersonId, $firstPersonId);
|
||||
$this->assertSame($applicantAddressId, $rootAddressId);
|
||||
|
||||
// Distinct people keep distinct ids.
|
||||
$this->assertNotSame($applicantPersonId, $secondPersonId);
|
||||
|
||||
// The applicant and participant 1 are one person, so only two identities exist.
|
||||
$this->assertSame(2, $anonymizer->getLastIdentityCount());
|
||||
}
|
||||
|
||||
public function testAnonymizeReplacesKundeAttributes(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
@@ -526,8 +642,10 @@ XML;
|
||||
$this->assertSame('170', $height);
|
||||
$this->assertSame('70', $weight);
|
||||
$this->assertSame('42', $shoeSize);
|
||||
$this->assertSame('123456', $personId);
|
||||
$this->assertSame('654321', $addressIdRoot);
|
||||
// Same here: <adressdaten> carries no ids of its own, so the ones at the <ergebnis>
|
||||
// level are its own and must map onto this person's replacements.
|
||||
$this->assertSame('700001', $personId);
|
||||
$this->assertSame('800001', $addressIdRoot);
|
||||
$this->assertSame(1, $anonymizer->getLastIdentityCount());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user