Bug 11247: Add a simple unit test for TransformHtmlToXml
authorMarcel de Rooy <m.de.rooy@rijksmuseum.nl>
Wed, 26 Aug 2015 12:09:53 +0000 (14:09 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 2 Sep 2015 17:36:33 +0000 (14:36 -0300)
The unit test is db dependent (as Jonathan correctly remarked),
since the sub checks a preference.

Test plan:
Run t/db_dependent/Biblio/TransformHtmlToXml.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
t/db_dependent/Biblio/TransformHtmlToXml.t [new file with mode: 0644]

diff --git a/t/db_dependent/Biblio/TransformHtmlToXml.t b/t/db_dependent/Biblio/TransformHtmlToXml.t
new file mode 100644 (file)
index 0000000..bbf8588
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl
+
+use Modern::Perl;
+use Test::More tests => 4;
+use XML::Simple;
+
+use C4::Biblio qw/TransformHtmlToXml/;
+
+my $tags= [ '001', '100',  '245', '245' ];
+my $subfields = [ '', 'a', 'a', 'c' ];
+my $values = [ '12345', 'author', 'title', 'resp' ];
+my $ind = [ '  ', '00', ' 9', '  ' ];
+
+my $xml = TransformHtmlToXml( $tags, $subfields, $values, $ind, undef, 'MARC21' );
+my $xmlh = XML::Simple->new->XMLin( $xml );
+
+# check number of controlfields
+is( ref $xmlh->{record}->{controlfield}, 'HASH', 'One controlfield' );
+# check datafields
+my $cnt = @{$xmlh->{record}->{datafield}};
+is( $cnt, 2, 'Two datafields' );
+# check value of 245c
+is( $xmlh->{record}->{datafield}->[1]->{subfield}->[1]->{content}, 'resp', 'Check value' );
+# check second indicator of 245
+is( $xmlh->{record}->{datafield}->[1]->{ind2}, '9', 'Check indicator' );