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

(-)a/t/db_dependent/Holds.t (-50 / +18 lines)
Lines 7-13 use t::lib::TestBuilder; Link Here
7
7
8
use C4::Context;
8
use C4::Context;
9
9
10
use Test::More tests => 55;
10
use Test::More tests => 53;
11
use MARC::Record;
11
use MARC::Record;
12
use C4::Biblio;
12
use C4::Biblio;
13
use C4::Items;
13
use C4::Items;
Lines 127-137 $holds = $patron->holds; Link Here
127
is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
127
is( $holds->next->borrowernumber, $borrowernumbers[0], "Test Koha::Patron->holds");
128
128
129
129
130
Koha::Holds->find( $reserve_id )->cancel;
131
132
$holds = $biblio->holds;
133
is( $holds->count, $borrowers_count - 1, "Koha::Hold->cancel" );
134
135
$holds = $item->current_holds;
130
$holds = $item->current_holds;
136
$first_hold = $holds->next;
131
$first_hold = $holds->next;
137
$borrowernumber = $first_hold->borrowernumber;
132
$borrowernumber = $first_hold->borrowernumber;
Lines 219-225 is( $hold->priority, '1', "Test AlterPriority(), move up" ); Link Here
219
214
220
AlterPriority( 'bottom', $hold->reserve_id );
215
AlterPriority( 'bottom', $hold->reserve_id );
221
$hold = Koha::Holds->find( $reserveid );
216
$hold = Koha::Holds->find( $reserveid );
222
is( $hold->priority, '5', "Test AlterPriority(), move to bottom" );
217
is( $hold->priority, '6', "Test AlterPriority(), move to bottom" );
223
218
224
# Regression test for bug 2394
219
# Regression test for bug 2394
225
#
220
#
Lines 275-323 ok( Link Here
275
    '... unless canreservefromotherbranches is ON (bug 2394)'
270
    '... unless canreservefromotherbranches is ON (bug 2394)'
276
);
271
);
277
272
278
# Regression test for bug 11336
273
{
279
($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
274
    # Regression test for bug 11336 # Test if ModReserve correctly recalculate the priorities
280
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
275
    ($bibnum, $title, $bibitemnum) = create_helper_biblio('DUMMY');
281
AddReserve(
276
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
282
    $branch_1,
277
    my $reserveid1 = AddReserve($branch_1, $borrowernumbers[0], $bibnum, '', 1);
283
    $borrowernumbers[0],
278
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
284
    $bibnum,
279
    my $reserveid2 = AddReserve($branch_1, $borrowernumbers[1], $bibnum, '', 2);
285
    '',
280
    ($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
286
    1,
281
    my $reserveid3 = AddReserve($branch_1, $borrowernumbers[2], $bibnum, '', 3);
287
);
282
    my $hhh = Koha::Holds->search({ biblionumber => $bibnum });
288
283
    my $hold3 = Koha::Holds->find( $reserveid3 );
289
my $reserveid1 = Koha::Holds->search({ biblionumber => $bibnum, borrowernumber => $borrowernumbers[0] })->next->reserve_id;
284
    is( $hold3->priority, 3, "The 3rd hold should have a priority set to 3" );
290
285
    ModReserve({ reserve_id => $reserveid1, rank => 'del' });
291
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
286
    ModReserve({ reserve_id => $reserveid2, rank => 'del' });
292
my $reserveid2 = AddReserve(
287
    is( $hold3->discard_changes->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
293
    $branch_1,
288
}
294
    $borrowernumbers[1],
295
    $bibnum,
296
    '',
297
    2,
298
);
299
300
my $hold1 = Koha::Holds->find( $reserveid1 );
301
$hold1->cancel;
302
303
my $hold2 = Koha::Holds->find( $reserveid2 );
304
is( $hold2->priority, 1, "After cancelreserve, the 2nd reserve becomes the first on the waiting list" );
305
306
($item_bibnum, $item_bibitemnum, $itemnumber) = AddItem({ homebranch => $branch_1, holdingbranch => $branch_1 } , $bibnum);
307
my $reserveid3 = AddReserve(
308
    $branch_1,
309
    $borrowernumbers[0],
310
    $bibnum,
311
    '',
312
    2,
313
);
314
315
my $hold3 = Koha::Holds->find( $reserveid3 );
316
is( $hold3->priority, 2, "New reserve for patron 0, the reserve has a priority = 2" );
317
318
ModReserve({ reserve_id => $reserveid2, rank => 'del' });
319
$hold3 = Koha::Holds->find( $reserveid3 );
320
is( $hold3->priority, 1, "After ModReserve, the 3rd reserve becomes the first on the waiting list" );
321
289
322
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
290
ModItem({ damaged => 1 }, $item_bibnum, $itemnumber);
323
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
291
t::lib::Mocks::mock_preference( 'AllowHoldsOnDamagedItems', 1 );
(-)a/t/db_dependent/Koha/Holds.t (+154 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2017 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use C4::Reserves;
25
use Koha::Holds;
26
use Koha::Database;
27
28
use t::lib::Mocks;
29
use t::lib::TestBuilder;
30
31
my $schema = Koha::Database->new->schema;
32
$schema->storage->txn_begin;
33
34
my $builder = t::lib::TestBuilder->new;
35
36
subtest 'cancel' => sub {
37
    plan tests => 10;
38
    my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } );
39
    my $library    = $builder->build_object( { class => 'Koha::Libraries' } );
40
    my $itemtype   = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } );
41
    my $item_info  = {
42
        biblionumber     => $biblioitem->biblionumber,
43
        biblioitemnumber => $biblioitem->biblioitemnumber,
44
        homebranch       => $library->branchcode,
45
        holdingbranch    => $library->branchcode,
46
        itype            => $itemtype->itemtype,
47
    };
48
    my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } );
