From fd83b65147d88e6b4770d01077de72e4a3fc34cc Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Mon, 30 Sep 2024 11:37:13 +0000 Subject: [PATCH] Bug 38033: Koha::Biblio->record does not return items Koha::Biblio->record introduced by Bug 33083 seems to be a straigtforward alias for Koha::Biblio::Metadata->record but it does not pass the parameters to $self->metadata->record call. This may lead to misunderstandings and possible bugs. The provided patch corrects this issue. Use unit test to test. Sponsored-by: Ignatianum University in Cracow --- Koha/Biblio.pm | 4 ++-- t/db_dependent/Biblio.t | 40 +++++++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Koha/Biblio.pm b/Koha/Biblio.pm index 8029be8e43..0315aee584 100644 --- a/Koha/Biblio.pm +++ b/Koha/Biblio.pm @@ -110,9 +110,9 @@ Returns a Marc::Record object =cut sub record { - my ( $self ) = @_; + my $self = shift; - return $self->metadata->record; + return $self->metadata->record(@_); } =head3 record_schema diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t index d2d5a5bbff..acbcff5c93 100755 --- a/t/db_dependent/Biblio.t +++ b/t/db_dependent/Biblio.t @@ -238,16 +238,17 @@ $biblio_module->mock( sub { my ($self) = shift; - my ( $title_field, $title_subfield ) = get_title_field(); - my ( $subtitle_field, $subtitle_subfield ) = get_subtitle_field(); - my ( $medium_field, $medium_subfield ) = get_medium_field(); - my ( $part_number_field, $part_number_subfield ) = get_part_number_field(); - my ( $part_name_field, $part_name_subfield ) = get_part_name_field(); - my ( $isbn_field, $isbn_subfield ) = get_isbn_field(); - my ( $issn_field, $issn_subfield ) = get_issn_field(); - my ( $biblionumber_field, $biblionumber_subfield ) = ( '999', 'c' ); + my ( $title_field, $title_subfield ) = get_title_field(); + my ( $subtitle_field, $subtitle_subfield ) = get_subtitle_field(); + my ( $medium_field, $medium_subfield ) = get_medium_field(); + my ( $part_number_field, $part_number_subfield ) = get_part_number_field(); + my ( $part_name_field, $part_name_subfield ) = get_part_name_field(); + my ( $isbn_field, $isbn_subfield ) = get_isbn_field(); + my ( $issn_field, $issn_subfield ) = get_issn_field(); + my ( $biblionumber_field, $biblionumber_subfield ) = ( '999', 'c' ); my ( $biblioitemnumber_field, $biblioitemnumber_subfield ) = ( '999', '9' ); - my ( $itemnumber_field, $itemnumber_subfield ) = get_itemnumber_field(); + my ( $itemnumber_field, $itemnumber_subfield ) = get_itemnumber_field(); + my ( $itemcallnumber_field, $itemcallnumber_subfield ) = get_itemcallnumber_field(); return { 'biblio.title' => [ { tagfield => $title_field, tagsubfield => $title_subfield } ], @@ -259,7 +260,8 @@ $biblio_module->mock( 'biblioitems.isbn' => [ { tagfield => $isbn_field, tagsubfield => $isbn_subfield } ], 'biblioitems.issn' => [ { tagfield => $issn_field, tagsubfield => $issn_subfield } ], 'biblioitems.biblioitemnumber' => [ { tagfield => $biblioitemnumber_field, tagsubfield => $biblioitemnumber_subfield } ], - 'items.itemnumber' => [ { tagfield => $itemnumber_subfield, tagsubfield => $itemnumber_subfield } ], + 'items.itemnumber' => [ { tagfield => $itemnumber_field, tagsubfield => $itemnumber_subfield } ], + 'items.itemcallnumber' => [ { tagfield => $itemcallnumber_field, tagsubfield => $itemcallnumber_subfield } ], }; } ); @@ -556,6 +558,11 @@ sub get_itemnumber_field { return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', '9' ) : ( '952', '9' ); } +sub get_itemcallnumber_field { + my $marc_flavour = C4::Context->preference('marcflavour'); + return ( $marc_flavour eq 'UNIMARC' ) ? ( '995', 'k' ) : ( '952', 'o' ); +} + sub get_author_field { my $marc_flavour = C4::Context->preference('marcflavour'); return ( $marc_flavour eq 'UNIMARC' ) ? ( '700', 'a', '4' ) : ( '100', 'a', 'e' ); @@ -952,7 +959,7 @@ subtest 'autoControlNumber tests' => sub { }; subtest 'record test' => sub { - plan tests => 1; + plan tests => 2; my $marc_record = MARC::Record->new; $marc_record->append_fields( create_isbn_field( '0590353403', 'MARC21' ) ); @@ -963,6 +970,17 @@ subtest 'record test' => sub { is( $biblio->record->as_formatted, $biblio->metadata->record->as_formatted ); + + Koha::Item->new( + { + biblionumber => $biblio->biblionumber, biblioitemnumber => $biblio->biblioitem->biblioitemnumber, + itemcallnumber => '12345' + } + )->store; + is( + $biblio->record( { embed_items => 1 } )->as_formatted, + $biblio->metadata->record( { embed_items => 1 } )->as_formatted + ); }; subtest 'record_schema test' => sub { -- 2.39.5