|
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-230
subtest 'post() tests' => sub {
Link Here
|
| 228 |
|
228 |
|
| 229 |
$schema->storage->txn_rollback; |
229 |
$schema->storage->txn_rollback; |
| 230 |
}; |
230 |
}; |
| 231 |
- |
231 |
|
|
|
232 |
subtest 'put() tests' => sub { |
| 233 |
|
| 234 |
plan tests => 14; |
| 235 |
|
| 236 |
$schema->storage->txn_begin; |
| 237 |
|
| 238 |
Koha::Authorities->delete; |
| 239 |
|
| 240 |
my $record; |
| 241 |
my $subfield_a; |
| 242 |
|
| 243 |
my $patron = $builder->build_object( |
| 244 |
{ |
| 245 |
class => 'Koha::Patrons', |
| 246 |
value => { flags => 0 } # no permissions |
| 247 |
} |
| 248 |
); |
| 249 |
my $password = 'thePassword123'; |
| 250 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 251 |
my $userid = $patron->userid; |
| 252 |
|
| 253 |
my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => { |
| 254 |
marcxml => q|<?xml version="1.0" encoding="UTF-8"?> |
| 255 |
<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"> |
| 256 |
<controlfield tag="001">1001</controlfield> |
| 257 |
<datafield tag="110" ind1=" " ind2=" "> |
| 258 |
<subfield code="9">102</subfield> |
| 259 |
<subfield code="a">My Corporation</subfield> |
| 260 |
</datafield> |
| 261 |
</record>| |
| 262 |
} }); |
| 263 |
|
| 264 |
my $authid = $authority->authid; |
| 265 |
my $authtypecode = $authority->authtypecode; |
| 266 |
|
| 267 |
my $marcxml = q|<?xml version="1.0" encoding="UTF-8"?> |
| 268 |
<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"> |
| 269 |
<controlfield tag="001">1001</controlfield> |
| 270 |
<datafield tag="110" ind1=" " ind2=" "> |
| 271 |
<subfield code="9">102</subfield> |
| 272 |
<subfield code="a">MARCXML</subfield> |
| 273 |
</datafield> |
| 274 |
</record>|; |
| 275 |
|
| 276 |
my $mij = '{"fields":[{"001":"1001"},{"110":{"subfields":[{"9":"102"},{"a":"MIJ"}],"ind1":" ","ind2":" "}}],"leader":" "}'; |
| 277 |
my $marc = '00079 2200049 45000010005000001100024000051001 9102aUSMARCFormated'; |
| 278 |
|
| 279 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid") |
| 280 |
->status_is(403, 'Not enough permissions makes it return the right code'); |
| 281 |
|
| 282 |
# Add permissions |
| 283 |
$patron->flags( 2 ** 14 )->store; # 14 => editauthorities userflag |
| 284 |
|
| 285 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marcxml+xml', 'x-authority-type' => $authtypecode} => $marcxml) |
| 286 |
->status_is(200) |
| 287 |
->json_has('/id'); |
| 288 |
|
| 289 |
$authority = Koha::Authorities->find($authid); |
| 290 |
$record = $authority->record; |
| 291 |
$subfield_a = $record->subfield('110', 'a'); |
| 292 |
|
| 293 |
is($subfield_a, 'MARCXML'); |
| 294 |
|
| 295 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marc-in-json', 'x-authority-type' => $authtypecode} => $mij) |
| 296 |
->status_is(200) |
| 297 |
->json_has('/id'); |
| 298 |
|
| 299 |
$authority = Koha::Authorities->find($authid); |
| 300 |
$record = $authority->record; |
| 301 |
$subfield_a = $record->subfield('110', 'a'); |
| 302 |
|
| 303 |
is($subfield_a, 'MIJ'); |
| 304 |
|
| 305 |
$t->put_ok("//$userid:$password@/api/v1/authorities/$authid" => {'Content-Type' => 'application/marc', 'x-authority-type' => $authtypecode} => $marc) |
| 306 |
->status_is(200) |
| 307 |
->json_has('/id'); |
| 308 |
|
| 309 |
$authority = Koha::Authorities->find($authid); |
| 310 |
$record = $authority->record; |
| 311 |
$subfield_a = $record->subfield('110', 'a'); |
| 312 |
|
| 313 |
is($subfield_a, 'USMARCFormated'); |
| 314 |
|
| 315 |
$schema->storage->txn_rollback; |
| 316 |
}; |