Lines 20-26
use Modern::Perl;
Link Here
|
20 |
use utf8; |
20 |
use utf8; |
21 |
use Encode; |
21 |
use Encode; |
22 |
|
22 |
|
23 |
use Test::More tests => 3; |
23 |
use Test::More tests => 4; |
24 |
use Test::MockModule; |
24 |
use Test::MockModule; |
25 |
use Test::Mojo; |
25 |
use Test::Mojo; |
26 |
use Test::Warn; |
26 |
use Test::Warn; |
Lines 228-232
subtest 'post() tests' => sub {
Link Here
|
228 |
->status_is(200) |
228 |
->status_is(200) |
229 |
->json_has('/id'); |
229 |
->json_has('/id'); |
230 |
|
230 |
|
|
|
231 |
$schema->storage->txn_rollback; |
232 |
}; |
233 |
|
234 |
subtest 'put() tests' => sub { |
235 |
|
236 |
plan tests => 18; |
237 |
|
238 |
$schema->storage->txn_begin; |
239 |
|
240 |
Koha::Authorities->delete; |
241 |
|
242 |
my $record; |
243 |
my $subfield_a; |
244 |
|
245 |
my $patron = $builder->build_object( |
246 |
{ |
247 |
class => 'Koha::Patrons', |
248 |
value => { flags => 0 } # no permissions |
249 |
} |
250 |
); |
251 |
my $password = 'thePassword123'; |
252 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
253 |
my $userid = $patron->userid; |
254 |
|
255 |
my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => { |
256 |
marcxml => q|<?xml version="1.0" encoding="UTF-8"?> |
257 |
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
258 |
<controlfield tag="001">1001</controlfield> |
259 |
<datafield tag="110" ind1=" " ind2=" "> |
260 |
<subfield code="9">102</subfield> |
261 |
<subfield code="a">My Corporation</subfield> |
262 |
</datafield> |
263 |
</record>| |
264 |
} }); |
265 |
|
266 |
my $authid = $authority->authid; |
267 |
my $authtypecode = $authority->authtypecode; |
268 |
|
269 |
my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?> |
270 |
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
271 |
<controlfield tag="001">1001</controlfield> |
272 |
<datafield tag="110" ind1=" " ind2=" "> |
273 |
<subfield code="9">102</subfield> |
274 |
<subfield code="a">MARCXML</subfield> |
275 |
</datafield> |
276 |
</record>|; |
277 |
|
278 |
my $mij = '{"fields":[{"001":"1001"},{"110":{"subfields":[{"9":"102"},{"a":"MIJ"}],"ind1":" ","ind2":" "}}],"leader":" "}'; |
279 |
my $marc = '00079 2200049 45000010005000001100024000051001 9102aUSMARCFormated'; |
280 |
my $json = { |
281 |
authtypecode => $authtypecode, |
282 |
marcxml => q|<?xml version="1.0" encoding="UTF-8"?> |
283 |
<record xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.loc.gov/MARC21/slim" xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"> |
284 |
<controlfield tag="001">1001</controlfield> |
285 |
<datafield tag="110" ind1=" " ind2=" "> |
286 |
<subfield code="9">102</subfield> |
287 |
<subfield code="a">JSON</subfield> |
288 |
</datafield> |
289 |
</record>| |
290 |
}; |
291 |
|
292 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid") |
293 |
->status_is(403, 'Not enough permissions makes it return the right code'); |
294 |
|
295 |
# Add permissions |
296 |
$builder->build( |
297 |
{ |
298 |
source => 'UserPermission', |
299 |
value => { |
300 |
borrowernumber => $patron->borrowernumber, |
301 |
module_bit => 9, |
302 |
code => 'edit_catalogue' |
303 |
} |
304 |
} |
305 |
); |
306 |
|
307 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => json => $json) |
308 |
->status_is(200) |
309 |
->json_has('/id'); |
310 |
|
311 |
$authority = Koha::Authorities->find($authid); |
312 |
$record = $authority->record; |
313 |
$subfield_a = $record->subfield('110', 'a'); |
314 |
|
315 |
is($subfield_a, 'JSON'); |
316 |
|
317 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marcxml+xml', 'x-authority-type' => $authtypecode} => $marcxml) |
318 |
->status_is(200) |
319 |
->json_has('/id'); |
320 |
|
321 |
$authority = Koha::Authorities->find($authid); |
322 |
$record = $authority->record; |
323 |
$subfield_a = $record->subfield('110', 'a'); |
324 |
|
325 |
is($subfield_a, 'MARCXML'); |
326 |
|
327 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marc-in-json', 'x-authority-type' => $authtypecode} => $mij) |
328 |
->status_is(200) |
329 |
->json_has('/id'); |
330 |
|
331 |
$authority = Koha::Authorities->find($authid); |
332 |
$record = $authority->record; |
333 |
$subfield_a = $record->subfield('110', 'a'); |
334 |
|
335 |
is($subfield_a, 'MIJ'); |
336 |
|
337 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marc', 'x-authority-type' => $authtypecode} => $marc) |
338 |
->status_is(200) |
339 |
->json_has('/id'); |
340 |
|
341 |
$authority = Koha::Authorities->find($authid); |
342 |
$record = $authority->record; |
343 |
$subfield_a = $record->subfield('110', 'a'); |
344 |
|
345 |
is($subfield_a, 'USMARCFormated'); |
346 |
|
231 |
$schema->storage->txn_rollback; |
347 |
$schema->storage->txn_rollback; |
232 |
}; |
348 |
}; |
233 |
- |
|
|