3 # This file is part of Koha.
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.
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.
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>.
23 use Test::More tests => 1;
29 use t::lib::TestBuilder;
33 use Koha::Authorities;
35 my $schema = Koha::Database->new->schema;
36 my $builder = t::lib::TestBuilder->new;
38 t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
40 my $t = Test::Mojo->new('Koha::REST::V1');
42 subtest 'get() tests' => sub {
46 $schema->storage->txn_begin;
48 my $patron = $builder->build_object(
50 class => 'Koha::Patrons',
51 value => { flags => 0 }
54 my $password = 'thePassword123';
55 $patron->set_password( { password => $password, skip_validation => 1 } );
56 $patron->discard_changes;
57 my $userid = $patron->userid;
59 my $authority = $builder->build_object({ 'class' => 'Koha::Authorities', value => {
60 marcxml => q|<?xml version="1.0" encoding="UTF-8"?>
61 <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">
62 <controlfield tag="001">1001</controlfield>
63 <datafield tag="110" ind1=" " ind2=" ">
64 <subfield code="9">102</subfield>
65 <subfield code="a">My Corporation</subfield>
70 $t->get_ok("//$userid:$password@/api/v1/authorities/" . $authority->authid)
73 $patron->flags(4)->store;
75 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
76 => { Accept => 'application/weird+format' } )
79 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
80 => { Accept => 'application/json' } )
82 ->json_is( '/authid', $authority->authid )
83 ->json_is( '/authtypecode', $authority->authtypecode );
85 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
86 => { Accept => 'application/marcxml+xml' } )
89 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
90 => { Accept => 'application/marc-in-json' } )
93 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
94 => { Accept => 'application/marc' } )
97 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
98 => { Accept => 'text/plain' } )
100 ->content_is(q|LDR 00079 2200049 4500
106 $t->get_ok( "//$userid:$password@/api/v1/authorities/" . $authority->authid
107 => { Accept => 'application/marc' } )
109 ->json_is( '/error', 'Object not found.' );
111 $schema->storage->txn_rollback;