Lines 18-28
Link Here
|
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
use Test::More tests => 24; |
21 |
use Test::More tests => 28; |
22 |
use Test::Exception; |
22 |
use Test::Exception; |
23 |
use File::Temp qw/tempfile/; |
23 |
use File::Temp qw/tempfile/; |
24 |
|
24 |
|
25 |
use t::lib::TestBuilder; |
25 |
use t::lib::TestBuilder; |
|
|
26 |
use t::lib::Mocks; |
27 |
|
26 |
use HTTP::OAI; |
28 |
use HTTP::OAI; |
27 |
use HTTP::OAI::Metadata::OAI_DC; |
29 |
use HTTP::OAI::Metadata::OAI_DC; |
28 |
use HTTP::OAI::Record; |
30 |
use HTTP::OAI::Record; |
Lines 39-46
$schema->storage->txn_begin;
Link Here
|
39 |
|
41 |
|
40 |
my $new_oai_biblio = Koha::OAIServer->new( |
42 |
my $new_oai_biblio = Koha::OAIServer->new( |
41 |
{ |
43 |
{ |
42 |
endpoint => 'my_host1.org', |
44 |
endpoint => C4::Context->preference('OPACBaseURL') . '/cgi-bin/koha/oai.pl', |
43 |
oai_set => 'set1', |
45 |
oai_set => '', |
44 |
servername => 'my_test_1', |
46 |
servername => 'my_test_1', |
45 |
dataformat => 'oai_dc', |
47 |
dataformat => 'oai_dc', |
46 |
recordtype => 'biblio', |
48 |
recordtype => 'biblio', |
Lines 48-55
my $new_oai_biblio = Koha::OAIServer->new(
Link Here
|
48 |
} |
50 |
} |
49 |
)->store; |
51 |
)->store; |
50 |
|
52 |
|
|
|
53 |
C4::Context->set_preference( 'OAI-PMH', 1 ); |
54 |
t::lib::Mocks::mock_preference( |
55 |
'OAI-PMH:HarvestEmailReport', |
56 |
C4::Context->preference('KohaAdminEmailAddress') |
57 |
); |
58 |
|
51 |
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 1 } ); |
59 |
my $harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 1 } ); |
52 |
|
60 |
|
|
|
61 |
my $init_results = $harvester->init(); |
62 |
|
63 |
like( |
64 |
$init_results->{metadata_formats}, |
65 |
qr/oai_dc marc21 marcxml/, |
66 |
'Got list of supported metadata formats' |
67 |
); |
68 |
is( $init_results->{is_error}, undef, 'ListRecords request worked' ); |
69 |
cmp_ok( $init_results->{total}, '>', 0, 'Records have been processed' ); |
70 |
isnt( $init_results->{letter_message_id}, undef, 'Report has been enqueued' ); |
71 |
|
53 |
my $record = |
72 |
my $record = |
54 |
'<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><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"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>'; |
73 |
'<metadata xmlns="http://www.openarchives.org/OAI/2.0/"><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"><dc:title>Pièces diverses </dc:title><dc:identifier>ARCH/0320 [cote]</dc:identifier><dc:relation>FR-920509801 [RCR établissement]</dc:relation><dc:relation>Central obrera boliviana [Fonds ou collection]</dc:relation><dc:format>1 carton</dc:format><dc:date>1971/2000</dc:date><dc:type>Archives et manuscrits</dc:type></oai_dc:dc></metadata>'; |
55 |
|
74 |
|
Lines 80-86
is( $status, 'updated', 'When force is used, record is updated' );
Link Here
|
80 |
|
99 |
|
81 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 0 } ); |
100 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_biblio, verbose => 1, days => 1, force => 0 } ); |
82 |
$status = $harvester->processRecord($r); |
101 |
$status = $harvester->processRecord($r); |
83 |
is( $status, 'skipped', 'When force is not used, record is skipped (already up to date)' ); |
102 |
is( |
|
|
103 |
$status, 'skipped', |
104 |
'When force is not used, record is skipped (already up to date)' |
105 |
); |
84 |
|
106 |
|
85 |
$r->header->datestamp('2018-05-10T09:18:13Z'); |
107 |
$r->header->datestamp('2018-05-10T09:18:13Z'); |
86 |
$status = $harvester->processRecord($r); |
108 |
$status = $harvester->processRecord($r); |
Lines 105-111
isnt(
Link Here
|
105 |
|
127 |
|
106 |
$r->header->status('deleted'); |
128 |
$r->header->status('deleted'); |
107 |
$status = $harvester->processRecord($r); |
129 |
$status = $harvester->processRecord($r); |
108 |
is( $status, 'deleted', 'When a record is marked to be deleted, status is deleted' ); |
130 |
is( |
|
|
131 |
$status, 'deleted', |
132 |
'When a record is marked to be deleted, status is deleted' |
133 |
); |
109 |
|
134 |
|
110 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
135 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-234' } ); |
111 |
is( $imported_record, undef, 'Record has been deleted' ); |
136 |
is( $imported_record, undef, 'Record has been deleted' ); |
Lines 145-151
$status = $harvester->processRecord($r);
Link Here
|
145 |
is( $status, 'updated', 'Authority with no date is updated' ); |
170 |
is( $status, 'updated', 'Authority with no date is updated' ); |
146 |
|
171 |
|
147 |
$status = $harvester->processRecord($r); |
172 |
$status = $harvester->processRecord($r); |
148 |
is( $status, 'updated', 'Authority with no date is updated even without force' ); |
173 |
is( |
|
|
174 |
$status, 'updated', |
175 |
'Authority with no date is updated even without force' |
176 |
); |
149 |
|
177 |
|
150 |
$r->header->identifier('oai:myarchive.org:oid-162'); |
178 |
$r->header->identifier('oai:myarchive.org:oid-162'); |
151 |
$r->header->datestamp('2017-05-10T09:18:13Z'); |
179 |
$r->header->datestamp('2017-05-10T09:18:13Z'); |
Lines 158-168
is( $status, 'updated', 'When force is used, authority is updated' );
Link Here
|
158 |
|
186 |
|
159 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 0 } ); |
187 |
$harvester = Koha::OAI::Client::Harvester->new( { server => $new_oai_auth, verbose => 1, days => 1, force => 0 } ); |
160 |
$status = $harvester->processRecord($r); |
188 |
$status = $harvester->processRecord($r); |
161 |
is( $status, 'skipped', 'When force is not used, authority is skipped (already up to date)' ); |
189 |
is( |
|
|
190 |
$status, 'skipped', |
191 |
'When force is not used, authority is skipped (already up to date)' |
192 |
); |
162 |
|
193 |
|
163 |
$r->header->datestamp('2018-05-10T09:18:13Z'); |
194 |
$r->header->datestamp('2018-05-10T09:18:13Z'); |
164 |
$status = $harvester->processRecord($r); |
195 |
$status = $harvester->processRecord($r); |
165 |
is( $status, 'updated', 'When force is not used, authority is updated if newer' ); |
196 |
is( |
|
|
197 |
$status, 'updated', |
198 |
'When force is not used, authority is updated if newer' |
199 |
); |
166 |
|
200 |
|
167 |
my $imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
201 |
my $imported_authority = Koha::Import::OAI::Authorities->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
168 |
$imported_authority->update( |
202 |
$imported_authority->update( |
Lines 183-189
isnt(
Link Here
|
183 |
|
217 |
|
184 |
$r->header->status('deleted'); |
218 |
$r->header->status('deleted'); |
185 |
$status = $harvester->processRecord($r); |
219 |
$status = $harvester->processRecord($r); |
186 |
is( $status, 'deleted', 'When an authority is marked to be deleted, status is deleted' ); |
220 |
is( |
|
|
221 |
$status, 'deleted', |
222 |
'When an authority is marked to be deleted, status is deleted' |
223 |
); |
187 |
|
224 |
|
188 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
225 |
$imported_record = Koha::Import::OAI::Biblios->find( { identifier => 'oai:myarchive.org:oid-162' } ); |
189 |
is( $imported_record, undef, 'Authority has been deleted' ); |
226 |
is( $imported_record, undef, 'Authority has been deleted' ); |
190 |
- |
|
|