|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/env perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 5 |
# Koha is free software; you can redistribute it and/or modify it |
| 6 |
# under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation; either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# Koha is distributed in the hope that it will be useful, but |
| 11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use utf8; |
| 21 |
use Encode; |
| 22 |
|
| 23 |
use Test::More tests => 1; |
| 24 |
use Test::MockModule; |
| 25 |
use Test::Mojo; |
| 26 |
use Test::Warn; |
| 27 |
use JSON; |
| 28 |
|
| 29 |
use t::lib::Mocks; |
| 30 |
use t::lib::TestBuilder; |
| 31 |
|
| 32 |
use C4::Auth; |
| 33 |
|
| 34 |
use Koha::Biblios; |
| 35 |
use Koha::Database; |
| 36 |
|
| 37 |
my $schema = Koha::Database->new->schema; |
| 38 |
my $builder = t::lib::TestBuilder->new; |
| 39 |
|
| 40 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 41 |
|
| 42 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 43 |
|
| 44 |
subtest 'PUT /api/v1/biblios/{biblio_id}/metadata' => sub { |
| 45 |
plan tests => 10; |
| 46 |
|
| 47 |
$schema->storage->txn_begin; |
| 48 |
|
| 49 |
my $patron = $builder->build_object( |
| 50 |
{ |
| 51 |
class => 'Koha::Patrons', |
| 52 |
value => { flags => 0 } |
| 53 |
} |
| 54 |
); |
| 55 |
my $password = 'thePassword123'; |
| 56 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 57 |
$patron->discard_changes; |
| 58 |
my $userid = $patron->userid; |
| 59 |
|
| 60 |
my $biblio = $builder->build_sample_biblio({ |
| 61 |
title => 'The unbearable lightness of being', |
| 62 |
author => 'Milan Kundera', |
| 63 |
}); |
| 64 |
my $biblio_id = $biblio->id; |
| 65 |
|
| 66 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/metadata") |
| 67 |
->status_is(403); |
| 68 |
|
| 69 |
$patron->flags(9)->store; |
| 70 |
|
| 71 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/metadata") |
| 72 |
->status_is(400); |
| 73 |
|
| 74 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/metadata", "not marcxml") |
| 75 |
->status_is(400) |
| 76 |
->json_like('/error', qr/parser error/); |
| 77 |
|
| 78 |
my $biblio2 = $builder->build_sample_biblio({ |
| 79 |
'title' => 'Another title', |
| 80 |
}); |
| 81 |
my $record2 = $biblio2->metadata->record; |
| 82 |
|
| 83 |
$t->put_ok("//$userid:$password@/api/v1/biblios/$biblio_id/metadata", $record2->as_xml_record) |
| 84 |
->status_is(204); |
| 85 |
|
| 86 |
$biblio->discard_changes; |
| 87 |
is($biblio->title, 'Another title'); |
| 88 |
|
| 89 |
$schema->storage->txn_rollback; |
| 90 |
}; |