View | Details | Raw Unified | Return to bug 40058
Collapse All | Expand All

(-)a/t/db_dependent/Circulation.t (-1 / +1 lines)
Lines 1529-1535 subtest "CanBookBeRenewed tests" => sub { Link Here
1529
                }
1529
                }
1530
            }
1530
            }
1531
        );
1531
        );
1532
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj,, $issue );
1532
        $latest_auto_renew_date = GetLatestAutoRenewDate( $renewing_borrower_obj, $issue );
1533
        is(
1533
        is(
1534
            $latest_auto_renew_date->truncate( to => 'minute' ),
1534
            $latest_auto_renew_date->truncate( to => 'minute' ),
1535
            $five_days_before->truncate( to => 'minute' ),
1535
            $five_days_before->truncate( to => 'minute' ),
(-)a/t/db_dependent/Hold.t (-2 / +2 lines)
Lines 257-263 subtest "store() tests" => sub { Link Here
257
    $hold->discard_changes;
257
    $hold->discard_changes;
258
258
259
    $hold->set_waiting;
259
    $hold->set_waiting;
260
    C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
260
    $hold->revert_waiting();
261
    $hold->discard_changes;
261
    $hold->discard_changes;
262
262
263
    $expected_date = dt_from_string( $hold->reservedate )->add( years => 2 )->ymd;
263
    $expected_date = dt_from_string( $hold->reservedate )->add( years => 2 )->ymd;
Lines 283-289 subtest "store() tests" => sub { Link Here
283
    $hold->discard_changes;
283
    $hold->discard_changes;
284
284
285
    $hold->set_waiting;
285
    $hold->set_waiting;
286
    C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
286
    $hold->revert_waiting();
287
    $hold->discard_changes;
287
    $hold->discard_changes;
288
288
289
    is(
289
    is(
(-)a/t/db_dependent/Holds/RevertWaitingStatus.t (-95 lines)
Lines 1-95 Link Here
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
use Test::NoWarnings;
20
use Test::More tests => 4;
21
use MARC::Record;
22
23
use Koha::Libraries;
24
use Koha::Patrons;
25
use C4::Context;
26
use C4::Items;
27
use C4::Biblio;
28
use C4::Reserves qw( AddReserve ModReserve ModReserveAffect );
29
30
use t::lib::TestBuilder;
31
use t::lib::Mocks;
32
33
my $schema = Koha::Database->schema;
34
$schema->storage->txn_begin;
35
my $builder = t::lib::TestBuilder->new;
36
my $dbh     = C4::Context->dbh;
37
38
$dbh->do("DELETE FROM reserves");
39
$dbh->do("DELETE FROM old_reserves");
40
41
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
42
my $itemtype   = $builder->build( { source => 'Itemtype', value => { notforloan => 0 } } )->{itemtype};
43
44
t::lib::Mocks::mock_userenv( { flags => 1, userid => '1', branchcode => $branchcode } );
45
46
my $borrowers_count = 3;
47
48
my $biblio       = $builder->build_sample_biblio();
49
my $item_barcode = 'my_barcode';
50
my $itemnumber   = Koha::Item->new(
51
    {
52
        biblionumber  => $biblio->biblionumber,
53
        homebranch    => $branchcode,
54
        holdingbranch => $branchcode,
55
        barcode       => $item_barcode,
56
        itype         => $itemtype
57
    },
58
)->store->itemnumber;
59
60
# Create some borrowers
61
my $patron_category = $builder->build( { source => 'Category' } );
62
my @borrowernumbers;
63
foreach my $i ( 1 .. $borrowers_count ) {
64
    my $borrowernumber = Koha::Patron->new(
65
        {
66
            firstname    => 'my firstname',
67
            surname      => 'my surname ' . $i,
68
            categorycode => $patron_category->{categorycode},
69
            branchcode   => $branchcode,
70
        }
71
    )->store->borrowernumber;
72
    push @borrowernumbers, $borrowernumber;
73
}
74
75
# Create five item level holds
76
foreach my $borrowernumber (@borrowernumbers) {
77
    AddReserve(
78
        {
79
            branchcode     => $branchcode,
80
            borrowernumber => $borrowernumber,
81
            biblionumber   => $biblio->biblionumber,
82
        }
83
    );
84
}
85
86
ModReserveAffect( $itemnumber, $borrowernumbers[0] );
87
my $patron = Koha::Patrons->find( $borrowernumbers[1] );
88
C4::Circulation::AddIssue( $patron, $item_barcode, undef, 'revert' );
89
90
my $priorities = $dbh->selectall_arrayref("SELECT priority FROM reserves ORDER BY priority ASC");
91
ok( scalar @$priorities == 2,   'Only 2 holds remain in the reserves table' );
92
ok( $priorities->[0]->[0] == 1, 'First hold has a priority of 1' );
93
ok( $priorities->[1]->[0] == 2, 'Second hold has a priority of 2' );
94
95
$schema->storage->txn_rollback;
(-)a/t/db_dependent/Koha/Hold.t (-1 / +1 lines)
Lines 20-26 Link Here
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::More tests => 16;
23
use Test::More tests => 17;
24
24
25
use Test::Exception;
25
use Test::Exception;
26
use Test::MockModule;
26
use Test::MockModule;
(-)a/t/db_dependent/Koha/Holds.t (-2 / +2 lines)
Lines 992-998 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
992
        is( $hold->expirationdate,         $patron_expiration_date );
992
        is( $hold->expirationdate,         $patron_expiration_date );
993
        is( $hold->patron_expiration_date, $patron_expiration_date );
993
        is( $hold->patron_expiration_date, $patron_expiration_date );
994
994
995
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
995
        $hold->revert_waiting();
996
996
997
        $hold = $hold->get_from_storage;
997
        $hold = $hold->get_from_storage;
998
        is( $hold->expirationdate,         $patron_expiration_date );
998
        is( $hold->expirationdate,         $patron_expiration_date );
Lines 1033-1039 subtest 'set_waiting+patron_expiration_date' => sub { Link Here
1033
        is( $hold->expirationdate,         $new_expiration_date );
1033
        is( $hold->expirationdate,         $new_expiration_date );
1034
        is( $hold->patron_expiration_date, $patron_expiration_date );
1034
        is( $hold->patron_expiration_date, $patron_expiration_date );
1035
1035
1036
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1036
        $hold->revert_waiting();
1037
1037
1038
        $hold = $hold->get_from_storage;
1038
        $hold = $hold->get_from_storage;
1039
        is( $hold->expirationdate,         $patron_expiration_date );
1039
        is( $hold->expirationdate,         $patron_expiration_date );
(-)a/t/db_dependent/Reserves.t (-115 / +4 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 71;
20
use Test::More tests => 70;
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
Lines 34-40 use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); Link Here
34
use C4::HoldsQueue;
34
use C4::HoldsQueue;
35
use C4::Members;
35
use C4::Members;
36
use C4::Reserves
36
use C4::Reserves
37
    qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
37
    qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee CanItemBeReserved MergeHolds );
38
use Koha::ActionLogs;
38
use Koha::ActionLogs;
39
use Koha::Biblios;
39
use Koha::Biblios;
40
use Koha::Caches;
40
use Koha::Caches;
Lines 1029-1146 subtest 'ChargeReserveFee tests' => sub { Link Here
1029
    is( $line->branchcode,        $library->id, "Library id is picked from userenv and stored correctly" );
1029
    is( $line->branchcode,        $library->id, "Library id is picked from userenv and stored correctly" );
1030
};
1030
};
1031
1031
1032
subtest 'reserves.item_level_hold' => sub {
1033
    plan tests => 2;
1034
1035
    my $item   = $builder->build_sample_item;
1036
    my $patron = $builder->build_object(
1037
        {
1038
            class => 'Koha::Patrons',
1039
            value => { branchcode => $item->homebranch }
1040
        }
1041
    );
1042
1043
    subtest 'item level hold' => sub {
1044
        plan tests => 5;
1045
        my $reserve_id = AddReserve(
1046
            {
1047
                branchcode     => $item->homebranch,
1048
                borrowernumber => $patron->borrowernumber,
1049
                biblionumber   => $item->biblionumber,
1050
                priority       => 1,
1051
                itemnumber     => $item->itemnumber,
1052
            }
1053
        );
1054
1055
        my $hold = Koha::Holds->find($reserve_id);
1056
        is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' );
1057
1058
        # Mark it waiting
1059
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 );
1060
1061
        my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
1062
        $mock->mock(
1063
            'enqueue',
1064
            sub {
1065
                my ( $self, $args ) = @_;
1066
                is_deeply(
1067
                    $args->{biblio_ids},
1068
                    [ $hold->biblionumber ],
1069
                    "AlterPriority triggers a holds queue update for the related biblio"
1070
                );
1071
            }
1072
        );
1073
1074
        t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
1075
        t::lib::Mocks::mock_preference( 'HoldsLog',           1 );
1076
1077
        # Revert the waiting status
1078
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1079
1080
        $hold = Koha::Holds->find($reserve_id);
1081
1082
        is(
1083
            $hold->itemnumber, $item->itemnumber,
1084
            'Itemnumber should not be removed when the waiting status is revert'
1085
        );
1086
1087
        my $log =
1088
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->next;
1089
        my $expected = sprintf q{'timestamp' => '%s'}, $hold->timestamp;
1090
        like( $log->info, qr{$expected}, 'Timestamp logged is the current one' );
1091
        my $log_count =
1092
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1093
1094
        t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
1095
        t::lib::Mocks::mock_preference( 'HoldsLog',           0 );
1096
1097
        $hold->set_waiting;
1098
1099
        # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test
1100
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1101
1102
        $hold->delete;    # cleanup
1103
1104
        my $log_count_after =
1105
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1106
        is( $log_count, $log_count_after, "No logging is added for RevertWaitingStatus when HoldsLog is disabled" );
1107
1108
    };
1109
1110
    subtest 'biblio level hold' => sub {
1111
        plan tests => 3;
1112
        my $reserve_id = AddReserve(
1113
            {
1114
                branchcode     => $item->homebranch,
1115
                borrowernumber => $patron->borrowernumber,
1116
                biblionumber   => $item->biblionumber,
1117
                priority       => 1,
1118
            }
1119
        );
1120
1121
        my $hold = Koha::Holds->find($reserve_id);
1122
        is(
1123
            $hold->item_level_hold, 0,
1124
            'item_level_hold should not be set when AddReserve is called without a specific item'
1125
        );
1126
1127
        # Mark it waiting
1128
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 );
1129
1130
        $hold = Koha::Holds->find($reserve_id);
1131
        is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should be set on hold confirmation' );
1132
1133
        # Revert the waiting status
1134
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1135
1136
        $hold = Koha::Holds->find($reserve_id);
1137
        is( $hold->itemnumber, undef, 'Itemnumber should be removed when the waiting status is revert' );
1138
1139
        $hold->delete;
1140
    };
1141
1142
};
1143
1144
subtest 'MoveReserve additional test' => sub {
1032
subtest 'MoveReserve additional test' => sub {
1145
1033
1146
    plan tests => 8;
1034
    plan tests => 8;
Lines 1216-1222 subtest 'MoveReserve additional test' => sub { Link Here
1216
1104
1217
};
1105
};
1218
1106
1219
subtest 'RevertWaitingStatus' => sub {
1107
# FIXME: Should be in Circulation.t
1108
subtest 'AddIssue calls $hold->revert_waiting()' => sub {
1220
1109
1221
    plan tests => 2;
1110
    plan tests => 2;
1222
1111
(-)a/t/db_dependent/SIP/Transaction.t (-3 / +3 lines)
Lines 22-28 use C4::SIP::ILS::Transaction::Hold; Link Here
22
use C4::SIP::ILS::Transaction::Checkout;
22
use C4::SIP::ILS::Transaction::Checkout;
23
use C4::SIP::ILS::Transaction::Checkin;
23
use C4::SIP::ILS::Transaction::Checkin;
24
24
25
use C4::Reserves qw( AddReserve ModReserve ModReserveAffect RevertWaitingStatus );
25
use C4::Reserves qw( AddReserve ModReserve ModReserveAffect );
26
use Koha::CirculationRules;
26
use Koha::CirculationRules;
27
use Koha::Item::Transfer;
27
use Koha::Item::Transfer;
28
use Koha::DateUtils qw( dt_from_string output_pref );
28
use Koha::DateUtils qw( dt_from_string output_pref );
Lines 1118-1124 subtest do_checkout_with_holds => sub { Link Here
1118
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' );
1118
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' );
1119
1119
1120
    # Test non-attached holds
1120
    # Test non-attached holds
1121
    C4::Reserves::RevertWaitingStatus( { itemnumber => $hold->itemnumber } );
1121
    $hold->set_waiting();
1122
    $hold->revert_waiting();
1122
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' );
1123
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' );
1123
    $co_transaction->do_checkout();
1124
    $co_transaction->do_checkout();
1124
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' );
1125
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' );
1125
- 

Return to bug 40058