Skip to content

Commit

Permalink
MetadataTemplate::fetchValues(): remove duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
zozlak committed Oct 4, 2024
1 parent 1d42764 commit 6d16828
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
/.phpunit.cache
/config
/log
/build
/harvestoaipmh.php
1 change: 1 addition & 0 deletions src/acdhOeaw/arche/oaipmh/metadata/TemplateMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ private function fetchValues(Value $val): array {
$sbjs = $objs;
}
}
$sbjs = array_unique($sbjs);
usort($sbjs, fn($x, $y) => ((string) $x) <=> ((string) $y));
return $sbjs;
}
Expand Down
11 changes: 11 additions & 0 deletions tests/TemplateMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,17 @@ public function testIfSpecial(): void {
<cc1>baz</cc1>
<cc2>baz</cc2>
</root>
OUT;
$this->assertEquals($this->std($expected), $xml);
}

public function testForeachDistinct(): void {
$tmpl = $this->getMetadataObject('foreachDistinct');
$xml = $this->asString($tmpl->getXml());
$expected = <<<OUT
<root>
<b>http://127.0.0.1/api/987</b>
</root>
OUT;
$this->assertEquals($this->std($expected), $xml);
}
Expand Down
8 changes: 8 additions & 0 deletions tests/data/foreachDistinct.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<http://127.0.0.1/api/123> <https://id> <http://127.0.0.1/api/123> .
<http://127.0.0.1/api/234> <https://id> <http://127.0.0.1/api/234> ;
<https://isPartOf> <http://127.0.0.1/api/123> ;
<https://author> <http://127.0.0.1/api/987> .
<http://127.0.0.1/api/235> <https://id> <http://127.0.0.1/api/235> ;
<https://isPartOf> <http://127.0.0.1/api/123> ;
<https://author> <http://127.0.0.1/api/987> .
<http://127.0.0.1/api/987> <https://id> <http://127.0.0.1/api/987> .
7 changes: 7 additions & 0 deletions tests/data/foreachDistinct.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<root>
<a foreach="/^base:isPartOf/base:author" remove="remove">
<b val="CURNODE"/>
</a>
</root>

10 changes: 10 additions & 0 deletions tests/data/foreachDistinct.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
metadataPrefix: templateMetadata
metadataNamespace: http://unknown/namespace
schema: http://unknown/schema
class: \acdhOeaw\arche\oaipmh\metadata\TemplateMetadata
templatePath: ""
keepComments: false
xmlErrors: true
rdfNamespaces:
base: https://
local: http://127.0.0.1/api/

0 comments on commit 6d16828

Please sign in to comment.