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;
28 use Capture::Tiny ':all';
34 use_ok('Koha::OAI::Server::DeletedRecord');
35 use_ok('Koha::OAI::Server::Description');
36 use_ok('Koha::OAI::Server::GetRecord');
37 use_ok('Koha::OAI::Server::Identify');
38 use_ok('Koha::OAI::Server::ListIdentifiers');
39 use_ok('Koha::OAI::Server::ListMetadataFormats');
40 use_ok('Koha::OAI::Server::ListRecords');
41 use_ok('Koha::OAI::Server::ListSets');
42 use_ok('Koha::OAI::Server::Record');
43 use_ok('Koha::OAI::Server::Repository');
44 use_ok('Koha::OAI::Server::ResumptionToken');
48 # Mocked CGI module in order to be able to send CGI parameters to OAI Server
50 my $module = Test::MockModule->new('CGI');
51 $module->mock('Vars', sub { %param; });
53 my $dbh = C4::Context->dbh;
54 $dbh->{AutoCommit} = 0;
55 $dbh->{RaiseError} = 1;
56 $dbh->do('DELETE FROM issues');
57 $dbh->do('DELETE FROM biblio');
58 $dbh->do('DELETE FROM biblioitems');
59 $dbh->do('DELETE FROM items');
61 # Add 10 biblio records
63 my $record = MARC::Record->new();
64 $record->append_fields( MARC::Field->new('245', '', '', 'a' => "Title $_" ) );
65 my ($biblionumber) = AddBiblio($record, '');
69 t::lib::Mocks::mock_preference('LibraryName', 'My Library');
70 t::lib::Mocks::mock_preference('OAI::PMH', 1);
71 t::lib::Mocks::mock_preference('OAI-PMH:archiveID', 'TEST');
72 t::lib::Mocks::mock_preference('OAI-PMH:ConfFile', '' );
73 t::lib::Mocks::mock_preference('OAI-PMH:MaxCount', 3);
74 t::lib::Mocks::mock_preference('OAI-PMH:DeletedRecord', 'persistent');
76 %param = ( verb => 'ListMetadataFormats' );
77 my ($response) = capture { Koha::OAI::Server::Repository->new(); };
78 $response = XMLin($response);
79 my $now = DateTime->now . 'Z';
81 request => 'http://localhost',
83 xmlns => 'http://www.openarchives.org/OAI/2.0/',
84 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
85 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
86 ListMetadataFormats => {
89 metadataNamespace => 'http://www.openarchives.org/OAI/2.0/oai_dc/',
90 metadataPrefix=> 'oai_dc',
91 schema => 'http://www.openarchives.org/OAI/2.0/oai_dc.xsd',
94 metadataNamespace => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim',
95 metadataPrefix => 'marcxml',
96 schema => 'http://www.loc.gov/MARC21/slim http://www.loc.gov/ standards/marcxml/schema/MARC21slim.xsd',
101 is_deeply($response, $expected, "ListMetadataFormats");
103 %param = ( verb => 'ListIdentifiers' );
104 ($response) = capture { Koha::OAI::Server::Repository->new(); };
105 $response = XMLin($response);
106 $now = DateTime->now . 'Z';
108 request => 'http://localhost',
109 responseDate => $now,
110 xmlns => 'http://www.openarchives.org/OAI/2.0/',
111 'xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance',
112 'xsi:schemaLocation' => 'http://www.openarchives.org/OAI/2.0/ http://www.openarchives.org/OAI/2.0/OAI-PMH.xsd',
114 code => 'badArgument',
115 content => "Required argument 'metadataPrefix' was undefined",
118 is_deeply($response, $expected, "ListIdentifiers without metadaPrefix argument");