49
50
    my ( @patrons, @holds );
51
    for my $i ( 0 .. 2 ) {
52
        my $priority = $i + 1;
53
        my $patron   = $builder->build_object(
54
            {
55
                class => 'Koha::Patrons',
56
                value => { branchcode => $library->branchcode, }
57
            }
58
        );
59
        my $reserve_id = C4::Reserves::AddReserve(
60
            $library->branchcode, $patron->borrowernumber,
61
            $item->biblionumber,  '',
62
            $priority,            undef,
63
            undef,                '',
64
            "title for fee",      $item->itemnumber,
65
        );
66
        my $hold = Koha::Holds->find($reserve_id);
67
        push @patrons, $patron;
68
        push @holds,   $hold;
69
    }
70
71
    # There are 3 holds on this records
72
    my $nb_of_holds =
73
      Koha::Holds->search( { biblionumber => $item->biblionumber } )->count;
74
    is( $nb_of_holds, 3,
75
        'There should have 3 holds placed on this biblio record' );
76
    my $first_hold  = $holds[0];
77
    my $second_hold = $holds[1];
78
    my $third_hold  = $holds[2];
79
    is( ref($second_hold), 'Koha::Hold',
80
        'We should play with Koha::Hold objects' );
81
    is( $second_hold->priority, 2,
82
        'Second hold should have a priority set to 3' );
83
84
    # Remove the second hold, only 2 should still exist in DB and priorities must have been updated
85
    my $is_cancelled = $second_hold->cancel;
86
    is( ref($is_cancelled), 'Koha::Hold',
87
        'Koha::Hold->cancel should return the Koha::Hold (?)' )
88
      ;    # This is can reconsidered
89
    is( $second_hold->in_storage, 0,
90
        'The hold has been cancelled and does not longer exist in DB' );
91
    $nb_of_holds =
92
      Koha::Holds->search( { biblionumber => $item->biblionumber } )->count;
93
    is( $nb_of_holds, 2,
94
        'a hold has been cancelled, there should have only 2 holds placed on this biblio record'
95
    );
96
97
    # discard_changes to refetch
98
    is( $first_hold->discard_changes->priority, 1, 'First hold should still be first' );
99
    is( $third_hold->discard_changes->priority, 2, 'Third hold should now be second' );
100
101
    subtest 'charge_cancel_fee parameter' => sub {
102
        plan tests => 4;
103
        my $patron_category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { reservefee => 0 } } );
104
        my $patron = $builder->build_object({ class => 'Koha::Patrons', value => { categorycode => $patron_category->categorycode } });
105
        is( $patron->account->balance, 0, 'A new patron does not have any charges' );
106
107
        my @hold_info = (
108
            $library->branchcode, $patron->borrowernumber,
109
            $item->biblionumber,  '',
110
            1,                    undef,
111
            undef,                '',
112
            "title for fee",      $item->itemnumber,
113
        );
114
115
        # First, test cancelling a reserve when there's no charge configured.
116
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
117
        my $reserve_id = C4::Reserves::AddReserve( @hold_info );
118
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
119
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=0 - The patron should not have been charged' );
120
121
        # Then, test cancelling a reserve when there's no charge desired.
122
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
123
        $reserve_id = C4::Reserves::AddReserve( @hold_info );
124
        Koha::Holds->find( $reserve_id )->cancel(); # charge_cancel_fee => 0
125
        is( $patron->account->balance, 0, 'ExpireReservesMaxPickUpDelayCharge=42, but charge_cancel_fee => 0, The patron should not have been charged' );
126
127
128
        # Finally, test cancelling a reserve when there's a charge desired and configured.
129
        t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
130
        $reserve_id = C4::Reserves::AddReserve( @hold_info );
131
        Koha::Holds->find( $reserve_id )->cancel( { charge_cancel_fee => 1 } );
132
        is( int($patron->account->balance), 42, 'ExpireReservesMaxPickUpDelayCharge=42 and charge_cancel_fee => 1, The patron should have been charged!' );
133
    };
