2 use Test::More tests => 5;
9 use C4::Acquisition qw( FillWithDefaultValues );
11 my $dbh = C4::Context->dbh;
12 $dbh->{AutoCommit} = 0;
13 $dbh->{RaiseError} = 1;
15 my $biblio_module = Test::MockModule->new('C4::Biblio');
16 my $default_author = 'default author';
17 my $default_x = 'my default value';
22 # default value for an existing field
24 c => { defaultvalue => $default_author },
31 # default for a nonexisting field
33 x => { defaultvalue => $default_x },
39 my $record = MARC::Record->new;
40 $record->leader('03174nam a2200445 a 4500');
44 a => 'Knuth, Donald Ervin',
49 a => 'The art of computer programming',
50 c => 'Donald E. Knuth.',
53 245, '1', '4', a => 'my second title',
57 $record->append_fields(@fields);
59 C4::Acquisition::FillWithDefaultValues($record);
61 my @fields_245 = $record->field(245);
62 is( scalar(@fields_245), 2, 'No new 245 field has been created' );
63 my @subfields_245_0 = $fields_245[0]->subfields;
64 my @subfields_245_1 = $fields_245[1]->subfields;
67 [ [ 'a', 'The art of computer programming' ], [ 'c', 'Donald E. Knuth.' ] ],
68 'first 245 field has not been updated'
72 [ [ 'a', 'my second title' ], [ 'c', $default_author ] ],
73 'second 245 field has a new subfield c with a default value'
76 my @fields_099 = $record->field('099');
77 is( scalar(@fields_099), 1, '1 new 099 field has been created' );
78 my @subfields_099 = $fields_099[0]->subfields;
81 [ [ 'x', $default_x ] ],
82 '099$x contains the default value'