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/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 => 69;
20
use Test::More tests => 68;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 33-39 use C4::Biblio qw( GetMarcFromKohaField ModBiblio ); Link Here
33
use C4::HoldsQueue;
33
use C4::HoldsQueue;
34
use C4::Members;
34
use C4::Members;
35
use C4::Reserves
35
use C4::Reserves
36
    qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee RevertWaitingStatus CanItemBeReserved MergeHolds );
36
    qw( AddReserve AlterPriority CheckReserves ModReserve ModReserveAffect ReserveSlip CalculatePriority CanBookBeReserved IsAvailableForItemLevelRequest MoveReserve ChargeReserveFee CanItemBeReserved MergeHolds );
37
use Koha::ActionLogs;
37
use Koha::ActionLogs;
38
use Koha::Biblios;
38
use Koha::Biblios;
39
use Koha::Caches;
39
use Koha::Caches;
Lines 1021-1138 subtest 'ChargeReserveFee tests' => sub { Link Here
1021
    is( $line->branchcode,        $library->id, "Library id is picked from userenv and stored correctly" );
1021
    is( $line->branchcode,        $library->id, "Library id is picked from userenv and stored correctly" );
1022
};
1022
};
1023
1023
1024
subtest 'reserves.item_level_hold' => sub {
1025
    plan tests => 2;
1026
1027
    my $item   = $builder->build_sample_item;
1028
    my $patron = $builder->build_object(
1029
        {
1030
            class => 'Koha::Patrons',
1031
            value => { branchcode => $item->homebranch }
1032
        }
1033
    );
1034
1035
    subtest 'item level hold' => sub {
1036
        plan tests => 5;
1037
        my $reserve_id = AddReserve(
1038
            {
1039
                branchcode     => $item->homebranch,
1040
                borrowernumber => $patron->borrowernumber,
1041
                biblionumber   => $item->biblionumber,
1042
                priority       => 1,
1043
                itemnumber     => $item->itemnumber,
1044
            }
1045
        );
1046
1047
        my $hold = Koha::Holds->find($reserve_id);
1048
        is( $hold->item_level_hold, 1, 'item_level_hold should be set when AddReserve is called with a specific item' );
1049
1050
        # Mark it waiting
1051
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 );
1052
1053
        my $mock = Test::MockModule->new('Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue');
1054
        $mock->mock(
1055
            'enqueue',
1056
            sub {
1057
                my ( $self, $args ) = @_;
1058
                is_deeply(
1059
                    $args->{biblio_ids},
1060
                    [ $hold->biblionumber ],
1061
                    "AlterPriority triggers a holds queue update for the related biblio"
1062
                );
1063
            }
1064
        );
1065
1066
        t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 1 );
1067
        t::lib::Mocks::mock_preference( 'HoldsLog',           1 );
1068
1069
        # Revert the waiting status
1070
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1071
1072
        $hold = Koha::Holds->find($reserve_id);
1073
1074
        is(
1075
            $hold->itemnumber, $item->itemnumber,
1076
            'Itemnumber should not be removed when the waiting status is revert'
1077
        );
1078
1079
        my $log =
1080
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->next;
1081
        my $expected = sprintf q{'timestamp' => '%s'}, $hold->timestamp;
1082
        like( $log->info, qr{$expected}, 'Timestamp logged is the current one' );
1083
        my $log_count =
1084
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1085
1086
        t::lib::Mocks::mock_preference( 'RealTimeHoldsQueue', 0 );
1087
        t::lib::Mocks::mock_preference( 'HoldsLog',           0 );
1088
1089
        $hold->set_waiting;
1090
1091
        # Revert the waiting status, RealTimeHoldsQueue => shouldn't add a test
1092
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1093
1094
        $hold->delete;    # cleanup
1095
1096
        my $log_count_after =
1097
            Koha::ActionLogs->search( { module => 'HOLDS', action => 'MODIFY', object => $hold->reserve_id } )->count;
1098
        is( $log_count, $log_count_after, "No logging is added for RevertWaitingStatus when HoldsLog is disabled" );
1099
1100
    };
1101
1102
    subtest 'biblio level hold' => sub {
1103
        plan tests => 3;
1104
        my $reserve_id = AddReserve(
1105
            {
1106
                branchcode     => $item->homebranch,
1107
                borrowernumber => $patron->borrowernumber,
1108
                biblionumber   => $item->biblionumber,
1109
                priority       => 1,
1110
            }
1111
        );
1112
1113
        my $hold = Koha::Holds->find($reserve_id);
1114
        is(
1115
            $hold->item_level_hold, 0,
1116
            'item_level_hold should not be set when AddReserve is called without a specific item'
1117
        );
1118
1119
        # Mark it waiting
1120
        ModReserveAffect( $item->itemnumber, $patron->borrowernumber, 1 );
1121
1122
        $hold = Koha::Holds->find($reserve_id);
1123
        is( $hold->itemnumber, $item->itemnumber, 'Itemnumber should be set on hold confirmation' );
1124
1125
        # Revert the waiting status
1126
        C4::Reserves::RevertWaitingStatus( { itemnumber => $item->itemnumber } );
1127
1128
        $hold = Koha::Holds->find($reserve_id);
1129
        is( $hold->itemnumber, undef, 'Itemnumber should be removed when the waiting status is revert' );
1130
1131
        $hold->delete;
1132
    };
1133
1134
};
1135
1136
subtest 'MoveReserve additional test' => sub {
1024
subtest 'MoveReserve additional test' => sub {
1137
1025
1138
    plan tests => 8;
1026
    plan tests => 8;
Lines 1208-1214 subtest 'MoveReserve additional test' => sub { Link Here
1208
1096
1209
};
1097
};
1210
1098
1211
subtest 'RevertWaitingStatus' => sub {
1099
# FIXME: Should be in Circulation.t
1100
subtest 'AddIssue calls $hold->revert_waiting()' => sub {
1212
1101
1213
    plan tests => 2;
1102
    plan tests => 2;
1214
1103
(-)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 1099-1105 subtest do_checkout_with_holds => sub { Link Here
1099
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' );
1099
    is( $patron->checkouts->count, 0, 'Checkout was not done due to attached hold (P)' );
1100
1100
1101
    # Test non-attached holds
1101
    # Test non-attached holds
1102
    C4::Reserves::RevertWaitingStatus( { itemnumber => $hold->itemnumber } );
1102
    $hold->set_waiting();
1103
    $hold->revert_waiting();
1103
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' );
1104
    t::lib::Mocks::mock_preference( 'AllowItemsOnHoldCheckoutSIP', '0' );
1104
    $co_transaction->do_checkout();
1105
    $co_transaction->do_checkout();
1105
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' );
1106
    is( $patron->checkouts->count, 0, 'Checkout refused due to hold and AllowItemsOnHoldCheckoutSIP' );
1106
- 

Return to bug 40058