Bug 40058: Adjust existing tests

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
(cherry picked from commit 23a2b69a2a)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomas Cohen Arazi 2025-06-03 10:32:05 -03:00 committed by Paul Derscheid
parent 12e98336db
commit 18709e563d
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
7 changed files with 13 additions and 218 deletions

View File

@ -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' ),

View File

@ -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(

View File

@ -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;

View File

@ -20,7 +20,7 @@
use Modern::Perl;
use Test::NoWarnings;
use Test::More tests => 16;
use Test::More tests => 17;
use Test::Exception;
use Test::MockModule;

View File

@ -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 );

View File

@ -17,7 +17,7 @@
use Modern::Perl;
use Test::More tests => 71;
use Test::More tests => 70;
use Test::NoWarnings;
use Test::MockModule;
use Test::Warn;
@ -34,7 +34,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;
@ -1029,118 +1029,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;
@ -1216,7 +1104,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;

View File

@ -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 );
@ -1118,7 +1118,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' );