Bug 26589: Fix t/db_dependent/OAI/Sets.t failing when OAI-PMH:AutoUpdateSets is enabled

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>
This commit is contained in:
Alex Buckley 2020-09-29 05:53:34 +00:00 committed by Jonathan Druart
parent c32503fcb6
commit 913897f3a4

View file

@ -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);