Patch from Galen Charlton, removing $Id$ $Log$ and $Revision$ from files
[koha.git] / C4 / tests / Record_test.pl
1 #!/usr/bin/perl
2 #
3 # Copyright 2006 (C) LibLime
4 # Joshua Ferraro <jmf@liblime.com>
5 #
6 # This file is part of Koha.
7 #
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
11 # version.
12 #
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.
16 #
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
20 #
21 #
22 use strict; use warnings; #FIXME: turn off warnings before release
23
24 # specify the number of tests
25 use Test::More tests => 23;
26 #use C4::Context;
27 use C4::Record;
28
29 =head1 NAME
30
31 Record_test.pl - test suite for Record.pm
32
33 =head1 SYNOPSIS
34
35 $ export KOHA_CONF=/path/to/koha.conf
36 $ ./Record_test.pl
37
38 =cut
39
40 ## FIXME: Preliminarily grab the modules dir so we can run this in context
41
42 ok (1, 'module compiled');
43
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;
49 }
50 $marc21_marc8 =~ s/\n$//;
51 close MARC21MARC8;
52
53 open (MARC21UTF8,"<:utf8","testrecords/marc21_utf8.dat") or die $!;
54 my $marc21_utf8;
55 foreach my $line (<MARC21UTF8>) {
56         $marc21_utf8 .= $line;
57 }
58 $marc21_utf8 =~ s/\n$//;
59 close MARC21UTF8;
60
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;
65 }
66 $marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here?
67 close MARC21MARC8COMBCHARS;
68
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;
73 }
74 close MARC21UTF8COMBCHARS;
75
76 open (MARCXMLUTF8,"<:utf8","testrecords/marcxml_utf8.xml") or die $!;
77 my $marcxml_utf8;
78 foreach my $line (<MARCXMLUTF8>) {
79         $marcxml_utf8 .= $line;
80 }
81 close MARCXMLUTF8;
82
83 $marcxml_utf8 =~ s/\n//g;
84
85 ## The Tests:
86 my $error; my $marc; my $marcxml; my $dcxml; # some scalars to store values
87 ## MARC to MARCXML
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');
91         $marcxml =~ s/\n//g; 
92         $marcxml =~ s/v\/ s/v\/s/g; # FIXME: bug in new_from_xml_record!!
93 is ($marcxml,$marcxml_utf8, 'record matches antitype');
94
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');
97         $marcxml =~ s/\n//g;
98         $marcxml =~ s/v\/ s/v\/s/g;
99 is ($marcxml,$marcxml_utf8, 'record matches antitype');
100
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');
104
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');
107
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');
110
111 ok (($error,$dcxml) = marc2dcxml($marc21_utf8), 'marc2dcxml - from ISO-2709 to Dublin Core');
112 ok (!$error, 'no errors in conversion');
113
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');
117
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');
120
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');
123
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');
126
127 __END__
128
129 =head1 TODO
130
131 Still lots more to test including UNIMARC support
132
133 =head1 AUTHOR
134
135 Joshua Ferraro <jmf@liblime.com>
136
137 =head1 MODIFICATIONS
138
139
140 =cut