From e021d93c311d96bc90dee390419f1f3c456608f7 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 12 Dec 2016 22:38:40 +0000 Subject: [PATCH] Bug 17726: TestBuilder - Add default values The items.more_subfields_xml is set to random data (generated by TestBuilder), and so GetMarcBiblio does not manage to embed items (if needed). The error is: :1: parser error : Start tag expected, '<' not found More precisely it explodes in C4::Items::_parse_unlinked_item_subfields_from_xml when MARC::Record->new_from_xml is called with an invalid xml This patch adds a default values mechanism to TestBuilder to avoid modifying all the existing calls. Test plan: Set SearchEngine to ElasticSearch prove t/db_dependent/Circulation.pl should return green with this patch Signed-off-by: Marcel de Rooy Signed-off-by: Kyle M Hall (cherry picked from commit 41358176e1d276e47d3034a37bd089b7e6c7e846) Signed-off-by: Katrin Fischer --- t/db_dependent/TestBuilder.t | 11 ++++++++++- t/lib/TestBuilder.pm | 15 +++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/TestBuilder.t b/t/db_dependent/TestBuilder.t index 3046ad8580..4d93cee948 100644 --- a/t/db_dependent/TestBuilder.t +++ b/t/db_dependent/TestBuilder.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use Test::Warn; use Data::Dumper qw(Dumper); @@ -332,6 +332,15 @@ subtest 'Date handling' => sub { }; +subtest 'Default values' => sub { + plan tests => 2; + $builder = t::lib::TestBuilder->new; + my $item = $builder->build( { source => 'Item' } ); + is( $item->{more_subfields_xml}, undef ); + $item = $builder->build( { source => 'Item', value => { more_subfields_xml => 'some xml' } } ); + is( $item->{more_subfields_xml}, 'some xml' ); +}; + $schema->storage->txn_rollback; 1; diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index 666cc87617..0d312d0c54 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -13,6 +13,7 @@ sub new { $self->schema->storage->sql_maker->quote_char('`'); $self->{gen_type} = _gen_type(); + $self->{default_values} = _gen_default_values(); return $self; } @@ -290,6 +291,8 @@ sub _buildColumnValue { return; } push @$retvalue, $value->{$col_name}; + } elsif( exists $self->{default_values}{$source}{$col_name} ) { + push @$retvalue, $self->{default_values}{$source}{$col_name}; } else { my $data_type = $col_info->{data_type}; $data_type =~ s| |_|; @@ -414,6 +417,18 @@ sub _gen_blob { return 'b'; } +sub _gen_default_values { + my ($self) = @_; + return { + Item => { + more_subfields_xml => undef, + }, + Biblioitem => { + marcxml => undef, + } + }; +} + =head1 NAME t::lib::TestBuilder.pm - Koha module to create test records -- 2.39.5