Bug 11247: Improve tests
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Wed, 2 Sep 2015 14:07:07 +0000 (15:07 +0100)
committerMason James <mtj@kohaaloha.com>
Mon, 28 Sep 2015 12:07:05 +0000 (01:07 +1300)
This patch makes the tests non dependent on the DB and test the 3 marc
flavours.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
(cherry picked from commit 6e0b61e2acea7c797c1da727474daf7d7a657574)
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
(cherry picked from commit 27ba1a6fa1a5be170d9bf04747f31caab15766b1)
Signed-off-by: Liz Rea <wizzyrea@gmail.com>

t/Biblio/TransformHtmlToXml.t [new file with mode: 0644]
t/db_dependent/Biblio/TransformHtmlToXml.t [deleted file]

diff --git a/t/Biblio/TransformHtmlToXml.t b/t/Biblio/TransformHtmlToXml.t
new file mode 100644 (file)
index 0000000..909fec3
--- /dev/null
@@ -0,0 +1,80 @@
+#!/usr/bin/perl
+
+# This file is part of Koha.
+#
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# Koha is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
+
+use Modern::Perl;
+
+use Test::More tests => 3;
+use t::lib::Mocks;
+
+use XML::Simple;
+
+use C4::Biblio qw/TransformHtmlToXml/;
+
+
+sub run_tests {
+
+    my ($marc_flavour) = @_;
+
+    t::lib::Mocks::mock_preference('marcflavour', $marc_flavour);
+
+    my ( $tags, $subfields );
+    if ( $marc_flavour eq 'UNIMARC' ) {
+        $tags= [ '001', '600',  '200', '200' ];
+        $subfields = [ '', 'a', 'a', 'c' ];
+    } else {
+        $tags= [ '001', '100',  '245', '245' ];
+        $subfields = [ '', 'a', 'a', 'c' ];
+    }
+    my $values = [ '12345', 'author', 'title', 'resp' ];
+    my $ind = [ '  ', '00', ' 9', '  ' ];
+
+    my $xml = TransformHtmlToXml( $tags, $subfields, $values, $ind, undef, $marc_flavour );
+    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}};
+    if ( $marc_flavour eq 'UNIMARC' ) {
+        is( $cnt, 3, 'Three datafields' ); # 100$a is automatically created
+    } else {
+        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' );
+}
+
+subtest "->TransformHtmlToXml (MARC21) tests" => sub {
+
+    plan tests => 4;
+    run_tests('MARC21');
+};
+
+subtest "->TransformHtmlToXml (UNIMARC) tests" => sub {
+
+    plan tests => 4;
+    run_tests('UNIMARC');
+};
+
+subtest "->TransformHtmlToXml (NORMARC) tests" => sub {
+    plan tests => 4;
+    run_tests('NORMARC');
+};
+
+1;
diff --git a/t/db_dependent/Biblio/TransformHtmlToXml.t b/t/db_dependent/Biblio/TransformHtmlToXml.t
deleted file mode 100644 (file)
index bbf8588..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-#!/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' );