Lines 1-141
Link Here
|
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 |
18 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
19 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
20 |
# |
21 |
# |
22 |
use strict; |
23 |
use warnings; |
24 |
|
25 |
# specify the number of tests |
26 |
use Test::More tests => 23; |
27 |
#use C4::Context; |
28 |
use C4::Record; |
29 |
|
30 |
=head1 NAME |
31 |
|
32 |
Record_test.pl - test suite for Record.pm |
33 |
|
34 |
=head1 SYNOPSIS |
35 |
|
36 |
$ export KOHA_CONF=/path/to/koha.conf |
37 |
$ ./Record_test.pl |
38 |
|
39 |
=cut |
40 |
|
41 |
## FIXME: Preliminarily grab the modules dir so we can run this in context |
42 |
|
43 |
ok (1, 'module compiled'); |
44 |
|
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; |
50 |
} |
51 |
$marc21_marc8 =~ s/\n$//; |
52 |
close MARC21MARC8; |
53 |
|
54 |
open (MARC21UTF8,"<:utf8","testrecords/marc21_utf8.dat") or die $!; |
55 |
my $marc21_utf8; |
56 |
foreach my $line (<MARC21UTF8>) { |
57 |
$marc21_utf8 .= $line; |
58 |
} |
59 |
$marc21_utf8 =~ s/\n$//; |
60 |
close MARC21UTF8; |
61 |
|
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; |
66 |
} |
67 |
$marc21_marc8_combining_chars =~ s/\n$//; #FIXME: why is a newline ending up here? |
68 |
close MARC21MARC8COMBCHARS; |
69 |
|
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; |
74 |
} |
75 |
close MARC21UTF8COMBCHARS; |
76 |
|
77 |
open (MARCXMLUTF8,"<:utf8","testrecords/marcxml_utf8.xml") or die $!; |
78 |
my $marcxml_utf8; |
79 |
foreach my $line (<MARCXMLUTF8>) { |
80 |
$marcxml_utf8 .= $line; |
81 |
} |
82 |
close MARCXMLUTF8; |
83 |
|
84 |
$marcxml_utf8 =~ s/\n//g; |
85 |
|
86 |
## The Tests: |
87 |
my $error; my $marc; my $marcxml; my $dcxml; # some scalars to store values |
88 |
## MARC to MARCXML |
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'); |
92 |
$marcxml =~ s/\n//g; |
93 |
$marcxml =~ s/v\/ s/v\/s/g; # FIXME: bug in new_from_xml_record!! |
94 |
is ($marcxml,$marcxml_utf8, 'record matches antitype'); |
95 |
|
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'); |
98 |
$marcxml =~ s/\n//g; |
99 |
$marcxml =~ s/v\/ s/v\/s/g; |
100 |
is ($marcxml,$marcxml_utf8, 'record matches antitype'); |
101 |
|
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'); |
105 |
|
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'); |
108 |
|
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'); |
111 |
|
112 |
ok (($error,$dcxml) = marc2dcxml($marc21_utf8), 'marc2dcxml - from ISO-2709 to Dublin Core'); |
113 |
ok (!$error, 'no errors in conversion'); |
114 |
|
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'); |
118 |
|
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'); |
121 |
|
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'); |
124 |
|
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'); |
127 |
|
128 |
__END__ |
129 |
|
130 |
=head1 TODO |
131 |
|
132 |
Still lots more to test including UNIMARC support |
133 |
|
134 |
=head1 AUTHOR |
135 |
|
136 |
Joshua Ferraro <jmf@liblime.com> |
137 |
|
138 |
=head1 MODIFICATIONS |
139 |
|
140 |
|
141 |
=cut |