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 with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA 02111-1307 USA
22 use strict; use warnings; #FIXME: turn off warnings before release
24 # specify the number of tests
25 use Test::More tests => 23;
31 Record_test.pl - test suite for Record.pm
35 $ export KOHA_CONF=/path/to/koha.conf
40 ## FIXME: Preliminarily grab the modules dir so we can run this in context
42 ok (1, 'module compiled');
44 # open some files for testing
45 open MARC21MARC8,"testrecords/marc21_marc8.dat" or die $!;
46 my $marc21_marc8; # = scalar (MARC21MARC8);
47 foreach my $line (<MARC21MARC8>) {
48 $marc21_marc8 .= $line;
50 $marc21_marc8 =~ s/\n$//;
53 open (MARC21UTF8,"<:utf8","testrecords/marc21_utf8.dat") or die $!;
55 foreach my $line (<MARC21UTF8>) {
56 $marc21_utf8 .= $line;
58 $marc21_utf8 =~ s/\n$//;
61 open MARC21MARC8COMBCHARS,"testrecords/marc21_marc8_combining_chars.dat" or die $!;
62 my $marc21_marc8_combining_chars;
63 foreach my $line(<MARC21MARC8COMBCHARS>) {
64 $marc21_marc8_combining_chars.=$line;
66 $marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here?
67 close MARC21MARC8COMBCHARS;
69 open (MARC21UTF8COMBCHARS,"<:utf8","testrecords/marc21_utf8_combining_chars.dat") or die $!;
70 my $marc21_utf8_combining_chars;
71 foreach my $line(<MARC21UTF8COMBCHARS>) {
72 $marc21_utf8_combining_chars.=$line;
74 close MARC21UTF8COMBCHARS;
76 open (MARCXMLUTF8,"<:utf8","testrecords/marcxml_utf8.xml") or die $!;
78 foreach my $line (<MARCXMLUTF8>) {
79 $marcxml_utf8 .= $line;
83 $marcxml_utf8 =~ s/\n//g;
86 my $error; my $marc; my $marcxml; my $dcxml; # some scalars to store values
88 print "\n1. Checking conversion of simple ISO-2709 (MARC21) records to MARCXML\n";
89 ok (($error,$marcxml) = marc2marcxml($marc21_marc8,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 (MARC21)');
90 ok (!$error, 'no errors in conversion');
92 $marcxml =~ s/v\/ s/v\/s/g; # FIXME: bug in new_from_xml_record!!
93 is ($marcxml,$marcxml_utf8, 'record matches antitype');
95 ok (($error,$marcxml) = marc2marcxml($marc21_utf8,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 (MARC21)');
96 ok (!$error, 'no errors in conversion');
98 $marcxml =~ s/v\/ s/v\/s/g;
99 is ($marcxml,$marcxml_utf8, 'record matches antitype');
101 print "\n2. checking binary MARC21 records with combining characters to MARCXML\n";
102 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'MARC-8','MARC21'), 'marc2marcxml - from MARC-8 to MARC-8 with combining characters(MARC21)');
103 ok (!$error, 'no errors in conversion');
105 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 with combining characters (MARC21)');
106 ok (!$error, 'no errors in conversion');
108 ok (($error,$marcxml) = marc2marcxml($marc21_utf8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 with combining characters (MARC21)');
109 ok (!$error, 'no errors in conversion');
111 ok (($error,$dcxml) = marc2dcxml($marc21_utf8), 'marc2dcxml - from ISO-2709 to Dublin Core');
112 ok (!$error, 'no errors in conversion');
114 print "\n3. checking ability to alter encoding\n";
115 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from MARC-8 to UTF-8');
116 ok (!$error, 'no errors in conversion');
118 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from UTF-8 to MARC-8');
119 ok (!$error, 'no errors in conversion');
121 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from MARC-8 to MARC-8');
122 ok (!$error, 'no errors in conversion');
124 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from UTF-8 to UTF-8');
125 ok (!$error, 'no errors in conversion');
131 Still lots more to test including UNIMARC support
135 Joshua Ferraro <jmf@liblime.com>