Skip to content

Commit 0c9e93d

Browse files
JeroenDeDauwclaude
andcommitted
Test the Mapping deserializer's reserved schema-key skip
The deserializer constructs a SchemaName from each schemas entry's key to validate it and skips the entry when that throws, so one dead entry never sinks the whole page's mapping. A reserved key ("page"/"subject") reaches this branch through a normal save, not only an import: the save-time validator enforces only propertyNames minLength and never constructs a SchemaName. That skip was untested — deleting it would silently null the entire page's mapping with no red test. Cover it with a reserved-key entry between two valid siblings, mirroring the missing-subject.class skip test. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent ad28a42 commit 0c9e93d

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tests/phpunit/Persistence/MediaWiki/MappingPersistenceDeserializerTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,27 @@ public function testSkipsAMalformedSchemaEntryButKeepsItsValidSiblings(): void {
6868
);
6969
}
7070

71+
public function testSkipsAnEntryWithAReservedSchemaKeyButKeepsItsValidSiblings(): void {
72+
// "page" is a reserved Schema name, so no Subject can carry it and the entry is unreachable. Save
73+
// validation permits the key (it never constructs a SchemaName), so a saved page can hold one; the
74+
// deserializer validates the key by constructing a SchemaName and skips the entry when that throws,
75+
// keeping its valid siblings rather than letting one dead entry sink the whole page's mapping.
76+
$mapping = $this->deserialize( <<<JSON
77+
{
78+
"version": 1,
79+
"prefixes": { "edm": "http://www.europeana.eu/schemas/edm/" },
80+
"schemas": {
81+
"Person": { "subject": { "class": "edm:Agent" }, "properties": {} },
82+
"page": { "subject": { "class": "edm:Place" }, "properties": {} },
83+
"City": { "subject": { "class": "edm:Place" }, "properties": {} }
84+
}
85+
}
86+
JSON );
87+
88+
$this->assertSame( 'edm:Agent', $mapping->forSchema( new SchemaName( 'Person' ) )?->subjectClass );
89+
$this->assertSame( 'edm:Place', $mapping->forSchema( new SchemaName( 'City' ) )?->subjectClass );
90+
}
91+
7192
public function testDeserializesAPropertyWithALanguageTag(): void {
7293
$name = $this->deserialize( $this->validJson() )->forSchema( new SchemaName( 'Person' ) )?->properties->get( 'Name' );
7394

0 commit comments

Comments
 (0)