3 # Copyright Tamil s.a.r.l. 2015
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
24 use Test::More tests => 13;
33 use_ok('Koha::OAI::Server::DeletedRecord');
34 use_ok('Koha::OAI::Server::Description');
35 use_ok('Koha::OAI::Server::GetRecord');
36 use_ok('Koha::OAI::Server::Identify');
37 use_ok('Koha::OAI::Server::ListIdentifiers');
38 use_ok('Koha::OAI::Server::ListMetadataFormats');
39 use_ok('Koha::OAI::Server::ListRecords');
40 use_ok('Koha::OAI::Server::ListSets');
41 use_ok('Koha::OAI::Server::Record');
42 use_ok('Koha::OAI::Server::Repository');
43 use_ok('Koha::OAI::Server::ResumptionToken');
47 # Mocked CGI module in order to be able to send CGI parameters to OAI Server
49 my $module = Test::MockModule->new('CGI');
50 $module->mock('Vars', sub { %param; });
52 my $dbh = C4::Context->dbh;
53 $dbh->{AutoCommit} = 0;
54 $dbh->{RaiseError} = 1;
55 $dbh->do('DELETE FROM issues');
56 $dbh->do('DELETE FROM biblio');
57 $dbh->do('DELETE FROM biblioitems');
58 $dbh->do('DELETE FROM items');
60 # Add 10 biblio records
62 my $record = MARC::Record->new();
63 $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
64 my ($biblionumber) = AddBiblio($record, '');
68 t::lib::Mocks::mock_preference('LibraryName', 'My Library');
69 t::lib::Mocks::mock_preference('OAI::PMH', 1);
70 t::lib::Mocks::mock_preference('OAI-PMH:archiveID', 'TEST');
71 t::lib::Mocks::mock_preference('OAI-PMH:ConfFile', '' );
72 t::lib::Mocks::mock_preference('OAI-PMH:MaxCount', 3);
73 t::lib::Mocks::mock_preference('OAI-PMH:DeletedRecord', 'persistent');
75 %param = ( verb => 'ListMetadataFormats' );
77 my $get_response = sub {
80 open STDOUT, '>', \$stdout;
81 Koha::OAI::Server::Repository->new();
82 $response = XMLin($stdout);
85 my $now = DateTime->now . 'Z';
87 request => 'http://localhost',
89 xmlns => 'http://www.openarchives.org/OAI/2.0/',
90 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
91 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
92 ListMetadataFormats => {
95 metadataNamespace => 'http://www.openarchives.org/OAI/2.0/oai_dc/',
96 metadataPrefix=> 'oai_dc',
97 schema => 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
100 metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim',
101 metadataPrefix => 'marcxml',
102 schema => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd',
107 is_deeply($response, $expected, "ListMetadataFormats");
109 %param = ( verb => 'ListIdentifiers' );
111 $now = DateTime->now . 'Z';
113 request => 'http://localhost',
114 responseDate => $now,
115 xmlns => 'http://www.openarchives.org/OAI/2.0/',
116 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
117 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
119 code => 'badArgument',
120 content => "Required argument 'metadataPrefix' was undefined",
123 is_deeply($response, $expected, "ListIdentifiers without metadaPrefix argument");