From 37a722e40bdc4e6fdd732b0e7ea4e838f1dd9696 Mon Sep 17 00:00:00 2001 From: Magnus Enger Date: Wed, 29 Jan 2020 23:56:32 +0100 Subject: [PATCH] Bug 24531 - Test for OAI-PMH sets and repeated fields This patch adds two tests related to OAI-PMH sets. It creates a dummy record with a repeated field, with different values. It then tests if the record is caught by mappings that match the value in the first field, and then if it is caught by mappings that match the second field. Signed-off-by: David Nind --- t/db_dependent/OAI/Sets.t | 73 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/OAI/Sets.t b/t/db_dependent/OAI/Sets.t index f68552613f..6bc08dac13 100644 --- a/t/db_dependent/OAI/Sets.t +++ b/t/db_dependent/OAI/Sets.t @@ -18,7 +18,7 @@ use Modern::Perl; -use Test::More tests => 144; +use Test::More tests => 147; use Test::MockModule; use Test::Warn; use MARC::Record; @@ -587,4 +587,75 @@ UpdateOAISetsBiblio($biblionumberNotVH, $record); my @setsNotEq = CalcOAISetsBiblio($record); is_deeply(@setsNotEq, $setNotVH_id, 'The $record only belongs to $setNotVH'); +# ---------- Testing CalcOAISetsBiblio with repeated field ---------- + +# Delete all existing sets to avoid false positives +my $all_sets = GetOAISets; +foreach my $set ( @$all_sets ) { + DelOAISet( $set->{'id'} ); +} + +# Create a MARC record with a repeated field 374 +my $record_rep = MARC::Record->new; +$record_rep->add_fields( + [ '001', '1234' ], + [ '100', ' ', ' ', a => 'N., N.' ], + [ '374', ' ', ' ', a => 'A' ], + [ '374', ' ', ' ', a => 'B', a => 'C' ] +); + +# Create a set +my $setRep = { + 'spec' => 'Set where 374a equals a given letter', + 'name' => 'Rep' +}; +my $setRep_id = AddOAISet($setRep); +# Create a mapping : 374$a should be "A" +my $mappingRepA = [ + { + marcfield => '374', + marcsubfield => 'a', + operator => 'equal', + marcvalue => 'A', + }, +]; +# Add the mapping to the set +ModOAISetMappings($setRep_id, $mappingRepA); + +# Get a list of set ids the record belongs to +my @setsRepA = CalcOAISetsBiblio($record_rep); +is_deeply(\@setsRepA, [$setRep_id], 'The $record belongs to $setRep_id (matching on first field, first subfield)'); + +# Create another mapping : 374$a should now be "B" +my $mappingRepB = [ + { + marcfield => '374', + marcsubfield => 'a', + operator => 'equal', + marcvalue => 'B', + }, +]; +# Replace the first mapping with the second one +ModOAISetMappings($setRep_id, $mappingRepB); + +# Get a list of set ids the record belongs to +my @setsRepB = CalcOAISetsBiblio($record_rep); +is_deeply(\@setsRepB, [$setRep_id], 'The $record belongs to $setRep_id (matching on second field, first subfield)'); + +# Create another mapping : 374$a should now be "C" +my $mappingRepC = [ + { + marcfield => '374', + marcsubfield => 'a', + operator => 'equal', + marcvalue => 'C', + }, +]; +# Replace the first mapping with the second one +ModOAISetMappings($setRep_id, $mappingRepC); + +# Get a list of set ids the record belongs to +my @setsRepC = CalcOAISetsBiblio($record_rep); +is_deeply(\@setsRepC, [$setRep_id], 'The $record belongs to $setRep_id (matching on second field, second subfield)'); + $schema->storage->txn_rollback; -- 2.11.0