From d14f17b0c766f5df963cba2ff794c259fab2d42d Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 2 Sep 2015 15:07:07 +0100 Subject: [PATCH] Bug 11247: Improve tests This patch makes the tests non dependent on the DB and test the 3 marc flavours. --- t/Biblio/TransformHtmlToXml.t | 80 ++++++++++++++++++++++++++++++ t/db_dependent/Biblio/TransformHtmlToXml.t | 25 ---------- 2 files changed, 80 insertions(+), 25 deletions(-) create mode 100644 t/Biblio/TransformHtmlToXml.t delete mode 100644 t/db_dependent/Biblio/TransformHtmlToXml.t diff --git a/t/Biblio/TransformHtmlToXml.t b/t/Biblio/TransformHtmlToXml.t new file mode 100644 index 0000000..909fec3 --- /dev/null +++ b/t/Biblio/TransformHtmlToXml.t @@ -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 . + +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 index bbf8588..0000000 --- a/t/db_dependent/Biblio/TransformHtmlToXml.t +++ /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' ); -- 2.1.0