Bug 9302: Use patron-title.inc
[koha.git] / t / Biblio / TransformHtmlToXml.t
blobbbbadd249fbdd1bd1f75234506805050cff4fe35
1 #!/usr/bin/perl
3 # This file is part of Koha.
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.
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.
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>.
18 use Modern::Perl;
20 use Test::More tests => 3;
21 use t::lib::Mocks;
23 use XML::Simple;
25 use C4::Biblio qw/TransformHtmlToXml/;
28 sub run_tests {
30 my ($marc_flavour) = @_;
32 t::lib::Mocks::mock_preference('marcflavour', $marc_flavour);
34 my ( $tags, $subfields );
35 if ( $marc_flavour eq 'UNIMARC' ) {
36 $tags= [ '001', '600', '200', '200', '400' ];
37 $subfields = [ '', 'a', 'a', 'c', 'a' ];
38 } else {
39 $tags= [ '001', '100', '245', '245', '400' ];
40 $subfields = [ '', 'a', 'a', 'c', 'a' ];
42 my $values = [ '12345', 'author', 'title', 'resp', '' ];
43 my $ind = [ ' ', '00', ' 9', ' ', ' ' ];
45 my $xml = TransformHtmlToXml( $tags, $subfields, $values, $ind, undef, $marc_flavour );
46 my $xmlh = XML::Simple->new->XMLin( $xml );
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' );
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' );
63 subtest "->TransformHtmlToXml (MARC21) tests" => sub {
65 plan tests => 4;
66 run_tests('MARC21');
69 subtest "->TransformHtmlToXml (UNIMARC) tests" => sub {
71 plan tests => 4;
72 run_tests('UNIMARC');
75 subtest "->TransformHtmlToXml (NORMARC) tests" => sub {
76 plan tests => 4;
77 run_tests('NORMARC');