From 56fcfc3e9a144c5a108f0824075d5e5bf2072d23 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 31 Jul 2020 11:14:09 -0300 Subject: [PATCH] Bug 26114: Regression tests Signed-off-by: Tomas Cohen Arazi --- t/db_dependent/Illrequests.t | 64 +++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/Illrequests.t b/t/db_dependent/Illrequests.t index be59d1ae86..f6d6fa76cd 100644 --- a/t/db_dependent/Illrequests.t +++ b/t/db_dependent/Illrequests.t @@ -18,6 +18,9 @@ use Modern::Perl; use File::Basename qw/basename/; + +use C4::Circulation qw(AddIssue AddReturn); + use Koha::Database; use Koha::Illrequestattributes; use Koha::Illrequest::Config; @@ -36,7 +39,7 @@ use Test::Exception; use Test::Deep qw/ cmp_deeply ignore /; use Test::Warn; -use Test::More tests => 12; +use Test::More tests => 13; my $schema = Koha::Database->new->schema; my $builder = t::lib::TestBuilder->new; @@ -1160,3 +1163,62 @@ subtest 'Custom statuses' => sub { $schema->storage->txn_rollback; }; + +subtest 'Checking in hook' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + # Build infrastructure + my $backend = Test::MockObject->new; + $backend->set_isa('Koha::Illbackends::Mock'); + $backend->set_always('name', 'Mock'); + + my $config = Test::MockObject->new; + $config->set_always('backend_dir', "/tmp"); + + my $item = $builder->build_sample_item(); + my $patron = $builder->build_object({ class => 'Koha::Patrons' }); + + t::lib::Mocks::mock_userenv( + { + patron => $patron, + branchcode => $patron->branchcode + } + ); + + my $illrq = $builder->build_object( + { + class => 'Koha::Illrequests', + value => { + biblio_id => $item->biblio->biblionumber, + status => 'NEW' + } + } + ); + + $illrq->_config($config); + $illrq->_backend($backend); + + t::lib::Mocks::mock_preference('CirculateILL', 1); + + # Add an issue + AddIssue( $patron->unblessed, $item->barcode ); + # Make the item withdrawn so checking-in is rejected + t::lib::Mocks::mock_preference('BlockReturnOfWithdrawnItems', 1); + $item->set({ withdrawn => 1 })->store; + AddReturn( $item->barcode, $patron->branchcode ); + # refresh request + $illrq->discard_changes; + isnt( $illrq->status, 'RET' ); + + # allow the check-in + $item->set({ withdrawn => 0 })->store; + AddReturn( $item->barcode, $patron->branchcode ); + # refresh request + $illrq->discard_changes; + is( $illrq->status, 'RET' ); + + $schema->storage->txn_rollback; +}; -- 2.28.0