Bugzilla – Attachment 186594 Details for
Bug 34596
Items in transit should not show up in the holds queue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34596: Unit tests
Bug-34596-Unit-tests.patch (text/plain), 8.04 KB, created by
Nick Clemens (kidclamp)
on 2025-09-18 20:23:35 UTC
(
hide
)
Description:
Bug 34596: Unit tests
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2025-09-18 20:23:35 UTC
Size:
8.04 KB
patch
obsolete
>From 07cd66a82c40de72986f2bc451f3d6575c5ee299 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Thu, 18 Sep 2025 20:21:57 +0000 >Subject: [PATCH] Bug 34596: Unit tests > >Writing these I found that transferbook was generating two queue rebuilds - fixed that >--- > C4/Circulation.pm | 4 +- > t/db_dependent/Circulation_holdsqueue.t | 79 -------------- > t/db_dependent/Realtime_holdsqueue.t | 134 ++++++++++++++++++++++++ > 3 files changed, 137 insertions(+), 80 deletions(-) > delete mode 100755 t/db_dependent/Circulation_holdsqueue.t > create mode 100755 t/db_dependent/Realtime_holdsqueue.t > >diff --git a/C4/Circulation.pm b/C4/Circulation.pm >index ea841d7749c..b6b4167a9b5 100644 >--- a/C4/Circulation.pm >+++ b/C4/Circulation.pm >@@ -415,7 +415,9 @@ sub transferbook { > $messages->{'WasTransfered'} = $tbr; > > } >- ModDateLastSeen($itemnumber); >+ >+ # Only build the holds queue if we have transferred above >+ ModDateLastSeen( $itemnumber, undef, { skip_holds_queue => 1 } ); > return ( $dotransfer, $messages ); > } > >diff --git a/t/db_dependent/Circulation_holdsqueue.t b/t/db_dependent/Circulation_holdsqueue.t >deleted file mode 100755 >index 33e2a2f791b..00000000000 >--- a/t/db_dependent/Circulation_holdsqueue.t >+++ /dev/null >@@ -1,79 +0,0 @@ >-#!/usr/bin/perl >- >-# This file is part of Koha. >-# >-# Koha is free software; you can redistribute it and/or modify it >-# under the terms of the GNU General Public License as published by >-# the Free Software Foundation; either version 3 of the License, or >-# (at your option) any later version. >-# >-# Koha is distributed in the hope that it will be useful, but >-# WITHOUT ANY WARRANTY; without even the implied warranty of >-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >-# GNU General Public License for more details. >-# >-# You should have received a copy of the GNU General Public License >-# along with Koha; if not, see <http://www.gnu.org/licenses>. >- >-use Modern::Perl; >- >-use Test::More tests => 2; >-use Test::NoWarnings; >-use Test::MockModule; >- >-use C4::Circulation qw( AddIssue AddReturn ); >- >-use Koha::Database; >- >-use t::lib::Mocks; >-use t::lib::TestBuilder; >- >-my $schema = Koha::Database->schema; >-my $builder = t::lib::TestBuilder->new; >- >-subtest 'AddIssue() and AddReturn() real-time holds queue tests' => sub { >- >- plan tests => 2; >- >- $schema->storage->txn_begin; >- >- my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >- my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >- my $item = $builder->build_sample_item( { library => $library->id } ); >- >- t::lib::Mocks::mock_userenv( { branchcode => $library->id } ); >- t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 ); >- t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >- >- my $action; >- >- my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >- $mock->mock( >- 'enqueue', >- sub { >- my ( $self, $args ) = @_; >- my ( $package, $filename, $line ) = caller; >- is_deeply( >- $args->{biblio_ids}, >- [ $item->biblionumber ], >- "$action triggers a holds queue update for the related biblio from $package at line $line" >- ); >- } >- ); >- >- $action = 'AddIssue'; >- AddIssue( $patron, $item->barcode, ); >- >- $action = 'AddReturn'; >- AddReturn( $item->barcode ); >- >- t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >- >- $action = 'AddIssue'; >- AddIssue( $patron, $item->barcode, ); >- >- $action = 'AddReturn'; >- AddReturn( $item->barcode ); >- >- $schema->storage->txn_rollback; >-}; >diff --git a/t/db_dependent/Realtime_holdsqueue.t b/t/db_dependent/Realtime_holdsqueue.t >new file mode 100755 >index 00000000000..c4c074d574a >--- /dev/null >+++ b/t/db_dependent/Realtime_holdsqueue.t >@@ -0,0 +1,134 @@ >+#!/usr/bin/perl >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it >+# under the terms of the GNU General Public License as published by >+# the Free Software Foundation; either version 3 of the License, or >+# (at your option) any later version. >+# >+# Koha is distributed in the hope that it will be useful, but >+# WITHOUT ANY WARRANTY; without even the implied warranty of >+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+# GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 2; >+use Test::NoWarnings; >+use Test::MockModule; >+ >+use C4::Circulation qw( AddIssue AddReturn transferbook ); >+use C4::SIP::ILS; >+use C4::SIP::ILS::Transaction::Checkin qw( do_checkin ); >+ >+use Koha::Checkouts; >+use Koha::Database; >+ >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+ >+my $schema = Koha::Database->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+subtest 'Real-time holds queue tests' => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $library = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $item = $builder->build_sample_item( { library => $library->id } ); >+ my $item_type = $item->item_type; >+ $item_type->automatic_checkin(1)->store(); >+ >+ t::lib::Mocks::mock_userenv( { branchcode => $library->id } ); >+ t::lib::Mocks::mock_preference( 'UpdateTotalIssuesOnCirc', 1 ); >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >+ >+ my $action; >+ >+ my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >+ $mock->mock( >+ 'enqueue', >+ sub { >+ my ( $self, $args ) = @_; >+ my ( $package, $filename, $line ) = caller; >+ is_deeply( >+ $args->{biblio_ids}, >+ [ $item->biblionumber ], >+ "$action triggers a holds queue update for the related biblio from $package at line $line" >+ ); >+ } >+ ); >+ >+ # Test 1 >+ $action = 'AddIssue'; >+ AddIssue( $patron, $item->barcode, ); >+ >+ # Called to remove item from the queue >+ >+ $action = 'AddReturn'; >+ AddReturn( $item->barcode ); >+ >+ # Not called >+ >+ # Test 2 >+ $action = 'transferbook'; >+ transferbook( >+ { >+ barcode => $item->barcode, >+ to_branch => $library1->branchcode, >+ from_branch => $library->branchcode, >+ trigger => 'Manual', >+ } >+ ); >+ >+ # Test 3 + 4 >+ $action = 'do_checkin'; >+ my $mockILS = Test::MockObject->new; >+ my $server = { ils => $mockILS }; >+ my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); >+ my $sip_item = C4::SIP::ILS::Item->new( $item->barcode ); >+ my $co_transaction = C4::SIP::ILS::Transaction::Checkout->new(); >+ $co_transaction->patron($sip_patron); >+ $co_transaction->item($sip_item); >+ >+ # Queue rebuilt by checkout >+ my $checkout = $co_transaction->do_checkout(); >+ my $ci_transaction = C4::SIP::ILS::Transaction::Checkin->new(); >+ $ci_transaction->patron($sip_patron); >+ $ci_transaction->item($sip_item); >+ >+ # Queue rebuilt on checkin >+ my $checkin = $ci_transaction->do_checkin( $library->branchcode, C4::SIP::Sip::timestamp ); >+ >+ # Test 5+6 >+ $action = 'automatic_checkin'; >+ AddIssue( $patron, $item->barcode, ); >+ >+ # Called to remove item from the queue >+ my $checkouts = Koha::Checkouts->search( { 'me.itemnumber' => $item->itemnumber } ); >+ $checkouts->automatic_checkin; >+ >+ t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >+ >+ # Below should not generate any tests as queue is deactivated >+ >+ $action = 'AddIssue'; >+ AddIssue( $patron, $item->barcode, ); >+ >+ # Not called >+ >+ $action = 'AddReturn'; >+ AddReturn( $item->barcode ); >+ >+ # Not called >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34596
:
174811
|
175804
|
186592
|
186593
|
186594
|
186595
|
186596
|
186597