|
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 tests => 1; |
| 21 |
use Test::MockModule; |
| 22 |
use Test::Mojo; |
| 23 |
use Test::Warn; |
| 24 |
|
| 25 |
use t::lib::TestBuilder; |
| 26 |
use t::lib::Mocks; |
| 27 |
|
| 28 |
use C4::Auth; |
| 29 |
use C4::Biblio; |
| 30 |
use C4::Items; |
| 31 |
use C4::Circulation; |
| 32 |
use C4::Members; |
| 33 |
use Koha::Patrons; |
| 34 |
use Koha::Illrequests; |
| 35 |
|
| 36 |
my $schema = Koha::Database->new->schema; |
| 37 |
my $builder = t::lib::TestBuilder->new; |
| 38 |
|
| 39 |
my $remote_address = '127.0.0.1'; |
| 40 |
my $t = Test::Mojo->new('Koha::REST::V1'); |
| 41 |
|
| 42 |
subtest 'list() tests' => sub { |
| 43 |
plan tests => 3; |
| 44 |
|
| 45 |
$schema->storage->txn_begin; |
| 46 |
|
| 47 |
my $itemtype = $builder->build({ source => 'Itemtype' })->{ itemtype }; |
| 48 |
my $category = $builder->build({ source => 'Category' })->{ categorycode }; |
| 49 |
my $branch_1 = $builder->build({ source => 'Branch' }); |
| 50 |
my $branch_2 = $builder->build({ source => 'Branch' }); |
| 51 |
|
| 52 |
my $c4_context = Test::MockModule->new('C4::Context'); |
| 53 |
$c4_context->mock('userenv', sub { |
| 54 |
{ branch => $branch_1->{ branchcode } } |
| 55 |
}); |
| 56 |
t::lib::Mocks::mock_preference('item-level_itypes', '0'); |
| 57 |
|
| 58 |
my $biblionumber1 = create_biblio('Test 1', $itemtype); |
| 59 |
AddItem({ |
| 60 |
barcode => 'GTI_BARCODE_001', |
| 61 |
homebranch => $branch_1->{ branchcode }, |
| 62 |
ccode => 'GTI_CCODE', |
| 63 |
}, $biblionumber1); |
| 64 |
|
| 65 |
my $biblionumber2 = create_biblio('Test 2', $itemtype); |
| 66 |
AddItem({ |
| 67 |
barcode => 'GTI_BARCODE_002', |
| 68 |
homebranch => $branch_2->{ branchcode }, |
| 69 |
}, $biblionumber2); |
| 70 |
|
| 71 |
my $borrowernumber = AddMember( |
| 72 |
userid => 'gti.test', |
| 73 |
categorycode => $category, |
| 74 |
branchcode => $branch_1->{ branchcode } |
| 75 |
); |
| 76 |
my $borrower = Koha::Patrons->find( $borrowernumber )->unblessed; |
| 77 |
|
| 78 |
AddIssue($borrower, 'GTI_BARCODE_001'); |
| 79 |
AddIssue($borrower, 'GTI_BARCODE_002'); |
| 80 |
|
| 81 |
my $expected = [ |
| 82 |
{ |
| 83 |
itemtype => $itemtype, |
| 84 |
title => 'Test 1', |
| 85 |
copyrightdate => undef, |
| 86 |
publishercode => undef, |
| 87 |
biblionumber => $biblionumber1, |
| 88 |
count => 1, |
| 89 |
place => undef, |
| 90 |
author => undef, |
| 91 |
publicationyear => undef, |
| 92 |
pages => undef, |
| 93 |
ccode => 'GTI_CCODE', |
| 94 |
size => undef, |
| 95 |
}, |
| 96 |
{ |
| 97 |
itemtype => $itemtype, |
| 98 |
title => 'Test 2', |
| 99 |
copyrightdate => undef, |
| 100 |
publishercode => undef, |
| 101 |
biblionumber => $biblionumber2, |
| 102 |
count => 1, |
| 103 |
place => undef, |
| 104 |
author => undef, |
| 105 |
publicationyear => undef, |
| 106 |
pages => undef, |
| 107 |
ccode => undef, |
| 108 |
size => undef, |
| 109 |
}, |
| 110 |
]; |
| 111 |
$t->get_ok("/api/v1/topissues?itemtype=$itemtype") |
| 112 |
->status_is(200) |
| 113 |
->json_is($expected); |
| 114 |
|
| 115 |
$schema->storage->txn_rollback; |
| 116 |
}; |
| 117 |
|
| 118 |
sub create_biblio { |
| 119 |
my ($title, $itemtype) = @_; |
| 120 |
|
| 121 |
my ($title_tag, $title_subfield) = GetMarcFromKohaField('biblio.title', ''); |
| 122 |
my ($it_tag, $it_subfield) = GetMarcFromKohaField('biblioitems.itemtype', ''); |
| 123 |
|
| 124 |
my $record = MARC::Record->new(); |
| 125 |
$record->append_fields( |
| 126 |
MARC::Field->new($title_tag, ' ', ' ', $title_subfield => $title), |
| 127 |
MARC::Field->new($it_tag, ' ', ' ', $it_subfield => $itemtype), |
| 128 |
); |
| 129 |
|
| 130 |
my ($biblionumber) = AddBiblio($record, ''); |
| 131 |
|
| 132 |
return $biblionumber; |
| 133 |
} |
| 134 |
|
| 135 |
1; |