0bbfb03568e3fa7b5e6eefe2ab10205518728bc8
[koha-equinox.git] / t / db_dependent / Record / Record.t
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
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.
12 #
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.
17 #
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>.
20 #
21 #
22 use strict;
23 use warnings;
24
25 use constant WHEREAMI => 't/db_dependent/Record/testrecords';
26
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;
31
32 =head1 NAME
33
34 Record_test.pl - test suite for Record.pm
35
36 =head1 SYNOPSIS
37
38 $ export KOHA_CONF=/path/to/koha.conf
39 $ ./Record_test.pl
40
41 =cut
42
43 ## FIXME: Preliminarily grab the modules dir so we can run this in context
44
45 ok (1, 'module compiled');
46
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;
52 }
53 $marc21_marc8 =~ s/\n$//;
54 close MARC21MARC8;
55
56 open (MARC21UTF8,"<:utf8",WHEREAMI."/marc21_utf8.dat") or die $!;
57 my $marc21_utf8;
58 foreach my $line (<MARC21UTF8>) {
59         $marc21_utf8 .= $line;
60 }
61 $marc21_utf8 =~ s/\n$//;
62 close MARC21UTF8;
63
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;
68 }
69 $marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here?
70 close MARC21MARC8COMBCHARS;
71
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;
76 }
77 close MARC21UTF8COMBCHARS;
78
79 open (MARCXMLUTF8,"<:utf8",WHEREAMI."/marcxml_utf8.xml") or die $!;
80 my $marcxml_utf8;
81 foreach my $line (<MARCXMLUTF8>) {
82         $marcxml_utf8 .= $line;
83 }
84 close MARCXMLUTF8;
85
86 $marcxml_utf8 =~ s/\n//g;
87
88 ## The Tests:
89 my $error; my $marc; my $marcxml; my $dcxml; # 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');
98
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');
105
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');
109
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');
112
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');
115
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');
119
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');
123
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');
126
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');
129
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');
132
133 __END__
134
135 =head1 TODO
136
137 Still lots more to test including UNIMARC support
138
139 =head1 AUTHOR
140
141 Joshua Ferraro <jmf@liblime.com>
142
143 =head1 MODIFICATIONS
144
145
146 =cut