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 under the |
6 |
# terms of the GNU General Public License as published by the Free Software |
7 |
# Foundation; either version 3 of the License, or (at your option) any later |
8 |
# version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY |
11 |
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
12 |
# A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
13 |
# |
14 |
# You should have received a copy of the GNU General Public License along |
15 |
# with Koha; if not, write to the Free Software Foundation, Inc., |
16 |
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More; |
21 |
use Test::Mojo; |
22 |
use t::lib::TestBuilder; |
23 |
use t::lib::Mocks; |
24 |
|
25 |
use C4::Auth; |
26 |
use C4::Context; |
27 |
|
28 |
use Koha::Database; |
29 |
use Koha::Patron; |
30 |
use Koha::AuthorisedValues; |
31 |
|
32 |
my $builder = t::lib::TestBuilder->new(); |
33 |
|
34 |
my $dbh = C4::Context->dbh; |
35 |
$dbh->{AutoCommit} = 0; |
36 |
$dbh->{RaiseError} = 1; |
37 |
|
38 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
39 |
|
40 |
my $categorycode = Koha::Database->new()->schema()->resultset('Category')->first()->categorycode(); |
41 |
my $branchcode = Koha::Database->new()->schema()->resultset('Branch')->first()->branchcode(); |
42 |
|
43 |
my $borrower = $builder->build({ source => 'Borrower' }); |
44 |
|
45 |
my $session = C4::Auth::get_session(''); |
46 |
$session->param('number', $borrower->{borrowernumber}); |
47 |
$session->param('id', $borrower->{userid}); |
48 |
$session->param('ip', '127.0.0.1'); |
49 |
$session->param('lasttime', time()); |
50 |
$session->flush; |
51 |
|
52 |
my $advanced_search_types = C4::Context->preference("AdvancedSearchTypes"); |
53 |
|
54 |
my %cat = map { $_ => 1 } Koha::AuthorisedValues->categories; |
55 |
foreach (qw/CCODE LOC/) { |
56 |
next unless $cat{$_}; |
57 |
|
58 |
t::lib::Mocks::mock_preference('AdvancedSearchTypes', $_); |
59 |
my $tx = $t->ua->build_tx(GET => '/api/v1/meta/advanced-search-types'); |
60 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
61 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
62 |
$t->request_ok($tx) |
63 |
->status_is(200) |
64 |
->json_is('/ccl' => $_) |
65 |
->json_has('/types/0/code') |
66 |
->json_has('/types/0/description') |
67 |
->json_has('/types/0/imageurl'); |
68 |
} |
69 |
|
70 |
t::lib::Mocks::mock_preference('AdvancedSearchTypes', 'itemtypes'); |
71 |
my $tx = $t->ua->build_tx(GET => '/api/v1/meta/advanced-search-types'); |
72 |
$tx->req->cookies({name => 'CGISESSID', value => $session->id}); |
73 |
$tx->req->env({REMOTE_ADDR => '127.0.0.1'}); |
74 |
$t->request_ok($tx) |
75 |
->status_is(200) |
76 |
->json_like('/ccl' => qr/\w+/) |
77 |
->json_has('/types/0/code') |
78 |
->json_has('/types/0/description') |
79 |
->json_has('/types/0/imageurl'); |
80 |
|
81 |
$dbh->rollback; |
82 |
done_testing(); |