Bugzilla – Attachment 187981 Details for
Bug 41031
Extractor::MARC->new does not check if metadata is a MARC::Record
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 41031: Add checks on metadata and biblio in Extractor::MARC->new
Bug-41031-Add-checks-on-metadata-and-biblio-in-Ext.patch (text/plain), 3.66 KB, created by
Marcel de Rooy
on 2025-10-16 09:43:06 UTC
(
hide
)
Description:
Bug 41031: Add checks on metadata and biblio in Extractor::MARC->new
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2025-10-16 09:43:06 UTC
Size:
3.66 KB
patch
obsolete
>From cda8c45501db05d311b19e8a8e566898a070a430 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Thu, 16 Oct 2025 10:18:49 +0200 >Subject: [PATCH] Bug 41031: Add checks on metadata and biblio in > Extractor::MARC->new >Content-Type: text/plain; charset=utf-8 > >Test plan: >Run t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t >Verify that addbiblio.pl still opens as expected when modifying an >existing record or adding a new record. > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > Koha/Biblio/Metadata/Extractor/MARC.pm | 8 ++++-- > .../Koha/Biblio/Metadata/Extractor/MARC.t | 27 ++++++++++++++++++- > 2 files changed, 32 insertions(+), 3 deletions(-) > >diff --git a/Koha/Biblio/Metadata/Extractor/MARC.pm b/Koha/Biblio/Metadata/Extractor/MARC.pm >index 3bbc02730d..b1c1cafd4c 100644 >--- a/Koha/Biblio/Metadata/Extractor/MARC.pm >+++ b/Koha/Biblio/Metadata/Extractor/MARC.pm >@@ -42,11 +42,15 @@ Constructor for the I<Koha::Biblio::Metadata::Extractor::MARC> class. > sub new { > my ( $class, $params ) = @_; > >+ # If metadata is missing, we should have a biblio parameter (Koha object). >+ # If we do not have biblio, metadata should be a MARC::Record object. > Koha::Exceptions::MissingParameter->throw( parameter => 'metadata' ) > unless $params->{metadata} || $params->{biblio}; >+ Koha::Exceptions::BadParameter->throw('biblio should be a Koha object') >+ if $params->{biblio} && ref( $params->{biblio} ) ne 'Koha::Biblio'; >+ Koha::Exceptions::BadParameter->throw('metadata should be a MARC::Record') >+ if !$params->{biblio} && ref( $params->{metadata} ) ne 'MARC::Record'; > >- #my $metadata = $biblio->metadata; >- #my $schema = $metadata->schema; > # Get the schema from the pref so that we do not fetch the biblio_metadata > my $schema = C4::Context->preference('marcflavour'); > >diff --git a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t b/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t >index 441acf670d..aa0618af8e 100755 >--- a/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t >+++ b/t/db_dependent/Koha/Biblio/Metadata/Extractor/MARC.t >@@ -20,17 +20,42 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 2; >+use Test::More tests => 3; > use Test::Exception; > > use t::lib::TestBuilder; > use t::lib::Mocks; > >+use Koha::Biblios; > use Koha::Biblio::Metadata::Extractor; > > my $schema = Koha::Database->schema; > my $builder = t::lib::TestBuilder->new; > >+subtest 'new' => sub { >+ plan tests => 6; >+ >+ my ( $extractor, $params, $record, $biblio ); >+ throws_ok { $extractor = Koha::Biblio::Metadata::Extractor->new } 'Koha::Exceptions::MissingParameter', >+ 'No parameters'; >+ $params = { metadata => q{} }; >+ throws_ok { $extractor = Koha::Biblio::Metadata::Extractor->new($params) } 'Koha::Exceptions::MissingParameter', >+ 'metadata empty'; >+ $params = { metadata => '123' }; >+ throws_ok { $extractor = Koha::Biblio::Metadata::Extractor->new($params) } 'Koha::Exceptions::BadParameter', >+ 'metadata no object'; >+ $params = { metadata => q{}, biblio => 1 }; >+ throws_ok { $extractor = Koha::Biblio::Metadata::Extractor->new($params) } 'Koha::Exceptions::BadParameter', >+ 'biblio no object'; >+ >+ $record = MARC::Record->new; >+ $params = { metadata => $record }; >+ lives_ok { $extractor = Koha::Biblio::Metadata::Extractor->new($params) } 'correct metadata'; >+ $biblio = Koha::Biblio->new; >+ $params = { metadata => q{}, biblio => $biblio }; >+ lives_ok { $extractor = Koha::Biblio::Metadata::Extractor->new($params) } 'correct biblio overrules metadata'; >+}; >+ > subtest 'get_control_number() tests' => sub { > > plan tests => 8; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 41031
: 187981 |
187982