Bug 25006: Regression tests

This patch introduces regression tests for as_marc_field. It makes sure
there are empty subfields and then uses List::MoreUtils' all to verify
all generated MARC subfields contain something (i.e. the undef ones are
skipped).

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
Tomas Cohen Arazi 2020-03-27 16:36:25 -03:00 committed by Martin Renvoize
parent 192b9d55a0
commit e986d4d0ad
No known key found for this signature in database
GPG Key ID: 422B469130441A0F
1 changed files with 10 additions and 1 deletions

View File

@ -28,6 +28,8 @@ use Koha::Items;
use Koha::Database;
use Koha::Old::Items;
use List::MoreUtils qw(all);
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -91,11 +93,13 @@ subtest "as_marc_field() tests" => sub {
my @schema_columns = $schema->resultset('Item')->result_source->columns;
my @mapped_columns = grep { exists $mss->{'items.'.$_} } @schema_columns;
plan tests => 2 * (scalar @mapped_columns + 1) + 1;
plan tests => 2 * (scalar @mapped_columns + 1) + 2;
$schema->storage->txn_begin;
my $item = $builder->build_sample_item;
# Make sure it has at least one undefined attribute
$item->set({ replacementprice => undef })->store->discard_changes;
# Tests with the mss parameter
my $marc_field = $item->as_marc_field({ mss => $mss });
@ -141,6 +145,11 @@ subtest "as_marc_field() tests" => sub {
$item->more_subfields_xml( C4::Items::_get_unlinked_subfields_xml( \@unlinked_subfields ) )->store;
$marc_field = $item->as_marc_field;
my @subfields = $marc_field->subfields;
my $result = all { defined $_->[1] } @subfields;
ok( $result, 'There are no undef subfields' );
is( scalar $marc_field->subfield('X'), 'Something weird', 'more_subfield_xml is considered' );
$schema->storage->txn_rollback;