From 97ce5fe66b5033d102f78ddc03619c73458020a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Delaune?= Date: Thu, 23 Jul 2015 16:28:57 +0200 Subject: [PATCH] Bug 10961: (followup) Make query fields explicit and add regression tests add correct frameworkcode to _koha_marc_update_bib_ids parameters add test, prove with : prove t/db_dependent/Biblio.t TEST PLAN --------- 1) git checkout -b bug_10961 origin/master 2) git bz apply 10961 3) git checkout origin/master -- C4/Biblio.pm 4) prove t/db_dependent/Biblio.t -- was expecting failure, got failure. 5) git reset --hard origin/master 6) git bz apply 10961 7) prove t/db_dependent/Biblio.t -- success as expected. 8) Read over code. -- Noted it also grabs the framework code for the biblio, rather than uses default. And it also corrects an indentation issue. Test case looks like it attempts to cover the biblionumber!=biblioitemnumber case by adding 1. 9) run koha qa test tools. Signed-off-by: Mark Tompsett Signed-off-by: Tomas Cohen Arazi (cherry picked from commit 62dc6b0ca15a9de99a1cb41809e6c9c016e6b0d0) Signed-off-by: Chris Cormack Signed-off-by: Liz Rea Conflicts: t/db_dependent/Biblio.t --- C4/Biblio.pm | 6 ++++-- t/db_dependent/Biblio.t | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 538384d7b4..57444cd115 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1274,10 +1274,12 @@ sub GetMarcBiblio { my $biblionumber = shift; my $embeditems = shift || 0; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT * FROM biblioitems WHERE biblionumber=? "); + my $sth = $dbh->prepare("SELECT biblioitemnumber, marcxml FROM biblioitems WHERE biblionumber=? "); $sth->execute($biblionumber); my $row = $sth->fetchrow_hashref; + my $biblioitemnumber = $row->{'biblioitemnumber'}; my $marcxml = StripNonXmlChars( $row->{'marcxml'} ); + my $frameworkcode = GetFrameworkCode($biblionumber); MARC::File::XML->default_record_format( C4::Context->preference('marcflavour') ); my $record = MARC::Record->new(); @@ -1286,7 +1288,7 @@ sub GetMarcBiblio { if ($@) { warn " problem with :$biblionumber : $@ \n$marcxml"; } return unless $record; - C4::Biblio::_koha_marc_update_bib_ids($record, '', $biblionumber, $row->{biblioitemnumber}); + C4::Biblio::_koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber); C4::Biblio::EmbedItemsInMarcBiblio($record, $biblionumber) if ($embeditems); return $record; diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index 3c0a15944f..fc78f16db4 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -178,7 +178,24 @@ sub run_tests { is( $isbns->[$i], $more_isbns[$i], "(GetMarcISBN) Corretly retrieves ISBN #". ($i + 1)); } +# fails for 3.16.x +# is( GetMarcPrice( $record_for_isbn, $marcflavour ), 100, +# "GetMarcPrice returns the correct value"); + + my $newincbiblioitemnumber=$biblioitemnumber+1; + $dbh->do("UPDATE biblioitems SET biblioitemnumber = ? WHERE biblionumber = ?;", undef, $newincbiblioitemnumber, $biblionumber ); + my $updatedrecord = GetMarcBiblio($biblionumber, 0); + my $frameworkcode = GetFrameworkCode($biblionumber); + my ( $biblioitem_tag, $biblioitem_subfield ) = GetMarcFromKohaField( "biblioitems.biblioitemnumber", $frameworkcode ); + die qq{No biblioitemnumber tag for framework "$frameworkcode"} unless $biblioitem_tag; + my $biblioitemnumbertotest; + if ( $biblioitem_tag < 10 ) { + $biblioitemnumbertotest = $updatedrecord->field($biblioitem_tag)->data(); + } else { + $biblioitemnumbertotest = $updatedrecord->field($biblioitem_tag)->subfield($biblioitem_subfield); + } + is ($newincbiblioitemnumber, $biblioitemnumbertotest); } sub mock_marcfromkohafield { @@ -241,16 +258,15 @@ sub create_issn_field { } subtest 'MARC21' => sub { - plan tests => 25; + plan tests => 26; run_tests('MARC21'); $dbh->rollback; }; subtest 'UNIMARC' => sub { - plan tests => 25; + plan tests => 26; run_tests('UNIMARC'); $dbh->rollback; }; - 1; -- 2.39.5