Bug 26589: Fix t/db_dependent/OAI/Sets.t failing when OAI-PMH:AutoUpdateSets is enabled
authorAlex Buckley <alexbuckley@catalyst.net.nz>
Tue, 29 Sep 2020 05:53:34 +0000 (05:53 +0000)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 14 Oct 2020 09:47:57 +0000 (11:47 +0200)
Test plan:
1. Check the OAI-PMH:AutoUpdateSets syspref is disabled
2. Run t/db_dependent/OAI/Sets.t tests and confirm tests pass
successfully
3. Enabled the OAI-PMH:AutoUpdateSets syspref
4. Repeat step 2 and confirm the tests fail

5. Apply this patch and restart plack: sudo koha-plack --restart
<instance>
6. Repeat step 2 and confirm the tests now pass
7. Disable the OAI-PMH:AutoUpdateSets syspref and repeat step 2 and
confirm tests still pass

Sponsored-By: Catalyst IT
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
t/db_dependent/OAI/Sets.t

index 6bc08da..8db222f 100755 (executable)
@@ -18,7 +18,7 @@
 
 use Modern::Perl;
 
-use Test::More tests => 147;
+use Test::More tests => 152;
 use Test::MockModule;
 use Test::Warn;
 use MARC::Record;
@@ -28,6 +28,7 @@ use C4::Biblio;
 use C4::OAI::Sets;
 
 use t::lib::TestBuilder;
+use t::lib::Mocks;
 
 my $schema  = Koha::Database->new->schema;
 $schema->storage->txn_begin;
@@ -349,11 +350,13 @@ is ($mappings->{$set2_id}->[0]->{operator}, 'equal', 'operator field is "equal"'
 is ($mappings->{$set2_id}->[0]->{marcvalue}, 'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"');
 
 
-# ---------- Testing AddOAISetsBiblios ----------
+# ---------- Testing AddOAISetsBiblios with OAI-PMH:AutoUpdateSets disabled ----------
 ok (!defined(AddOAISetsBiblios), 'AddOAISetsBiblios without argument is undef');
 ok (!defined(AddOAISetsBiblios(my $arg=[])), 'AddOAISetsBiblios with a no HASH argument is undef');
 ok (defined(AddOAISetsBiblios($arg={})), 'AddOAISetsBiblios with a HASH argument is def');
 
+t::lib::Mocks::mock_preference( 'OAI-PMH:AutoUpdateSets', 0 );
+
 # Create a biblio instance for testing
 my $biblio_1 = $builder->build_sample_biblio({ author => 'Moffat, Steven' });
 my $biblionumber1 = $biblio_1->biblionumber;
@@ -394,6 +397,29 @@ $sth->execute($set2_id);
 $count = $sth->rows;
 is ($count, '0', '$set_id2 has 0 biblio');
 
+# ---------- Testing AddOAISetsBiblios with OAI-PMH:AutoUpdateSets enabled ----------
+
+t::lib::Mocks::mock_preference( 'OAI-PMH:AutoUpdateSets', 1 );
+
+my $biblio_3 = $builder->build_sample_biblio({ author => 'Moffat, Steven' });
+my $biblionumber3 = $biblio_3->biblionumber;
+isa_ok(\$biblionumber3, 'SCALAR', '$biblionumber3 is a SCALAR');
+
+$sth = $dbh->prepare("SELECT count(*) FROM oai_sets_biblios");
+$sth->execute;
+$bibliosCount = $sth->fetchrow_array;
+is ($bibliosCount, 3, 'There are 3 biblios in oai_sets_biblios');
+
+#testing biblio for set1_id
+$sth = $dbh->prepare("SELECT * FROM oai_sets_biblios WHERE set_id = ?");
+$sth->execute($set1_id);
+$count = $sth->rows;
+is ($count, '3', '$set_id1 has 3 biblio');
+
+$sth->execute($set1_id);
+$line = ${ $sth->fetchall_arrayref( {} ) }[2];
+is($line->{set_id}, $set1_id, "set_id is good");
+is($line->{biblionumber}, $biblionumber3, "biblionumber is good");
 
 # ---------- Testing GetOAISetsBiblio -----------
 $oai_sets = GetOAISetsBiblio($biblionumber1);