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

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

Return to bug 15561