134
135
    subtest 'waiting hold' => sub {
136
        plan tests => 1;
137
        my $patron = $builder->build_object({ class => 'Koha::Patrons' });
138
        my $reserve_id = C4::Reserves::AddReserve(
139
            $library->branchcode, $patron->borrowernumber,
140
            $item->biblionumber,  '',
141
            1,                    undef,
142
            undef,                '',
143
            "title for fee",      $item->itemnumber,
144
            'W',
145
        );
146
        Koha::Holds->find( $reserve_id )->cancel;
147
        my $hold_old = Koha::Old::Holds->find( $reserve_id );
148
        is( $hold_old->found, 'W', 'The found column should have been kept and a hold is cancelled' );
149
    };
150
};
151
152
$schema->storage->txn_rollback;
153
154
1;
(-)a/t/db_dependent/Reserves.t (-87 / +1 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 67;
20
use Test::More tests => 58;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 321-331 $holds = $biblio->holds; Link Here
321
is($holds->count, 1, "Only one reserves for this biblio");
321
is($holds->count, 1, "Only one reserves for this biblio");
322
my $reserve_id = $holds->next->reserve_id;
322
my $reserve_id = $holds->next->reserve_id;
323
323
324
Koha::Holds->find( $reserve_id )->cancel;
325
326
my $hold = Koha::Holds->find( $reserve_id );
327
is($hold, undef, "Koha::Holds->cancel should have cancel the reserve");
328
329
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
324
# Tests for bug 9761 (ConfirmFutureHolds): new CheckReserves lookahead parameter, and corresponding change in AddReturn
330
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
325
# Note that CheckReserve uses its lookahead parameter and does not check ConfirmFutureHolds pref (it should be passed if needed like AddReturn does)
331
# Test 9761a: Add a reserve without date, CheckReserve should return it
326
# Test 9761a: Add a reserve without date, CheckReserve should return it
Lines 570-655 $dbh->do( Link Here
570
);
565
);
571
ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" );
566
ok( !C4::Reserves::OnShelfHoldsAllowed($item, $borrower), "OnShelfHoldsAllowed() disallowed" );
572
567
573
# Tests for bug 14464
574
575
$dbh->do("DELETE FROM reserves WHERE biblionumber=?",undef,($bibnum));
576
my $patron = Koha::Patrons->find( $borrowernumber );
577
my $bz14464_fines = $patron->account->balance;
578
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines at beginning' );
579
580
# First, test cancelling a reserve when there's no charge configured.
581
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 0);
582
583
my $bz14464_reserve = AddReserve(
584
    $branch_1,
585
    $borrowernumber,
586
    $bibnum,
587
    undef,
588
    '1',
589
    undef,
590
    undef,
591
    '',
592
    $title,
593
    $itemnumber,
594
    'W'
595
);
596
597
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
598
599
Koha::Holds->find( $bz14464_reserve )->cancel( { charge_cancel_fee => 1 } );
600
601
my $old_reserve = Koha::Database->new()->schema()->resultset('OldReserve')->find( $bz14464_reserve );
602
is($old_reserve->get_column('found'), 'W', 'Bug 14968 - Keep found column from reserve');
603
604
$bz14464_fines = $patron->account->balance;
605
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge configured' );
606
607
# Then, test cancelling a reserve when there's no charge desired.
608
t::lib::Mocks::mock_preference('ExpireReservesMaxPickUpDelayCharge', 42);
609
610
$bz14464_reserve = AddReserve(
611
    $branch_1,
612
    $borrowernumber,
613
    $bibnum,
614
    undef,
615
    '1',
616
    undef,
617
    undef,
618
    '',
619
    $title,
620
    $itemnumber,
621
    'W'
622
);
623
624
ok( $bz14464_reserve, 'Bug 14464 - 2nd reserve correctly created' );
625
626
Koha::Holds->find( $bz14464_reserve )->cancel();
627
628
$bz14464_fines = $patron->account->balance;
629
is( !$bz14464_fines || $bz14464_fines==0, 1, 'Bug 14464 - No fines after cancelling reserve with no charge desired' );
630
631
# Finally, test cancelling a reserve when there's a charge desired and configured.
632
$bz14464_reserve = AddReserve(
633
    $branch_1,
634
    $borrowernumber,
635
    $bibnum,
636
    undef,
637
    '1',
638
    undef,
639
    undef,
640
    '',
641
    $title,
642
    $itemnumber,
643
    'W'
644
);
645
646
ok( $bz14464_reserve, 'Bug 14464 - 1st reserve correctly created' );
647
648
Koha::Holds->find( $bz14464_reserve )->cancel( { charge_cancel_fee => 1 } );
649
650
$bz14464_fines = $patron->account->balance;
651
is( int( $bz14464_fines ), 42, 'Bug 14464 - Fine applied after cancelling reserve with charge desired and configured' );
652
653
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
568
# tests for MoveReserve in relation to ConfirmFutureHolds (BZ 14526)
654
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
569
#   hold from A pos 1, today, no fut holds: MoveReserve should fill it
655
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
570
$dbh->do('DELETE FROM reserves', undef, ($bibnum));
656
- 

Return to bug 19059