aff28cbf7dc69f426394eb02643d3374a826a4e6
[srvgit] / t / Koha / Util / MARC.t
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
9 #
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
17
18 use Modern::Perl;
19
20 use Test::More tests => 2;
21
22 BEGIN { use_ok('Koha::Util::MARC'); }
23
24 subtest 'set_marc_field' => sub {
25     plan tests => 6;
26
27     my $record = MARC::Record->new();
28
29     Koha::Util::MARC::set_marc_field($record, '999$9', 'foobar');
30     my @fields = $record->field('999');
31     is(scalar @fields, 1, 'Created one field');
32     my @subfields = $fields[0]->subfield('9');
33     is(scalar @subfields, 1, 'Created one subfield');
34     is($subfields[0], 'foobar', 'Created subfield has correct value');
35
36     Koha::Util::MARC::set_marc_field($record, '999$9', 'foobaz');
37     @fields = $record->field('999');
38     is(scalar @fields, 1, 'No additional field created');
39     @subfields = $fields[0]->subfield('9');
40     is(scalar @subfields, 1, 'No additional subfield created');
41     is($subfields[0], 'foobaz', 'Subfield value has been changed');
42 };