From 005a799051b38edb1c65070581996654b21a8e87 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Mon, 10 Jun 2019 18:54:30 +0000 Subject: [PATCH] Bug 12537: Don't retrieve XISBN results for the same biblionumber For a biblio with multiple ISBNS we sometimes get our own record back when check XISBN, we should test for this To test: 1 - Edit a record in the catalogue, add two isbns: 0521240670 0521284198 2 - Enable ThingISBN and FRBRizeEditions and OPACFRBRizeEditions 3 - View the record in staff and OPAC 4 - You should see editions tab pointing to the same record 5 - Apply patch 6 - Reload the record details, you should no longer see editions tab 7 - Add the second ISBN to another record 8 - Reload details for original record, you shoudl see editions linking to the record with second ISBN 9 - prove -v t/db_dependent/XISBN.t NOTE: Current tests don't work under elasticsearch, but the code does, tests should be rewritten on another bug Signed-off-by: Mark Tompsett Signed-off-by: Bouzid Fergani Signed-off-by: Arthur Bousquet Signed-off-by: Katrin Fischer Signed-off-by: Martin Renvoize (cherry picked from commit fd5686b156ceb10958cab728b7695aa2b39b9933) Signed-off-by: Fridolin Somers --- C4/XISBN.pm | 6 +++--- catalogue/detail.pl | 2 +- opac/opac-detail.pl | 2 +- t/db_dependent/XISBN.t | 20 +++++++++++++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/C4/XISBN.pm b/C4/XISBN.pm index 22b450255b..1b3a3bbbd6 100644 --- a/C4/XISBN.pm +++ b/C4/XISBN.pm @@ -72,14 +72,14 @@ sub _get_biblio_from_xisbn { return $biblio; } -=head1 get_xisbns($isbn); +=head1 get_xisbns($isbn, $biblionumber); =head2 $isbn is an ISBN string =cut sub get_xisbns { - my ( $isbn ) = @_; + my ( $isbn, $biblionumber ) = @_; my ($response,$thing_response,$syndetics_response,$errors); # THINGISBN if ( C4::Context->preference('ThingISBN') ) { @@ -107,7 +107,7 @@ sub get_xisbns { next if $unique_xisbns->{ $response_data->{content} }; $unique_xisbns->{ $response_data->{content} }++; my $xbiblio= _get_biblio_from_xisbn($response_data->{content}); - push @xisbns, $xbiblio if $xbiblio; + push @xisbns, $xbiblio if $xbiblio && $xbiblio->{biblionumber} ne $biblionumber; } if ( wantarray ) { return (\@xisbns, $errors); diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 027ca5253a..b7e4d6eced 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -461,7 +461,7 @@ if (C4::Context->preference("virtualshelves") ) { if (C4::Context->preference("FRBRizeEditions")==1) { eval { $template->param( - XISBNS => scalar get_xisbns($isbn) + XISBNS => scalar get_xisbns($isbn, $biblionumber) ); }; if ($@) { warn "XISBN Failed $@"; } diff --git a/opac/opac-detail.pl b/opac/opac-detail.pl index c859771590..11491182c8 100755 --- a/opac/opac-detail.pl +++ b/opac/opac-detail.pl @@ -919,7 +919,7 @@ if (C4::Context->preference("virtualshelves") ) { if (C4::Context->preference("OPACFRBRizeEditions")==1) { eval { $template->param( - XISBNS => scalar get_xisbns($isbn) + XISBNS => scalar get_xisbns($isbn, $biblionumber) ); }; if ($@) { warn "XISBN Failed $@"; } diff --git a/t/db_dependent/XISBN.t b/t/db_dependent/XISBN.t index 803743a787..500bb6df3a 100755 --- a/t/db_dependent/XISBN.t +++ b/t/db_dependent/XISBN.t @@ -5,7 +5,7 @@ use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 5; use MARC::Record; use C4::Biblio; use C4::XISBN; @@ -62,6 +62,24 @@ SKIP: { "Gets correct biblionumber from a book with a similar isbn using ThingISBN." ); } +eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber1); }; +SKIP: { + skip "Problem retrieving ThingISBN", 1 + unless $@ eq ''; + is( $results_thingisbn->[0]->{biblionumber}, + $biblionumber3, + "Gets correct biblionumber from a different book with a similar isbn using ThingISBN." ); +} + +eval { $results_thingisbn = C4::XISBN::get_xisbns($isbn1,$biblionumber3); }; +SKIP: { + skip "Problem retrieving ThingISBN", 1 + unless $@ eq ''; + is( $results_thingisbn->[0]->{biblionumber}, + undef, + "Doesn't get biblionumber if the biblionumber matches the one passed to the sub." ); +} + # Util subs # Add new biblio with isbn and return biblionumber -- 2.39.5