From 0fbfa7400729f8b1a336bf59b290982347e9b2ce Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 20 Dec 2019 08:20:23 +0000 Subject: [PATCH] Bug 24276: Add unit tests for mandatory parameter of FillWithDefaultValues Content-Type: text/plain; charset=utf-8 Test plan: Run t/db_dependent/Acquisition/FillWithDefaultValues.t Signed-off-by: Marcel de Rooy --- t/db_dependent/Acquisition/FillWithDefaultValues.t | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/t/db_dependent/Acquisition/FillWithDefaultValues.t b/t/db_dependent/Acquisition/FillWithDefaultValues.t index f70ae1e0b6..23c23295ce 100755 --- a/t/db_dependent/Acquisition/FillWithDefaultValues.t +++ b/t/db_dependent/Acquisition/FillWithDefaultValues.t @@ -1,5 +1,5 @@ use Modern::Perl; -use Test::More tests => 5; +use Test::More tests => 11; use Test::MockModule; use MARC::Record; @@ -21,7 +21,7 @@ $biblio_module->mock( { # default value for an existing field '245' => { - c => { defaultvalue => $default_author }, + c => { defaultvalue => $default_author, mandatory => 1 }, mandatory => 0, repeatable => 0, tab => 0, @@ -32,6 +32,11 @@ $biblio_module->mock( '099' => { x => { defaultvalue => $default_x }, }, + '942' => { + c => { defaultvalue => 'BK', mandatory => 1 }, + d => { defaultvalue => '942d_val' }, + f => { defaultvalue => '942f_val' }, + }, }; } ); @@ -81,3 +86,21 @@ is_deeply( [ [ 'x', $default_x ] ], '099$x contains the default value' ); +is( $record->subfield('942','d'), '942d_val', 'Check 942d' ); + +# Now test only_mandatory parameter +$record->delete_fields( $record->field('245') ); +$record->delete_fields( $record->field('942') ); +$record->append_fields( MARC::Field->new('942','','','f'=>'f val') ); +# We deleted 245 and replaced 942. If we only apply mandatories, we should get +# back 245c again and 942c but not 942d. 942f should be left alone. +C4::Acquisition::FillWithDefaultValues($record, { only_mandatory => 1 }); +@fields_245 = $record->field(245); +is( scalar @fields_245, 1, 'Only one 245 expected' ); +is( $record->subfield('245','c'), $default_author, '245c restored' ); +is( $record->subfield('942','c'), 'BK', '942c also restored' ); +is( $record->subfield('942','d'), undef, '942d should not be there' ); +is( $record->subfield('942','f'), 'f val', '942f untouched' ); + +# Rollback +$schema->storage->txn_begin; -- 2.11.0