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 under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
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
34 Record_test.pl - test suite for Record.pm
38 $ export KOHA_CONF=/path/to/koha.conf
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 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$//;
56 open (MARC21UTF8,"<:utf8",WHEREAMI."/marc21_utf8.dat") or die $!;
58 foreach my $line (<MARC21UTF8>) {
59 $marc21_utf8 .= $line;
61 $marc21_utf8 =~ s/\n$//;
64 open 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 (MARC21UTF8COMBCHARS,"<:utf8",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 (MARCXMLUTF8,"<:utf8",WHEREAMI."/marcxml_utf8.xml") or die $!;
81 foreach my $line (<MARCXMLUTF8>) {
82 $marcxml_utf8 .= $line;
86 $marcxml_utf8 =~ s/\n//g;
89 my $error; my $marc; my $marcxml; my $dcxml; # some scalars to store values
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 (($error,$dcxml) = marc2dcxml($marc21_utf8), 'marc2dcxml - from ISO-2709 to Dublin Core');
117 ok (!$error, 'no errors in conversion');
119 print "\n3. checking ability to alter encoding\n";
120 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from MARC-8 to UTF-8');
121 ok (!$error, 'no errors in conversion');
123 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from UTF-8 to MARC-8');
124 ok (!$error, 'no errors in conversion');
126 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from MARC-8 to MARC-8');
127 ok (!$error, 'no errors in conversion');
129 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from UTF-8 to UTF-8');
130 ok (!$error, 'no errors in conversion');
136 Still lots more to test including UNIMARC support
140 Joshua Ferraro <jmf@liblime.com>