Bugzilla – Attachment 182926 Details for
Bug 40058
Move RevertWaitingStatus to Koha::Hold->revert_waiting()
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40058: Adjust existing tests
Bug-40058-Adjust-existing-tests.patch (text/plain), 12.97 KB, created by
Tomás Cohen Arazi (tcohen)
on 2025-06-03 15:12:20 UTC
(
hide
)
Description:
Bug 40058: Adjust existing tests
Filename:
MIME Type:
Creator:
Tomás Cohen Arazi (tcohen)
Created:
2025-06-03 15:12:20 UTC
Size:
12.97 KB
patch
obsolete
>From 8798950c8df8b63ac3063eb445bf381ea283838c Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Tue, 3 Jun 2025 10:32:05 -0300 >Subject: [PATCH] Bug 40058: Adjust existing tests > >--- > t/db_dependent/Circulation.t | 2 +- > t/db_dependent/Hold.t | 4 +- > t/db_dependent/Holds/RevertWaitingStatus.t | 95 ---------------- > t/db_dependent/Koha/Holds.t | 4 +- > t/db_dependent/Reserves.t | 119 +-------------------- > t/db_dependent/SIP/Transaction.t | 5 +- > 6 files changed, 12 insertions(+), 217 deletions(-) > delete mode 100755 t/db_dependent/Holds/RevertWaitingStatus.t > >diff --git a/t/db_dependent/Circulation.t b/t/db_dependent/Circulation.t >index e10f7a01c9c..672eafed8d2 100755 >--- a/t/db_dependent/Circulation.t >+++ b/t/db_dependent/Circulation.t >@@ -1529,7 +1529,7 @@ subtest "CanBookBeRenewed tests" => sub { > } > } > ); >- $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj,, $issue ); >+ $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue ); > is( > $latest_auto_renew_date->truncate( to => 'minute' ), > $five_days_before->truncate( to => 'minute' ), >diff --git a/t/db_dependent/Hold.t b/t/db_dependent/Hold.t >index 21572e476c8..888f1b9d5d9 100755 >--- a/t/db_dependent/Hold.t >+++ b/t/db_dependent/Hold.t >@@ -257,7 +257,7 @@ subtest "store() tests" => sub { > $hold->discard_changes; > > $hold->set_waiting; >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >+ $hold->revert_waiting(); > $hold->discard_changes; > > $expected_date = dt_from_string( $hold->reservedate )->add( years => 2 )->ymd; >@@ -283,7 +283,7 @@ subtest "store() tests" => sub { > $hold->discard_changes; > > $hold->set_waiting; >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >+ $hold->revert_waiting(); > $hold->discard_changes; > > is( >diff --git a/t/db_dependent/Holds/RevertWaitingStatus.t b/t/db_dependent/Holds/RevertWaitingStatus.t >deleted file mode 100755 >index fdcb06423f1..00000000000 >--- a/t/db_dependent/Holds/RevertWaitingStatus.t >+++ /dev/null >@@ -1,95 +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::NoWarnings; >-use Test::More tests => 4; >-use MARC::Record; >- >-use Koha::Libraries; >-use Koha::Patrons; >-use C4::Context; >-use C4::Items; >-use C4::Biblio; >-use C4::Reserves qw( AddReserve ModReserve ModReserveAffect ); >- >-use t::lib::TestBuilder; >-use t::lib::Mocks; >- >-my $schema = Koha::Database->schema; >-$schema->storage->txn_begin; >-my $builder = t::lib::TestBuilder->new; >-my $dbh = C4::Context->dbh; >- >-$dbh->do("DELETE FROM reserves"); >-$dbh->do("DELETE FROM old_reserves"); >- >-my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; >-my $itemtype = $builder->build( { source => 'Itemtype', value => { notforloan => 0 } } )->{itemtype}; >- >-t::lib::Mocks::mock_userenv( { flags => 1, userid => '1', branchcode => $branchcode } ); >- >-my $borrowers_count = 3; >- >-my $biblio = $builder->build_sample_biblio(); >-my $item_barcode = 'my_barcode'; >-my $itemnumber = Koha::Item->new( >- { >- biblionumber => $biblio->biblionumber, >- homebranch => $branchcode, >- holdingbranch => $branchcode, >- barcode => $item_barcode, >- itype => $itemtype >- }, >-)->store->itemnumber; >- >-# Create some borrowers >-my $patron_category = $builder->build( { source => 'Category' } ); >-my @borrowernumbers; >-foreach my $i ( 1 .. $borrowers_count ) { >- my $borrowernumber = Koha::Patron->new( >- { >- firstname => 'my firstname', >- surname => 'my surname ' . $i, >- categorycode => $patron_category->{categorycode}, >- branchcode => $branchcode, >- } >- )->store->borrowernumber; >- push @borrowernumbers, $borrowernumber; >-} >- >-# Create five item level holds >-foreach my $borrowernumber (@borrowernumbers) { >- AddReserve( >- { >- branchcode => $branchcode, >- borrowernumber => $borrowernumber, >- biblionumber => $biblio->biblionumber, >- } >- ); >-} >- >-ModReserveAffect( $itemnumber, $borrowernumbers[0] ); >-my $patron = Koha::Patrons->find( $borrowernumbers[1] ); >-C4::Circulation::AddIssue( $patron, $item_barcode, undef, 'revert' ); >- >-my $priorities = $dbh->selectall_arrayref("SELECT priority FROM reserves ORDER BY priority ASC"); >-ok( scalar @$priorities == 2, 'Only 2 holds remain in the reserves table' ); >-ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' ); >-ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' ); >- >-$schema->storage->txn_rollback; >diff --git a/t/db_dependent/Koha/Holds.t b/t/db_dependent/Koha/Holds.t >index a27dd02ed8a..1a62606326d 100755 >--- a/t/db_dependent/Koha/Holds.t >+++ b/t/db_dependent/Koha/Holds.t >@@ -992,7 +992,7 @@ subtest 'set_waiting+patron_expiration_date' => sub { > is( $hold->expirationdate, $patron_expiration_date ); > is( $hold->patron_expiration_date, $patron_expiration_date ); > >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >+ $hold->revert_waiting(); > > $hold = $hold->get_from_storage; > is( $hold->expirationdate, $patron_expiration_date ); >@@ -1033,7 +1033,7 @@ subtest 'set_waiting+patron_expiration_date' => sub { > is( $hold->expirationdate, $new_expiration_date ); > is( $hold->patron_expiration_date, $patron_expiration_date ); > >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >+ $hold->revert_waiting(); > > $hold = $hold->get_from_storage; > is( $hold->expirationdate, $patron_expiration_date ); >diff --git a/t/db_dependent/Reserves.t b/t/db_dependent/Reserves.t >index 97cd34aa3bc..e40297462ca 100755 >--- a/t/db_dependent/Reserves.t >+++ b/t/db_dependent/Reserves.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 69; >+use Test::More tests => 68; > use Test::MockModule; > use Test::Warn; > >@@ -33,7 +33,7 @@ use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); > use C4::HoldsQueue; > use C4::Members; > use C4::Reserves >- qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds ); >+ qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee CanItemBeReserved MergeHolds ); > use Koha::ActionLogs; > use Koha::Biblios; > use Koha::Caches; >@@ -1021,118 +1021,6 @@ subtest 'ChargeReserveFee tests' => sub { > is( $line->branchcode, $library->id, "Library id is picked from userenv and stored correctly" ); > }; > >-subtest 'reserves.item_level_hold' => sub { >- plan tests => 2; >- >- my $item = $builder->build_sample_item; >- my $patron = $builder->build_object( >- { >- class => 'Koha::Patrons', >- value => { branchcode => $item->homebranch } >- } >- ); >- >- subtest 'item level hold' => sub { >- plan tests => 5; >- my $reserve_id = AddReserve( >- { >- branchcode => $item->homebranch, >- borrowernumber => $patron->borrowernumber, >- biblionumber => $item->biblionumber, >- priority => 1, >- itemnumber => $item->itemnumber, >- } >- ); >- >- my $hold = Koha::Holds->find($reserve_id); >- is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' ); >- >- # Mark it waiting >- ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 ); >- >- my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue'); >- $mock->mock( >- 'enqueue', >- sub { >- my ( $self, $args ) = @_; >- is_deeply( >- $args->{biblio_ids}, >- [ $hold->biblionumber ], >- "AlterPriority triggers a holds queue update for the related biblio" >- ); >- } >- ); >- >- t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 ); >- t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); >- >- # Revert the waiting status >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >- >- $hold = Koha::Holds->find($reserve_id); >- >- is( >- $hold->itemnumber, $item->itemnumber, >- 'Itemnumber should not be removed when the waiting status is revert' >- ); >- >- my $log = >- Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->next; >- my $expected = sprintf q{'timestamp' => '%s'}, $hold->timestamp; >- like( $log->info, qr{$expected}, 'Timestamp logged is the current one' ); >- my $log_count = >- Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; >- >- t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 ); >- t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); >- >- $hold->set_waiting; >- >- # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >- >- $hold->delete; # cleanup >- >- my $log_count_after = >- Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count; >- is( $log_count, $log_count_after, "No logging is added for RevertWaitingStatus when HoldsLog is disabled" ); >- >- }; >- >- subtest 'biblio level hold' => sub { >- plan tests => 3; >- my $reserve_id = AddReserve( >- { >- branchcode => $item->homebranch, >- borrowernumber => $patron->borrowernumber, >- biblionumber => $item->biblionumber, >- priority => 1, >- } >- ); >- >- my $hold = Koha::Holds->find($reserve_id); >- is( >- $hold->item_level_hold, 0, >- 'item_level_hold should not be set when AddReserve is called without a specific item' >- ); >- >- # Mark it waiting >- ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 ); >- >- $hold = Koha::Holds->find($reserve_id); >- is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should be set on hold confirmation' ); >- >- # Revert the waiting status >- C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } ); >- >- $hold = Koha::Holds->find($reserve_id); >- is( $hold->itemnumber, undef, 'Itemnumber should be removed when the waiting status is revert' ); >- >- $hold->delete; >- }; >- >-}; >- > subtest 'MoveReserve additional test' => sub { > > plan tests => 8; >@@ -1208,7 +1096,8 @@ subtest 'MoveReserve additional test' => sub { > > }; > >-subtest 'RevertWaitingStatus' => sub { >+# FIXME: Should be in Circulation.t >+subtest 'AddIssue calls $hold->revert_waiting()' => sub { > > plan tests => 2; > >diff --git a/t/db_dependent/SIP/Transaction.t b/t/db_dependent/SIP/Transaction.t >index a07033def5b..beab3c46175 100755 >--- a/t/db_dependent/SIP/Transaction.t >+++ b/t/db_dependent/SIP/Transaction.t >@@ -22,7 +22,7 @@ use C4::SIP::ILS::Transaction::Hold; > use C4::SIP::ILS::Transaction::Checkout; > use C4::SIP::ILS::Transaction::Checkin; > >-use C4::Reserves qw( AddReserve ModReserve ModReserveAffect RevertWaitingStatus ); >+use C4::Reserves qw( AddReserve ModReserve ModReserveAffect ); > use Koha::CirculationRules; > use Koha::Item::Transfer; > use Koha::DateUtils qw( dt_from_string output_pref ); >@@ -1099,7 +1099,8 @@ subtest do_checkout_with_holds => sub { > is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' ); > > # Test non-attached holds >- C4::Reserves::RevertWaitingStatus( { itemnumber => $hold->itemnumber } ); >+ $hold->set_waiting(); >+ $hold->revert_waiting(); > t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' ); > $co_transaction->do_checkout(); > is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' ); >-- >2.49.0
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 40058
:
182924
|
182925
|
182926
|
182941
|
182942
|
182943