From e7230327130205825cea2cb64c322c3754b1948a Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Thu, 24 Sep 2020 10:54:17 +0000 Subject: [PATCH] Bug 25460: Add unit test for change to C4::OAI::Sets->UpdateOAISetsBiblio() Test plan: 1. Run unit test: sudo koha-shell prove t/db_dependent/OAI/Sets.t 2. All tests should pass Sponsored-by: Catalyst IT Signed-off-by: David Nind Signed-off-by: Katrin Fischer JD amended patch: Put tests inside a subtest, and perltidy Signed-off-by: Jonathan Druart --- t/db_dependent/OAI/Sets.t | 55 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/OAI/Sets.t b/t/db_dependent/OAI/Sets.t index 8db222feb9..1fd577387f 100755 --- 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 => 152; +use Test::More tests => 153; use Test::MockModule; use Test::Warn; use MARC::Record; @@ -560,6 +560,59 @@ is($oai_setsVH->[0]->{id}, $setVH_id, 'id is ok'); is($oai_setsVH->[0]->{spec}, $setVH->{spec}, 'id is ok'); is($oai_setsVH->[0]->{name}, $setVH->{name}, 'id is ok'); +subtest 'OAI-PMH:AutoUpdateSetsEmbedItemData' => sub { + + plan tests => 6; + + t::lib::Mocks::mock_preference( 'OAI-PMH:AutoUpdateSetsEmbedItemData', 0 ); + + #Create a set + my $setFIC = { + 'spec' => 'Set where collection code is FIC', + 'name' => 'FIC' + }; + my $setFIC_id = AddOAISet($setFIC); + + #Create mappings : 'ccode' should be 'FIC' + my $mappingsFIC; + $mappingsFIC = [ + { + marcfield => '952', + marcsubfield => '8', + operator => 'equal', + marcvalue => 'FIC' + } + ]; + ModOAISetMappings( $setFIC_id, $mappingsFIC ); + + # Create biblio with 'FIC' item + my $biblio_FIC = $builder->build_sample_biblio(); + my $item = $builder->build_sample_item( + { + biblionumber => $biblio_FIC->biblionumber, + ccode => 'FIC' + } + ); + + #Update + my $recordFIC = GetMarcBiblio( { biblionumber => $biblio_FIC->biblionumber } ); + UpdateOAISetsBiblio( $biblio_FIC->biblionumber, $recordFIC ); + + #is biblio attached to setFIC ? + my $oai_setsFIC = GetOAISetsBiblio( $biblio_FIC->biblionumber ); + is( $oai_setsFIC->[0]->{id}, undef, 'id is ok' ); + is( $oai_setsFIC->[0]->{spec}, undef, 'id is ok' ); + is( $oai_setsFIC->[0]->{name}, undef, 'id is ok' ); + + t::lib::Mocks::mock_preference( 'OAI-PMH:AutoUpdateSetsEmbedItemData', 1 ); + UpdateOAISetsBiblio( $biblio_FIC->biblionumber, $recordFIC ); + + #is biblio attached to setFIC ? + $oai_setsFIC = GetOAISetsBiblio( $biblio_FIC->biblionumber ); + is( $oai_setsFIC->[0]->{id}, $setFIC_id, 'id is ok' ); + is( $oai_setsFIC->[0]->{spec}, $setFIC->{spec}, 'id is ok' ); + is( $oai_setsFIC->[0]->{name}, $setFIC->{name}, 'id is ok' ); +}; # ---------- Testing CalcOAISetsBiblio ---------- ok (!defined(CalcOAISetsBiblio), 'CalcOAISetsBiblio without argument is undef'); -- 2.39.5