Lines 19-36
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 3; |
22 |
use Test::More tests => 4; |
23 |
|
23 |
|
24 |
use Test::Exception; |
24 |
use Test::Exception; |
25 |
use Test::MockModule; |
25 |
use Test::MockModule; |
26 |
|
26 |
|
27 |
use t::lib::TestBuilder; |
27 |
use t::lib::TestBuilder; |
28 |
|
28 |
|
|
|
29 |
use Koha::ActionLogs; |
30 |
use Koha::Holds; |
29 |
use Koha::Libraries; |
31 |
use Koha::Libraries; |
30 |
|
32 |
|
31 |
my $schema = Koha::Database->new->schema; |
33 |
my $schema = Koha::Database->new->schema; |
32 |
my $builder = t::lib::TestBuilder->new; |
34 |
my $builder = t::lib::TestBuilder->new; |
33 |
|
35 |
|
|
|
36 |
subtest 'fill() tests' => sub { |
37 |
|
38 |
plan tests => 11; |
39 |
|
40 |
$schema->storage->txn_begin; |
41 |
|
42 |
my $fee = 15; |
43 |
|
44 |
my $category = $builder->build_object( |
45 |
{ |
46 |
class => 'Koha::Patron::Categories', |
47 |
value => { reservefee => $fee } |
48 |
} |
49 |
); |
50 |
my $patron = $builder->build_object( |
51 |
{ |
52 |
class => 'Koha::Patrons', |
53 |
value => { categorycode => $category->id } |
54 |
} |
55 |
); |
56 |
my $manager = $builder->build_object( { class => 'Koha::Patrons' } ); |
57 |
|
58 |
my $title = 'Do what you want'; |
59 |
my $biblio = $builder->build_sample_biblio( { title => $title } ); |
60 |
my $item = $builder->build_sample_item( { biblionumber => $biblio->id } ); |
61 |
my $hold = $builder->build_object( |
62 |
{ |
63 |
class => 'Koha::Holds', |
64 |
value => { |
65 |
biblionumber => $biblio->id, |
66 |
borrowernumber => $patron->id, |
67 |
itemnumber => $item->id, |
68 |
priority => 10, |
69 |
} |
70 |
} |
71 |
); |
72 |
|
73 |
t::lib::Mocks::mock_preference( 'HoldFeeMode', 'any_time_is_collected' ); |
74 |
t::lib::Mocks::mock_preference( 'HoldsLog', 1 ); |
75 |
t::lib::Mocks::mock_userenv( |
76 |
{ patron => $manager, branchcode => $manager->branchcode } ); |
77 |
|
78 |
my $interface = 'api'; |
79 |
C4::Context->interface($interface); |
80 |
|
81 |
my $ret = $hold->fill; |
82 |
|
83 |
is( ref($ret), 'Koha::Hold', '->fill returns the object type' ); |
84 |
is( $ret->id, $hold->id, '->fill returns the object' ); |
85 |
|
86 |
is( Koha::Holds->find($hold->id), undef, 'Hold no longer current' ); |
87 |
my $old_hold = Koha::Old::Holds->find( $hold->id ); |
88 |
|
89 |
is( $old_hold->id, $hold->id, 'reserve_id retained' ); |
90 |
is( $old_hold->priority, 0, 'priority set to 0' ); |
91 |
is( $old_hold->found, 'F', 'found set to F' ); |
92 |
|
93 |
subtest 'fee applied tests' => sub { |
94 |
|
95 |
plan tests => 9; |
96 |
|
97 |
my $account = $patron->account; |
98 |
is( $account->balance, $fee, 'Charge applied correctly' ); |
99 |
|
100 |
my $debits = $account->outstanding_debits; |
101 |
is( $debits->count, 1, 'Only one fee charged' ); |
102 |
|
103 |
my $fee_debit = $debits->next; |
104 |
is( $fee_debit->amount * 1, $fee, 'Fee amount stored correctly' ); |
105 |
is( $fee_debit->description, $title, |
106 |
'Fee description stored correctly' ); |
107 |
is( $fee_debit->manager_id, $manager->id, |
108 |
'Fee manager_id stored correctly' ); |
109 |
is( $fee_debit->branchcode, $manager->branchcode, |
110 |
'Fee branchcode stored correctly' ); |
111 |
is( $fee_debit->interface, $interface, |
112 |
'Fee interface stored correctly' ); |
113 |
is( $fee_debit->debit_type_code, |
114 |
'RESERVE', 'Fee debit_type_code stored correctly' ); |
115 |
is( $fee_debit->itemnumber, $item->id, |
116 |
'Fee itemnumber stored correctly' ); |
117 |
}; |
118 |
|
119 |
my $logs = Koha::ActionLogs->search( |
120 |
{ |
121 |
action => 'FILL', |
122 |
module => 'HOLDS', |
123 |
object => $hold->id |
124 |
} |
125 |
); |
126 |
|
127 |
is( $logs->count, 1, '1 log line added' ); |
128 |
|
129 |
# Set HoldFeeMode to something other than any_time_is_collected |
130 |
t::lib::Mocks::mock_preference( 'HoldFeeMode', 'not_always' ); |
131 |
# Disable logging |
132 |
t::lib::Mocks::mock_preference( 'HoldsLog', 0 ); |
133 |
|
134 |
$hold = $builder->build_object( |
135 |
{ |
136 |
class => 'Koha::Holds', |
137 |
value => { |
138 |
biblionumber => $biblio->id, |
139 |
borrowernumber => $patron->id, |
140 |
itemnumber => $item->id, |
141 |
priority => 10, |
142 |
} |
143 |
} |
144 |
); |
145 |
|
146 |
$hold->fill; |
147 |
|
148 |
my $account = $patron->account; |
149 |
is( $account->balance, $fee, 'No new charge applied' ); |
150 |
|
151 |
my $debits = $account->outstanding_debits; |
152 |
is( $debits->count, 1, 'Only one fee charged, because of HoldFeeMode' ); |
153 |
|
154 |
$logs = Koha::ActionLogs->search( |
155 |
{ |
156 |
action => 'FILL', |
157 |
module => 'HOLDS', |
158 |
object => $hold->id |
159 |
} |
160 |
); |
161 |
|
162 |
is( $logs->count, 0, 'HoldsLog disabled, no logs added' ); |
163 |
|
164 |
$schema->storage->txn_rollback; |
165 |
}; |
166 |
|
34 |
subtest 'patron() tests' => sub { |
167 |
subtest 'patron() tests' => sub { |
35 |
|
168 |
|
36 |
plan tests => 2; |
169 |
plan tests => 2; |
37 |
- |
|
|