Bug 15244: t/db_dependent/Reserves.t depends on external data/configuration
[koha.git] / t / db_dependent / Record.t
1 #!/usr/bin/perl
2
3 use Modern::Perl;
4
5 use Test::More tests => 12;
6 use MARC::Record;
7
8 use C4::Context;
9
10 BEGIN {
11         use_ok('C4::Record');
12 }
13
14 my $dbh = C4::Context->dbh;
15 # Start transaction
16 $dbh->{AutoCommit} = 0;
17 $dbh->{RaiseError} = 1;
18
19 C4::Context->set_preference( "BibtexExportAdditionalFields", q{} );
20
21 my @marcarray=marc2marc;
22 is ($marcarray[0],"Feature not yet implemented\n","error works");
23
24 my $marc=new MARC::Record;
25 my $marcxml=marc2marcxml($marc);
26 my $testxml=qq(<?xml version="1.0" encoding="UTF-8"?>
27 <record
28     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
29     xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
30     xmlns="http://www.loc.gov/MARC21/slim">
31
32   <leader>         a              </leader>
33 </record>
34 );
35 is ($marcxml, $testxml, "testing marc2xml");
36
37 my $rawmarc=$marc->as_usmarc;
38 $marcxml=marc2marcxml($rawmarc);
39 $testxml=qq(<?xml version="1.0" encoding="UTF-8"?>
40 <record
41     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
42     xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
43     xmlns="http://www.loc.gov/MARC21/slim">
44
45   <leader>00026    a2200025   4500</leader>
46 </record>
47 );
48 is ($marcxml, $testxml, "testing marc2xml");
49
50 my $marcconvert=marcxml2marc($marcxml);
51 is ($marcconvert->as_xml,$marc->as_xml, "testing xml2marc");
52
53 my $marcdc=marc2dcxml($marc);
54 my $test2xml=qq(<?xml version="1.0" encoding="UTF-8"?>
55 <metadata
56   xmlns="http://example.org/myapp/"
57   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
58   xsi:schemaLocation="http://example.org/myapp/ http://example.org/myapp/schema.xsd"
59   xmlns:dc="http://purl.org/dc/elements/1.1/"
60   xmlns:dcterms="http://purl.org/dc/terms/">
61 </metadata>);
62
63 is ($marcdc, $test2xml, "testing marc2dcxml");
64
65 my $marcqualified=marc2dcxml($marc,1);
66 my $test3xml=qq(<?xml version="1.0" encoding="UTF-8"?>
67 <metadata
68   xmlns="http://example.org/myapp/"
69   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
70   xsi:schemaLocation="http://example.org/myapp/ http://example.org/myapp/schema.xsd"
71   xmlns:dc="http://purl.org/dc/elements/1.1/"
72   xmlns:dcterms="http://purl.org/dc/terms/">
73 </metadata>);
74
75 is ($marcqualified, $test3xml, "testing marcQualified");
76
77 my $mods=marc2modsxml($marc);
78 my $test4xml=qq(<?xml version="1.0" encoding="UTF-8"?>
79 <mods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/mods/v3" version="3.1" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-1.xsd">
80   <typeOfResource/>
81   <originInfo>
82     <issuance/>
83   </originInfo>
84   <recordInfo/>
85 </mods>
86 );
87
88 is ($mods, $test4xml, "testing marc2modsxml");
89
90 $marc->append_fields(MARC::Field->new(
91     '100', ' ', ' ', a => 'Rowling, J.K.'
92 ));
93 my $field = MARC::Field->new('245','','','a' => "Harry potter");
94 $marc->append_fields($field);
95 $marc->append_fields(MARC::Field->new(
96     '260', ' ', ' ', b => 'Scholastic', c => '2001'
97 ));
98
99 #my $endnote=marc2endnote($marc->as_usmarc);
100 #print $endnote;
101
102 my $bibtex=marc2bibtex($marc, 'testID');
103 my $test5xml=qq(\@book{testID,
104         author = {Rowling, J.K.},
105         title = {Harry potter},
106         publisher = {Scholastic},
107         year = {2001}
108 }
109 );
110
111 is ($bibtex, $test5xml, "testing bibtex");
112
113 C4::Context->set_preference( "BibtexExportAdditionalFields", "'\@': 260\$b\ntest: 260\$b" );
114 $bibtex = marc2bibtex( $marc, 'testID' );
115 my $test6xml = qq(\@Scholastic{testID,
116 \tauthor = {Rowling, J.K.},
117 \ttitle = {Harry potter},
118 \tpublisher = {Scholastic},
119 \tyear = {2001},
120 \ttest = {Scholastic}
121 }
122 );
123 is( $bibtex, $test6xml, "testing bibtex" );
124 C4::Context->set_preference( "BibtexExportAdditionalFields", q{} );
125
126 $marc->append_fields(MARC::Field->new(
127     '264', '3', '1', b => 'Reprints', c => '2011'
128 ));
129 $bibtex = marc2bibtex($marc, 'testID');
130 my $rdabibtex = qq(\@book{testID,
131         author = {Rowling, J.K.},
132         title = {Harry potter},
133         publisher = {Reprints},
134         year = {2011}
135 }
136 );
137 is ($bibtex, $rdabibtex, "testing bibtex with RDA 264 field");
138
139 my @entity=C4::Record::_entity_encode("Björn");
140 is ($entity[0], "Bj&#xC3;&#xB6;rn", "Html umlauts");
141
142
143
144
145
146
147
148