|
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 <https://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 2; |
| 21 |
use Test::NoWarnings; |
| 22 |
use Test::Mojo; |
| 23 |
|
| 24 |
use t::lib::TestBuilder; |
| 25 |
use t::lib::Mocks; |
| 26 |
|
| 27 |
use Koha::OAI::Sets; |
| 28 |
use Koha::OAI::Set::Biblios; |
| 29 |
use Koha::Database; |
| 30 |
|
| 31 |
my $schema = Koha::Database->new->schema; |
| 32 |
my $builder = t::lib::TestBuilder->new; |
| 33 |
|
| 34 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 35 |
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); |
| 36 |
|
| 37 |
subtest 'get() tests' => sub { |
| 38 |
|
| 39 |
plan tests => 8; |
| 40 |
|
| 41 |
$schema->storage->txn_begin; |
| 42 |
|
| 43 |
Koha::OAI::Set::Biblios->search->delete; |
| 44 |
Koha::OAI::Sets->search->delete; |
| 45 |
|
| 46 |
my $librarian = $builder->build_object( |
| 47 |
{ |
| 48 |
class => 'Koha::Patrons', |
| 49 |
value => { flags => 25**2 } # parameters flag = 3 |
| 50 |
} |
| 51 |
); |
| 52 |
my $password = 'thePassword123'; |
| 53 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
| 54 |
my $userid = $librarian->userid; |
| 55 |
|
| 56 |
my $patron = $builder->build_object( |
| 57 |
{ |
| 58 |
class => 'Koha::Patrons', |
| 59 |
value => { flags => 0 } |
| 60 |
} |
| 61 |
); |
| 62 |
|
| 63 |
$patron->set_password( { password => $password, skip_validation => 1 } ); |
| 64 |
my $unauth_userid = $patron->userid; |
| 65 |
|
| 66 |
$t->get_ok("//$userid:$password@/api/v1/")->status_is(200)->json_is( [] ); |
| 67 |
|
| 68 |
my $set = $builder->build_object( |
| 69 |
{ |
| 70 |
class => 'Koha::OAI::Sets', |
| 71 |
value => { spec => 'A' } |
| 72 |
} |
| 73 |
); |
| 74 |
my $set_id = $set->id; |
| 75 |
|
| 76 |
my $set_item_deleted_1 = $builder->build_object( |
| 77 |
{ |
| 78 |
class => 'Koha::OAI::Set::Biblios', |
| 79 |
value => { set_id => $set_id, biblionumber => 123456789 } |
| 80 |
} |
| 81 |
); |
| 82 |
|
| 83 |
my $set_item_deleted_2 = $builder->build_object( |
| 84 |
{ |
| 85 |
class => 'Koha::OAI::Set::Biblios', |
| 86 |
value => { set_id => $set_id, biblionumber => 987654321 } |
| 87 |
} |
| 88 |
); |
| 89 |
|
| 90 |
my $biblio = $builder->build_sample_biblio(); |
| 91 |
|
| 92 |
my $set_item_in_catalog = $builder->build_object( |
| 93 |
{ |
| 94 |
class => 'Koha::OAI::Set::Biblios', |
| 95 |
value => { set_id => $set_id, biblionumber => $biblio->id } |
| 96 |
} |
| 97 |
); |
| 98 |
|
| 99 |
$t->get_ok("//$userid:$password@/api/v1/oai_sets/$set_id")->status_is(200)->json_is( [ $set->to_api ] ); |
| 100 |
|
| 101 |
# Unauthorized access |
| 102 |
$t->get_ok("//$unauth_userid:$password@/api/v1/oai_sets/$set_id")->status_is(403); |
| 103 |
|
| 104 |
$schema->storage->txn_rollback; |
| 105 |
}; |