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
23 use strict; use warnings; #FIXME: turn off warnings before release
25 # specify the number of tests
26 use Test::More tests => 23;
32 Record_test.pl - test suite for Record.pm
36 $ export KOHA_CONF=/path/to/koha.conf
41 ## FIXME: Preliminarily grab the modules dir so we can run this in context
43 ok (1, 'module compiled');
45 # open some files for testing
46 open MARC21MARC8,"testrecords/marc21_marc8.dat" or die $!;
47 my $marc21_marc8; # = scalar (MARC21MARC8);
48 foreach my $line (<MARC21MARC8>) {
49 $marc21_marc8 .= $line;
51 $marc21_marc8 =~ s/\n$//;
54 open (MARC21UTF8,"<:utf8","testrecords/marc21_utf8.dat") or die $!;
56 foreach my $line (<MARC21UTF8>) {
57 $marc21_utf8 .= $line;
59 $marc21_utf8 =~ s/\n$//;
62 open MARC21MARC8COMBCHARS,"testrecords/marc21_marc8_combining_chars.dat" or die $!;
63 my $marc21_marc8_combining_chars;
64 foreach my $line(<MARC21MARC8COMBCHARS>) {
65 $marc21_marc8_combining_chars.=$line;
67 $marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here?
68 close MARC21MARC8COMBCHARS;
70 open (MARC21UTF8COMBCHARS,"<:utf8","testrecords/marc21_utf8_combining_chars.dat") or die $!;
71 my $marc21_utf8_combining_chars;
72 foreach my $line(<MARC21UTF8COMBCHARS>) {
73 $marc21_utf8_combining_chars.=$line;
75 close MARC21UTF8COMBCHARS;
77 open (MARCXMLUTF8,"<:utf8","testrecords/marcxml_utf8.xml") or die $!;
79 foreach my $line (<MARCXMLUTF8>) {
80 $marcxml_utf8 .= $line;
84 $marcxml_utf8 =~ s/\n//g;
87 my $error; my $marc; my $marcxml; my $dcxml; # some scalars to store values
89 print "\n1. Checking conversion of simple ISO-2709 (MARC21) records to MARCXML\n";
90 ok (($error,$marcxml) = marc2marcxml($marc21_marc8,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 (MARC21)');
91 ok (!$error, 'no errors in conversion');
93 $marcxml =~ s/v\/ s/v\/s/g; # FIXME: bug in new_from_xml_record!!
94 is ($marcxml,$marcxml_utf8, 'record matches antitype');
96 ok (($error,$marcxml) = marc2marcxml($marc21_utf8,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 (MARC21)');
97 ok (!$error, 'no errors in conversion');
99 $marcxml =~ s/v\/ s/v\/s/g;
100 is ($marcxml,$marcxml_utf8, 'record matches antitype');
102 print "\n2. checking binary MARC21 records with combining characters to MARCXML\n";
103 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'MARC-8','MARC21'), 'marc2marcxml - from MARC-8 to MARC-8 with combining characters(MARC21)');
104 ok (!$error, 'no errors in conversion');
106 ok (($error,$marcxml) = marc2marcxml($marc21_marc8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from MARC-8 to UTF-8 with combining characters (MARC21)');
107 ok (!$error, 'no errors in conversion');
109 ok (($error,$marcxml) = marc2marcxml($marc21_utf8_combining_chars,'UTF-8','MARC21'), 'marc2marcxml - from UTF-8 to UTF-8 with combining characters (MARC21)');
110 ok (!$error, 'no errors in conversion');
112 ok (($error,$dcxml) = marc2dcxml($marc21_utf8), 'marc2dcxml - from ISO-2709 to Dublin Core');
113 ok (!$error, 'no errors in conversion');
115 print "\n3. checking ability to alter encoding\n";
116 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from MARC-8 to UTF-8');
117 ok (!$error, 'no errors in conversion');
119 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from UTF-8 to MARC-8');
120 ok (!$error, 'no errors in conversion');
122 ok (($error,$marc) = changeEncoding($marc21_marc8,'MARC','MARC21','MARC-8'), 'changeEncoding - MARC21 from MARC-8 to MARC-8');
123 ok (!$error, 'no errors in conversion');
125 ok (($error,$marc) = changeEncoding($marc21_utf8,'MARC','MARC21','UTF-8'), 'changeEncoding - MARC21 from UTF-8 to UTF-8');
126 ok (!$error, 'no errors in conversion');
132 Still lots more to test including UNIMARC support
136 Joshua Ferraro <jmf@liblime.com>