Bug 41031: Add checks on metadata and biblio in Extractor::MARC->new
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> Signed-off-by: Owen Leonard <oleonard@myacpl.org> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
6a8b160a2f
commit
4d2e2b8288
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue