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