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

(-)a/t/db_dependent/Holds/CancelAll.t (-1 / +122 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
5
use t::lib::Mocks;
6
use t::lib::TestBuilder;
7
8
use Test::More tests => 7;
9
10
use MARC::Record;
11
12
use C4::Context;
13
use C4::Biblio;
14
use C4::Items;
15
use C4::Members;
16
use Koha::Database;
17
use Koha::Holds;
18
use Koha::Account::Lines;
19
20
BEGIN {
21
    use FindBin;
22
    use lib $FindBin::Bin;
23
    use_ok('C4::Reserves');
24
}
25
26
my $schema = Koha::Database->new->schema;
27
$schema->storage->txn_begin;
28
29
my $builder = t::lib::TestBuilder->new();
30
my $dbh     = C4::Context->dbh;
31
32
# Create two random branchcodees
33
my $category   = $builder->build( { source => 'Category' } );
34
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode};
35
36
my $borrowers_count = 2;
37
38
my ( $biblionumber, $title, $biblioitemnumber ) = create_helper_biblio('DUMMY');
39
40
C4::Context->set_preference( 'ExpireReservesMaxPickUpDelayCharge', '5.00' );
41
42
my ( undef, undef, $itemnumber ) = AddItem(
43
    {
44
        homebranchcode    => $branchcode,
45
        holdingbranchcode => $branchcode
46
    },
47
    $biblionumber
48
);
49
50
my $borrowernumber = AddMember(
51
    firstname    => 'my firstname',
52
    surname      => 'my surname ' . $_,
53
    categorycode => $category->{categorycode},
54
    branchcode   => $branchcode,
55
);
56
57
my $id = AddReserve(
58
    $branchcode,
59
    $borrowernumber,
60
    $biblionumber,
61
    my $bibitems = q{},
62
    my $priority = C4::Reserves::CalculatePriority($biblionumber),
63
    my $resdate,
64
    my $expdate,
65
    my $notes = q{},
66
    $title,
67
    my $checkitem = $itemnumber,
68
    my $found,
69
);
70
71
my $hold = Koha::Holds->find($id);
72
is( $hold->id, $id, 'Hold created correctly.' );
73
74
$dbh->do("DELETE FROM accountlines");
75
76
# Cancel with no cancelation fee
77
ModReserveCancelAll( $itemnumber, $borrowernumber );
78
79
$hold = Koha::Holds->find( $id );
80
is( $hold, undef, 'Hold canceled correctly' );
81
82
my $accountlines =
83
  Koha::Account::Lines->search( { borrowernumber => $borrowernumber } );
84
is( $accountlines->count(), 0, "No charge created for cancelation" );
85
86
$id = AddReserve(
87
    $branchcode,
88
    $borrowernumber,
89
    $biblionumber,
90
    $bibitems = q{},
91
    $priority = C4::Reserves::CalculatePriority($biblionumber),
92
    $resdate,
93
    $expdate,
94
    $notes = q{},
95
    $title,
96
    $checkitem = $itemnumber,
97
    $found,
98
);
99
100
# Cancel with cancelation fee
101
ModReserveCancelAll( $itemnumber, $borrowernumber, 1 );
102
103
$hold = Koha::Holds->find( $id );
104
is( $hold, undef, 'Hold canceled correctly' );
105
106
$accountlines =
107
  Koha::Account::Lines->search( { borrowernumber => $borrowernumber } );
108
is( $accountlines->count(), 1, "Found charge for cancelation" );
109
is( $accountlines->as_list->[0]->amountoutstanding, '5.000000', 'Charge is equal to ExpireReservesMaxPickUpDelayCharge' );
110
111
# Helper method to set up a Biblio.
112
sub create_helper_biblio {
113
    my $itemtype = shift;
114
    my $bib      = MARC::Record->new();
115
    my $title    = 'Silence in the library';
116
    $bib->append_fields(
117
        MARC::Field->new( '100', ' ', ' ', a => 'Moffat, Steven' ),
118
        MARC::Field->new( '245', ' ', ' ', a => $title ),
119
        MARC::Field->new( '942', ' ', ' ', c => $itemtype ),
120
    );
121
    return ( $biblionumber, $title, $biblioitemnumber ) = AddBiblio( $bib, '' );
122
}

Return to bug 15561