Bug 15756: Some tests for haspermission in C4::Auth
[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 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 $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>
58 );
59
60 is ($marcsrwdc, $test2xml, "testing SRWDC Metadata");
61
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>
68 );
69
70 is ($marcoaidc, $test3xml, "testing OAIDC Metadata");
71
72 my $marcrdfdc=marc2dcxml( $marc, undef, undef, "rdfdc" );
73 my $test4xml=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>
78 );
79
80 is ($marcrdfdc, $test4xml, "testing OAIDC Metadata");
81
82 my $mods=marc2modsxml($marc);
83 my $test5xml=qq(<?xml version="1.0" encoding="UTF-8"?>
84 <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">
85   <typeOfResource/>
86   <originInfo>
87     <issuance/>
88   </originInfo>
89   <recordInfo/>
90 </mods>
91 );
92
93 is ($mods, $test5xml, "testing marc2modsxml");
94
95 $marc->append_fields(MARC::Field->new(
96     '100', ' ', ' ', a => 'Rowling, J.K.'
97 ));
98 my $field = MARC::Field->new('245','','','a' => "Harry potter");
99 $marc->append_fields($field);
100 $marc->append_fields(MARC::Field->new(
101     '260', ' ', ' ', b => 'Scholastic', c => '2001'
102 ));
103
104 #my $endnote=marc2endnote($marc->as_usmarc);
105 #print $endnote;
106
107 my $bibtex=marc2bibtex($marc, 'testID');
108 my $test6xml=qq(\@book{testID,
109         author = {Rowling, J.K.},
110         title = {Harry potter},
111         publisher = {Scholastic},
112         year = {2001}
113 }
114 );
115
116 is ($bibtex, $test6xml, "testing bibtex");
117
118 C4::Context->set_preference( "BibtexExportAdditionalFields", "'\@': 260\$b\ntest: 260\$b" );
119 $bibtex = marc2bibtex( $marc, 'testID' );
120 my $test7xml = qq(\@Scholastic{testID,
121 \tauthor = {Rowling, J.K.},
122 \ttitle = {Harry potter},
123 \tpublisher = {Scholastic},
124 \tyear = {2001},
125 \ttest = {Scholastic}
126 }
127 );
128 is( $bibtex, $test7xml, "testing bibtex" );
129 C4::Context->set_preference( "BibtexExportAdditionalFields", q{} );
130
131 $marc->append_fields(MARC::Field->new(
132     '264', '3', '1', b => 'Reprints', c => '2011'
133 ));
134 $bibtex = marc2bibtex($marc, 'testID');
135 my $rdabibtex = qq(\@book{testID,
136         author = {Rowling, J.K.},
137         title = {Harry potter},
138         publisher = {Reprints},
139         year = {2011}
140 }
141 );
142 is ($bibtex, $rdabibtex, "testing bibtex with RDA 264 field");
143
144 my @entity=C4::Record::_entity_encode("Björn");
145 is ($entity[0], "Bj&#xC3;&#xB6;rn", "Html umlauts");
146
147
148
149
150
151
152
153