DBRev Bug 15084 - Move the currency related code to
[koha.git] / t / Biblio / TransformHtmlToXml.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 => 3;
21 use t::lib::Mocks;
22
23 use XML::Simple;
24
25 use C4::Biblio qw/TransformHtmlToXml/;
26
27
28 sub run_tests {
29
30     my ($marc_flavour) = @_;
31
32     t::lib::Mocks::mock_preference('marcflavour', $marc_flavour);
33
34     my ( $tags, $subfields );
35     if ( $marc_flavour eq 'UNIMARC' ) {
36         $tags= [ '001', '600',  '200', '200' ];
37         $subfields = [ '', 'a', 'a', 'c' ];
38     } else {
39         $tags= [ '001', '100',  '245', '245' ];
40         $subfields = [ '', 'a', 'a', 'c' ];
41     }
42     my $values = [ '12345', 'author', 'title', 'resp' ];
43     my $ind = [ '  ', '00', ' 9', '  ' ];
44
45     my $xml = TransformHtmlToXml( $tags, $subfields, $values, $ind, undef, $marc_flavour );
46     my $xmlh = XML::Simple->new->XMLin( $xml );
47
48     # check number of controlfields
49     is( ref $xmlh->{record}->{controlfield}, 'HASH', 'One controlfield' );
50     # check datafields
51     my $cnt = @{$xmlh->{record}->{datafield}};
52     if ( $marc_flavour eq 'UNIMARC' ) {
53         is( $cnt, 3, 'Three datafields' ); # 100$a is automatically created
54     } else {
55         is( $cnt, 2, 'Two datafields' );
56     }
57     # check value of 245c
58     is( $xmlh->{record}->{datafield}->[1]->{subfield}->[1]->{content}, 'resp', 'Check value' );
59     # check second indicator of 245
60     is( $xmlh->{record}->{datafield}->[1]->{ind2}, '9', 'Check indicator' );
61 }
62
63 subtest "->TransformHtmlToXml (MARC21) tests" => sub {
64
65     plan tests => 4;
66     run_tests('MARC21');
67 };
68
69 subtest "->TransformHtmlToXml (UNIMARC) tests" => sub {
70
71     plan tests => 4;
72     run_tests('UNIMARC');
73 };
74
75 subtest "->TransformHtmlToXml (NORMARC) tests" => sub {
76     plan tests => 4;
77     run_tests('NORMARC');
78 };
79
80 1;