Bug 14639: (QA followup) make schema mandatory

This patch makes the 'schema' param mandatory. It is passed in every
call on the current codebase, so it makes no harm now, but makes
the code less error-prone.

Tests for this situation are added to t/Koha_MetadataRecord.t (schema
param is omitted and new() returns undef and a carped warning).

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Tomas Cohen Arazi 2015-09-03 10:13:18 -03:00
parent 2afaddb592
commit 40fc2a99c1
2 changed files with 19 additions and 5 deletions

View File

@ -82,8 +82,13 @@ sub new {
return;
}
if (!defined $params->{ schema }) {
carp 'No schema passed';
return;
}
my $record = $params->{ record };
my $schema = $params->{ schema } // 'marc21';
my $schema = $params->{ schema };
my $format = $params->{ format } // 'MARC';
my $id = $params->{ id };

View File

@ -100,17 +100,26 @@ is($dupkeys, 0, 'No duplicate keys');
subtest "new() tests" => sub {
plan tests => 12;
plan tests => 14;
# Test default values with a MARC::Record record
my $record = MARC::Record->new();
my $metadata_record = new Koha::MetadataRecord({
record => $record
my $metadata_record;
warning_is { $metadata_record = new Koha::MetadataRecord({
record => $record }) }
{ carped => 'No schema passed' },
"Metadata schema is mandatory, raise a carped warning if omitted";
is( $metadata_record, undef, "Metadata schema is mandatory, return undef if omitted");
$metadata_record = new Koha::MetadataRecord({
record => $record,
schema => 'marc21'
});
is( ref($metadata_record), 'Koha::MetadataRecord', 'Type correct');
is( ref($metadata_record->record), 'MARC::Record', 'Record type preserved');
is( $metadata_record->schema, 'marc21', 'Metadata schema defaults to marc21');
is( $metadata_record->schema, 'marc21', 'Metadata schema is set to marc21');
is( $metadata_record->format, 'MARC', 'Serializacion format defaults to marc');
is( $metadata_record->id, undef, 'id is optional, undef if unspecifid');