Bug 21395: Make perlcritic happy
[koha.git] / t / db_dependent / Record / Record.t
blob6fb335fa22c6daa28bc1498dfb8c4b61219615de
1 #!/usr/bin/perl
3 # Copyright 2006 (C) LibLime
4 # Joshua Ferraro <jmf@liblime.com>
6 # This file is part of Koha.
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
22 use strict;
23 use warnings;
25 use constant WHEREAMI => 't/db_dependent/Record/testrecords';
27 # specify the number of tests
28 use Test::More tests => 21; #FIXME Commented out two failing tests
29 #use C4::Context;
30 use C4::Record;
32 =head1 NAME
34 Record_test.pl - test suite for Record.pm
36 =head1 SYNOPSIS
38 $ export KOHA_CONF=/path/to/koha.conf
39 $ ./Record_test.pl
41 =cut
43 ## FIXME: Preliminarily grab the modules dir so we can run this in context
45 ok (1, 'module compiled');
47 # open some files for testing
48 open my $MARC21MARC8, '<', WHEREAMI."/marc21_marc8.dat" or die $!;
49 my $marc21_marc8; # = scalar (MARC21MARC8);
50 foreach my $line (<$MARC21MARC8>) {
51 $marc21_marc8 .= $line;
53 $marc21_marc8 =~ s/\n$//;
54 close $MARC21MARC8;
56 open (my $MARC21UTF8, '<:encoding(UTF-8)', WHEREAMI."/marc21_utf8.dat") or die $!;
57 my $marc21_utf8;
58 foreach my $line (<$MARC21UTF8>) {
59 $marc21_utf8 .= $line;
61 $marc21_utf8 =~ s/\n$//;
62 close $MARC21UTF8;
64 open(my $MARC21MARC8COMBCHARS, '<', WHEREAMI."/marc21_marc8_combining_chars.dat" or die $!;
65 my $marc21_marc8_combining_chars;
66 foreach my $line(<$MARC21MARC8COMBCHARS>) {
67 $marc21_marc8_combining_chars.=$line;
69 $marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here?
70 close $MARC21MARC8COMBCHARS;
72 open (my $MARC21UTF8COMBCHARS, '<:encoding(UTF-8)', WHEREAMI."/marc21_utf8_combining_chars.dat") or die $!;
73 my $marc21_utf8_combining_chars;
74 foreach my $line(<$MARC21UTF8COMBCHARS>) {
75 $marc21_utf8_combining_chars.=$line;
77 close $MARC21UTF8COMBCHARS;
79 open (my $MARCXMLUTF8, '<:encoding(UTF-8)', WHEREAMI."/marcxml_utf8.xml") or die $!;
80 my $marcxml_utf8;
81 foreach my $line (<$MARCXMLUTF8>) {
82 $marcxml_utf8 .= $line;
84 close $MARCXMLUTF8;
86 $marcxml_utf8 =~ s/\n//g;
88 ## The Tests:
89 my $error; my $marc; my $marcxml; # some scalars to store values
90 ## MARC to MARCXML
91 print "\n1. Checking conversion of simple ISO-2709 (MARC21) records to MARCXML\n";
92 ok (($error,$marcxml) = marc2marcxml($marc21_marc8,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 (MARC21)');
93 ok (!$error, 'no errors in conversion');
94 #FIXME This test fails
95 # $marcxml =~ s/\n//g;
96 # $marcxml =~ s/v\/ s/v\/s/g; # FIXME: bug in new_from_xml_record!!
97 #is ($marcxml,$marcxml_utf8, 'record matches antitype');
99 ok (($error,$marcxml) = marc2marcxml($marc21_utf8,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 (MARC21)');
100 ok (!$error, 'no errors in conversion');
101 #FIXME This test fails
102 # $marcxml =~ s/\n//g;
103 # $marcxml =~ s/v\/ s/v\/s/g;
104 #is ($marcxml,$marcxml_utf8, 'record matches antitype');
106 print "\n2. checking binary MARC21 records with combining characters to MARCXML\n";
107 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'MARC-8','MARC21'), 'marc2marcxml - from MARC-8 to MARC-8 with combining characters(MARC21)');
108 ok (!$error, 'no errors in conversion');
110 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 with combining characters (MARC21)');
111 ok (!$error, 'no errors in conversion');
113 ok (($error,$marcxml) = marc2marcxml($marc21_utf8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 with combining characters (MARC21)');
114 ok (!$error, 'no errors in conversion');
116 ok (eval{marc2dcxml($marc21_utf8, undef, undef, 'oaidc')}, 'marc2dcxml - from ISO-2709 to Dublin Core');
117 $error = $@;
118 ok (!$error, 'no errors in conversion to DublinCore');
120 print "\n3. checking ability to alter encoding\n";
121 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from MARC-8 to UTF-8');
122 ok (!$error, 'no errors in conversion');
124 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from UTF-8 to MARC-8');
125 ok (!$error, 'no errors in conversion');
127 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from MARC-8 to MARC-8');
128 ok (!$error, 'no errors in conversion');
130 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from UTF-8 to UTF-8');
131 ok (!$error, 'no errors in conversion');
133 __END__
135 =head1 TODO
137 Still lots more to test including UNIMARC support
139 =head1 AUTHOR
141 Joshua Ferraro <jmf@liblime.com>
143 =head1 MODIFICATIONS
146 =cut