|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/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 <http://www.gnu.org/licenses>. |
| 17 |
|
| 18 |
use Modern::Perl; |
| 19 |
|
| 20 |
use Test::More tests => 2; |
| 21 |
use Test::NoWarnings; |
| 22 |
use Test::MockModule; |
| 23 |
|
| 24 |
use C4::Circulation qw( AddIssue AddReturn transferbook ); |
| 25 |
use C4::SIP::ILS; |
| 26 |
use C4::SIP::ILS::Transaction::Checkin qw( do_checkin ); |
| 27 |
|
| 28 |
use Koha::Checkouts; |
| 29 |
use Koha::Database; |
| 30 |
|
| 31 |
use t::lib::Mocks; |
| 32 |
use t::lib::TestBuilder; |
| 33 |
|
| 34 |
my $schema = Koha::Database->schema; |
| 35 |
my $builder = t::lib::TestBuilder->new; |
| 36 |
|
| 37 |
subtest 'Real-time holds queue tests' => sub { |
| 38 |
|
| 39 |
plan tests => 5; |
| 40 |
|
| 41 |
$schema->storage->txn_begin; |
| 42 |
|
| 43 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 44 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 45 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 46 |
my $item = $builder->build_sample_item( { library => $library->id } ); |
| 47 |
my $item_type = $item->item_type; |
| 48 |
$item_type->automatic_checkin(1)->store(); |
| 49 |
|
| 50 |
t::lib::Mocks::mock_userenv( { branchcode => $library->id } ); |
| 51 |
t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 ); |
| 52 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); |
| 53 |
|
| 54 |
my $action; |
| 55 |
|
| 56 |
my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); |
| 57 |
$mock->mock( |
| 58 |
'enqueue', |
| 59 |
sub { |
| 60 |
my ( $self, $args ) = @_; |
| 61 |
my ( $package, $filename, $line ) = caller; |
| 62 |
is_deeply( |
| 63 |
$args->{biblio_ids}, |
| 64 |
[ $item->biblionumber ], |
| 65 |
"$action triggers a holds queue update for the related biblio from $package at line $line" |
| 66 |
); |
| 67 |
} |
| 68 |
); |
| 69 |
|
| 70 |
# Test 1 |
| 71 |
$action = 'AddIssue'; |
| 72 |
AddIssue( $patron, $item->barcode, ); |
| 73 |
|
| 74 |
# Called to remove item from the queue |
| 75 |
|
| 76 |
$action = 'AddReturn'; |
| 77 |
AddReturn( $item->barcode ); |
| 78 |
|
| 79 |
# Not called |
| 80 |
|
| 81 |
# Test 2 |
| 82 |
$action = 'transferbook'; |
| 83 |
transferbook( |
| 84 |
{ |
| 85 |
barcode => $item->barcode, |
| 86 |
to_branch => $library1->branchcode, |
| 87 |
from_branch => $library->branchcode, |
| 88 |
trigger => 'Manual', |
| 89 |
} |
| 90 |
); |
| 91 |
|
| 92 |
# Test 3 + 4 |
| 93 |
$action = 'do_checkin'; |
| 94 |
my $mockILS = Test::MockObject->new; |
| 95 |
my $server = { ils => $mockILS }; |
| 96 |
my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); |
| 97 |
my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); |
| 98 |
my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new(); |
| 99 |
$co_transaction->patron($sip_patron); |
| 100 |
$co_transaction->item($sip_item); |
| 101 |
|
| 102 |
# Queue rebuilt by checkout |
| 103 |
my $checkout = $co_transaction->do_checkout(); |
| 104 |
my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new(); |
| 105 |
$ci_transaction->patron($sip_patron); |
| 106 |
$ci_transaction->item($sip_item); |
| 107 |
|
| 108 |
# Queue rebuilt on checkin |
| 109 |
my $checkin = $ci_transaction->do_checkin( $library->branchcode, C4::SIP::Sip::timestamp ); |
| 110 |
|
| 111 |
# Test 5+6 |
| 112 |
$action = 'automatic_checkin'; |
| 113 |
AddIssue( $patron, $item->barcode, ); |
| 114 |
|
| 115 |
# Called to remove item from the queue |
| 116 |
my $checkouts = Koha::Checkouts->search( { 'me.itemnumber' => $item->itemnumber } ); |
| 117 |
$checkouts->automatic_checkin; |
| 118 |
|
| 119 |
t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); |
| 120 |
|
| 121 |
# Below should not generate any tests as queue is deactivated |
| 122 |
|
| 123 |
$action = 'AddIssue'; |
| 124 |
AddIssue( $patron, $item->barcode, ); |
| 125 |
|
| 126 |
# Not called |
| 127 |
|
| 128 |
$action = 'AddReturn'; |
| 129 |
AddReturn( $item->barcode ); |
| 130 |
|
| 131 |
# Not called |
| 132 |
|
| 133 |
$schema->storage->txn_rollback; |
| 134 |
}; |