Bug 24531: Test for OAI-PMH sets and repeated fields
authorMagnus Enger <magnus@libriotech.no>
Wed, 29 Jan 2020 22:56:32 +0000 (23:56 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 14 Feb 2020 12:00:20 +0000 (12:00 +0000)
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 <david@davidnind.com>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

t/db_dependent/OAI/Sets.t

index f685526..6bc08da 100644 (file)
@@ -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;