|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# Copyright 2021 Rijksmuseum |
| 4 |
# |
| 5 |
# This file is part of Koha |
| 6 |
# |
| 7 |
# Koha is free software; you can redistribute it and/or modify it |
| 8 |
# under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 3 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# Koha is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
| 19 |
|
| 20 |
use Modern::Perl; |
| 21 |
use Data::Dumper qw/Dumper/; |
| 22 |
|
| 23 |
use Test::More tests => 1; |
| 24 |
|
| 25 |
use t::lib::TestBuilder; |
| 26 |
use t::lib::Mocks; |
| 27 |
|
| 28 |
use Koha::Database; |
| 29 |
use Koha::ArticleRequests; |
| 30 |
use Koha::DateUtils qw/dt_from_string/; |
| 31 |
use Koha::Holds; |
| 32 |
use Koha::Items; |
| 33 |
use Koha::Patrons; |
| 34 |
use C4::Circulation (); |
| 35 |
use C4::Reserves (); |
| 36 |
|
| 37 |
my $schema = Koha::Database->new->schema; |
| 38 |
my $builder = t::lib::TestBuilder->new; |
| 39 |
|
| 40 |
subtest 'has_current_article_requests' => sub { |
| 41 |
plan tests => 8; |
| 42 |
$schema->storage->txn_begin; |
| 43 |
|
| 44 |
t::lib::Mocks::mock_preference( 'ArticleRequests', 1 ); |
| 45 |
|
| 46 |
my $item1 = $builder->build_sample_item; |
| 47 |
my $patron1 = $builder->build_object({ class => 'Koha::Patrons' }); |
| 48 |
t::lib::Mocks::mock_userenv({ branchcode => $patron1->branchcode }); |
| 49 |
|
| 50 |
my $artreq1 = $builder->build_object({ class => 'Koha::ArticleRequests', |
| 51 |
value => { borrowernumber => $patron1->borrowernumber, itemnumber => $item1->itemnumber, biblionumber => $item1->biblionumber, status => 'PENDING' }, |
| 52 |
}); |
| 53 |
C4::Circulation::AddIssue( $patron1->unblessed, $item1->barcode, dt_from_string() ); |
| 54 |
is( $item1->has_current_article_requests, 1, 'Expect true for item level request' ); |
| 55 |
|
| 56 |
$artreq1->status('COMPLETED')->store; |
| 57 |
is( $item1->has_current_article_requests, undef, 'Expect false for completed item level request' ); |
| 58 |
|
| 59 |
$artreq1->itemnumber(undef); |
| 60 |
$artreq1->status('PROCESSING')->store; |
| 61 |
is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with no other items' ); |
| 62 |
|
| 63 |
my $item2 = $builder->build_sample_item; |
| 64 |
$item2->biblionumber( $item1->biblionumber )->store; |
| 65 |
is( $item1->has_current_article_requests, undef, 'Expect false for biblio level request with another available item' ); |
| 66 |
|
| 67 |
$item2->damaged(1)->store; |
| 68 |
is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with only another damaged item' ); |
| 69 |
$item2->damaged(0)->store; |
| 70 |
is( $item1->has_current_article_requests, undef, 'Expect false again when clearing damaged status' ); |
| 71 |
|
| 72 |
C4::Reserves::AddReserve({ |
| 73 |
branchcode => $patron1->branchcode, borrowernumber => $patron1->borrowernumber, biblionumber => $item2->biblionumber, |
| 74 |
priority => 1, itemnumber => $item2->itemnumber, |
| 75 |
}); |
| 76 |
is( $item1->has_current_article_requests, undef, 'Expect false for biblio level request with only another item and a reserve' ); |
| 77 |
Koha::Holds->search({ itemnumber => $item2->itemnumber })->next->set_waiting; |
| 78 |
is( $item1->has_current_article_requests, 1, 'Expect true for biblio level request with only another item on hold and waiting' ); |
| 79 |
|
| 80 |
$schema->storage->txn_rollback; |
| 81 |
}; |