|
Lines 1-5
Link Here
|
| 1 |
use Modern::Perl; |
1 |
use Modern::Perl; |
| 2 |
use Test::More tests => 5; |
2 |
use Test::More tests => 11; |
| 3 |
use Test::MockModule; |
3 |
use Test::MockModule; |
| 4 |
|
4 |
|
| 5 |
use MARC::Record; |
5 |
use MARC::Record; |
|
Lines 21-27
$biblio_module->mock(
Link Here
|
| 21 |
{ |
21 |
{ |
| 22 |
# default value for an existing field |
22 |
# default value for an existing field |
| 23 |
'245' => { |
23 |
'245' => { |
| 24 |
c => { defaultvalue => $default_author }, |
24 |
c => { defaultvalue => $default_author, mandatory => 1 }, |
| 25 |
mandatory => 0, |
25 |
mandatory => 0, |
| 26 |
repeatable => 0, |
26 |
repeatable => 0, |
| 27 |
tab => 0, |
27 |
tab => 0, |
|
Lines 32-37
$biblio_module->mock(
Link Here
|
| 32 |
'099' => { |
32 |
'099' => { |
| 33 |
x => { defaultvalue => $default_x }, |
33 |
x => { defaultvalue => $default_x }, |
| 34 |
}, |
34 |
}, |
|
|
35 |
'942' => { |
| 36 |
c => { defaultvalue => 'BK', mandatory => 1 }, |
| 37 |
d => { defaultvalue => '942d_val' }, |
| 38 |
f => { defaultvalue => '942f_val' }, |
| 39 |
}, |
| 35 |
}; |
40 |
}; |
| 36 |
} |
41 |
} |
| 37 |
); |
42 |
); |
|
Lines 81-83
is_deeply(
Link Here
|
| 81 |
[ [ 'x', $default_x ] ], |
86 |
[ [ 'x', $default_x ] ], |
| 82 |
'099$x contains the default value' |
87 |
'099$x contains the default value' |
| 83 |
); |
88 |
); |
| 84 |
- |
89 |
is( $record->subfield('942','d'), '942d_val', 'Check 942d' ); |
|
|
90 |
|
| 91 |
# Now test only_mandatory parameter |
| 92 |
$record->delete_fields( $record->field('245') ); |
| 93 |
$record->delete_fields( $record->field('942') ); |
| 94 |
$record->append_fields( MARC::Field->new('942','','','f'=>'f val') ); |
| 95 |
# We deleted 245 and replaced 942. If we only apply mandatories, we should get |
| 96 |
# back 245c again and 942c but not 942d. 942f should be left alone. |
| 97 |
C4::Acquisition::FillWithDefaultValues($record, { only_mandatory => 1 }); |
| 98 |
@fields_245 = $record->field(245); |
| 99 |
is( scalar @fields_245, 1, 'Only one 245 expected' ); |
| 100 |
is( $record->subfield('245','c'), $default_author, '245c restored' ); |
| 101 |
is( $record->subfield('942','c'), 'BK', '942c also restored' ); |
| 102 |
is( $record->subfield('942','d'), undef, '942d should not be there' ); |
| 103 |
is( $record->subfield('942','f'), 'f val', '942f untouched' ); |
| 104 |
|
| 105 |
# Rollback |
| 106 |
$schema->storage->txn_rollback; |