Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/RecordManager/Base/Enrichment/AuthEnrichment.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
use RecordManager\Base\Utils\Logger;
use RecordManager\Base\Utils\MetadataUtils;

use function is_callable;

/**
* Enrich biblio records with authority record data.
*
Expand Down Expand Up @@ -169,6 +171,9 @@ protected function enrichField(
}

$authRecord = $this->createRecordFromDbRecord($data);
if (!is_callable([$authRecord, 'getAlternativeNames'])) {
return;
}
if ($altNames = $authRecord->getAlternativeNames()) {
$solrArray[$solrField]
= array_merge($solrArray[$solrField] ?? [], $altNames);
Expand Down
48 changes: 39 additions & 9 deletions tests/RecordManagerTest/Base/Enrichment/AuthEnrichmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ public static function getAuthEnrichmentData(): Generator
'author2' => ['Secondary Author With Missing Authority'],
],
];
yield 'no get alternative names method' => [
'fixture' => 'marc_auth_2.xml',
'authorityRecords' => [
'(FIN11)authority_002' => 'forward_authority_1.xml',
],
'config' => [],
'authorIds' => ['(FIN11)authority_002'],
'expected' => [],
];
}

/**
Expand Down Expand Up @@ -117,7 +126,9 @@ public function testAuthEnrichment(

$enricher = $this->getAuthEnricher($authorityRecords, $config);
$enricher->enrich('test', $record, $fields);

if (!$expected) {
$this->assertArrayNotHasKey('author_variant', $fields, 'author_variant field should not be present.');
}
foreach ($expected as $key => $value) {
$this->assertEquals($value, $fields[$key] ?? null, "Field '$key' did not match expected value.");
}
Expand Down Expand Up @@ -147,17 +158,30 @@ protected function getAuthEnricher(array $authorityRecords, array $config = []):
// Mock authority database records
$authorityDbRecords = [];
foreach ($authorityRecords as $id => $filename) {
$authorityRecord = $this->createMarcRecord(
\RecordManager\Base\Record\MarcAuthority::class,
$filename,
[]
);
$authorityRecord = null;
$format = '';
if (str_contains($filename, 'forward_authority')) {
$authorityRecord = $this->createRecord(
\RecordManager\Base\Record\ForwardAuthority::class,
$filename,
[]
);
$format = 'forwardAuthority';
} else {
$authorityRecord = $this->createMarcRecord(
\RecordManager\Base\Record\MarcAuthority::class,
$filename,
[]
);
$format = 'marc';
}

$authorityDbRecords[$id] = [
'_id' => $id,
'source_id' => 'test',
'oai_id' => $id,
'deleted' => false,
'format' => 'marc',
'format' => $format,
'original_data' => $authorityRecord->serialize(),
'normalized_data' => $authorityRecord->serialize(),
];
Expand All @@ -181,11 +205,17 @@ protected function getAuthEnricher(array $authorityRecords, array $config = []):
if ($format === 'marc') {
return $this->createMarcRecord(
\RecordManager\Base\Record\MarcAuthority::class,
'marc_authority_1.xml', // Dummy, will be replaced
'marc_authority_1.xml',
[]
);
} elseif ($format === 'forwardAuthority') {
return $this->createRecord(
\RecordManager\Base\Record\ForwardAuthority::class,
'forward_authority_1.xml',
[]
);
}
return null;
throw new \Exception("Unknown format requested in test: $format");
});

$enricher = $this->getMockBuilder(AuthEnrichment::class)
Expand Down
Loading