Bug 19382: (follow-up) Alternate tests
[koha.git] / t / db_dependent / Record.t
blob613e5ea7ea63448625b05d0eb8e926b9e95d1c23
1 #!/usr/bin/perl
3 use Modern::Perl;
5 use Test::More tests => 14;
6 use MARC::Record;
8 use t::lib::Mocks;
9 use C4::Context;
10 use Koha::Database;
12 BEGIN {
13 use_ok('C4::Record');
16 my $schema = Koha::Database->new->schema;
17 $schema->storage->txn_begin;
19 t::lib::Mocks::mock_preference( "BibtexExportAdditionalFields", q{} );
21 my @marcarray=marc2marc;
22 is ($marcarray[0],"Feature not yet implemented\n","error works");
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">
32 <leader> a </leader>
33 </record>
35 is ($marcxml, $testxml, "testing marc2xml");
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">
45 <leader>00026 a2200025 4500</leader>
46 </record>
48 is ($marcxml, $testxml, "testing marc2xml");
50 my $marcconvert=marcxml2marc($marcxml);
51 is ($marcconvert->as_xml,$marc->as_xml, "testing xml2marc");
53 my $marcsrwdc=marc2dcxml( $marc, undef, undef, "srwdc" );
54 my $test2xml=qq(<?xml version="1.0" encoding="UTF-8"?>
55 <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">
56 <type xmlns="http://purl.org/dc/elements/1.1/"/>
57 </srw_dc:dc>
60 is ($marcsrwdc, $test2xml, "testing SRWDC Metadata");
62 my $marcoaidc=marc2dcxml( $marc, undef, undef, "oaidc" );
63 my $test3xml=qq(<?xml version="1.0" encoding="UTF-8"?>
64 <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">
65 <dc:type/>
66 <dc:language/>
67 </oai_dc:dc>
70 is ($marcoaidc, $test3xml, "testing OAIDC Metadata");
72 my $marcrdfdc=marc2dcxml( $marc, undef, undef, "rdfdc" );
73 my $test4Axml=qq(<?xml version="1.0" encoding="UTF-8"?>
74 <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
75 <dc:type/>
76 <dc:language/>
77 </rdf:Description>
80 is ($marcrdfdc, $test4Axml, "testing RDFDC Metadata");
82 my $marcdc=marc2dcxml( $marc, undef, undef, "dc" );
83 my $test4Bxml=qq(<?xml version="1.0" encoding="UTF-8"?>
84 <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/">
85 <dc:type/>
86 <dc:language/>
87 </rdf:Description>
90 is ($marcrdfdc, $test4Bxml, "testing DC Metadata");
92 my $mods=marc2modsxml($marc);
93 my $test5xml=qq(<?xml version="1.0" encoding="UTF-8"?>
94 <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">
95 <typeOfResource/>
96 <originInfo>
97 <issuance/>
98 </originInfo>
99 <recordInfo/>
100 </mods>
103 is ($mods, $test5xml, "testing marc2modsxml");
105 $marc->append_fields(MARC::Field->new(
106 '100', ' ', ' ', a => 'Rowling, J.K.'
108 my $field = MARC::Field->new('245','','','a' => "Harry potter");
109 $marc->append_fields($field);
110 $marc->append_fields(MARC::Field->new(
111 '260', ' ', ' ', b => 'Scholastic', c => '2001'
114 #my $endnote=marc2endnote($marc->as_usmarc);
115 #print $endnote;
117 my $bibtex=marc2bibtex($marc, 'testID');
118 my $test6xml=qq(\@book{testID,
119 author = {Rowling, J.K.},
120 title = {Harry potter},
121 publisher = {Scholastic},
122 year = {2001}
126 is ($bibtex, $test6xml, "testing bibtex");
128 t::lib::Mocks::mock_preference( "BibtexExportAdditionalFields", "'\@': 260\$b\ntest: 260\$b" );
129 $bibtex = marc2bibtex( $marc, 'testID' );
130 my $test7xml = qq(\@Scholastic{testID,
131 \tauthor = {Rowling, J.K.},
132 \ttitle = {Harry potter},
133 \tpublisher = {Scholastic},
134 \tyear = {2001},
135 \ttest = {Scholastic}
138 is( $bibtex, $test7xml, "testing bibtex" );
139 t::lib::Mocks::mock_preference( "BibtexExportAdditionalFields", q{} );
141 $marc->append_fields(MARC::Field->new(
142 '264', '3', '1', b => 'Reprints', c => '2011'
144 $bibtex = marc2bibtex($marc, 'testID');
145 my $rdabibtex = qq(\@book{testID,
146 author = {Rowling, J.K.},
147 title = {Harry potter},
148 publisher = {Reprints},
149 year = {2011}
152 is ($bibtex, $rdabibtex, "testing bibtex with RDA 264 field");
154 my @entity=C4::Record::_entity_encode("Björn");
155 is ($entity[0], "Bj&#xC3;&#xB6;rn", "Html umlauts");