Lines 16-26
Link Here
|
16 |
|
16 |
|
17 |
use Modern::Perl; |
17 |
use Modern::Perl; |
18 |
|
18 |
|
19 |
use Test::More tests => 33; |
19 |
use Test::More tests => 43; |
20 |
use Test::NoWarnings; |
20 |
use Test::NoWarnings; |
21 |
|
21 |
|
22 |
use Test::MockModule; |
22 |
use Test::MockModule; |
23 |
use Test::Warn; |
23 |
use Test::Warn; |
|
|
24 |
use Try::Tiny; |
24 |
|
25 |
|
25 |
use IPC::Cmd qw(can_run); |
26 |
use IPC::Cmd qw(can_run); |
26 |
use MARC::Record; |
27 |
use MARC::Record; |
Lines 32-37
use C4::Context;
Link Here
|
32 |
use Koha::Patrons; |
33 |
use Koha::Patrons; |
33 |
use Koha::Patron::Discharge; |
34 |
use Koha::Patron::Discharge; |
34 |
use Koha::Database; |
35 |
use Koha::Database; |
|
|
36 |
use Koha::DateUtils qw( dt_from_string ); |
35 |
|
37 |
|
36 |
use t::lib::TestBuilder; |
38 |
use t::lib::TestBuilder; |
37 |
use t::lib::Mocks; |
39 |
use t::lib::Mocks; |
Lines 170-182
is(
Link Here
|
170 |
scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, |
172 |
scalar( Koha::Patron::Discharge::get_validated( { branchcode => $library->{branchcode} } ) ), 2, |
171 |
'There is 2 validated discharges for a given branchcode' |
173 |
'There is 2 validated discharges for a given branchcode' |
172 |
); # This is not used in the code yet |
174 |
); # This is not used in the code yet |
173 |
Koha::Patron::Debarments::DelUniqueDebarment( { 'borrowernumber' => $patron->borrowernumber, 'type' => 'DISCHARGE' } ); |
175 |
|
|
|
176 |
my $discharge = Koha::Patron::Discharge::get_validated( |
177 |
{ |
178 |
branchcode => $library->{branchcode}, |
179 |
borrowernumber => $patron->borrowernumber, |
180 |
} |
181 |
)->single; |
182 |
|
183 |
Koha::Patron::Discharge::cancel( |
184 |
{ |
185 |
discharge_id => $discharge->discharge_id, |
186 |
cancellation_reason => 'PATRON_MISTAKE', |
187 |
} |
188 |
); |
189 |
|
190 |
$discharge = Koha::Patron::Discharge::get_validated( |
191 |
{ |
192 |
branchcode => $library->{branchcode}, |
193 |
borrowernumber => $patron->borrowernumber, |
194 |
} |
195 |
)->single; |
196 |
|
197 |
Koha::Patron::Discharge::cancel( |
198 |
{ |
199 |
borrowernumber => $patron2->borrowernumber, |
200 |
cancellation_reason => 'PATRON_MISTAKE', |
201 |
} |
202 |
); |
203 |
|
204 |
my $discharge2 = Koha::Patron::Discharge::get_validated( |
205 |
{ |
206 |
branchcode => $library->{branchcode}, |
207 |
borrowernumber => $patron2->borrowernumber, |
208 |
} |
209 |
)->single; |
210 |
|
174 |
ok( !Koha::Patrons->find( $patron->borrowernumber )->is_debarred, 'The debarment has been lifted' ); |
211 |
ok( !Koha::Patrons->find( $patron->borrowernumber )->is_debarred, 'The debarment has been lifted' ); |
175 |
ok( |
212 |
ok( |
176 |
!Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), |
213 |
!Koha::Patron::Discharge::is_discharged( { borrowernumber => $patron->borrowernumber } ), |
177 |
'The patron is not discharged after the restriction has been lifted' |
214 |
'The patron is not discharged after the discharge has been cancelled' |
|
|
215 |
); |
216 |
|
217 |
ok( |
218 |
Koha::Patron::Discharge::is_cancelled( { discharge_id => $discharge->discharge_id } ), |
219 |
'The discharge is marked as cancelled after the discharge has been cancelled using dischargeid' |
220 |
); |
221 |
|
222 |
ok( |
223 |
Koha::Patron::Discharge::is_cancelled( { discharge_id => $discharge2->discharge_id } ), |
224 |
'The discharge is marked as cancelled after the discharge has been cancelled using borrowernumber' |
225 |
); |
226 |
|
227 |
is( |
228 |
$discharge->cancellation_reason, |
229 |
'PATRON_MISTAKE', |
230 |
'The cancellation reason is properly set using discharge_id' |
178 |
); |
231 |
); |
179 |
|
232 |
|
|
|
233 |
is( |
234 |
dt_from_string( $discharge->cancelled )->ymd, |
235 |
dt_from_string->ymd, |
236 |
'The cancellation date is properly set using discharge_id' |
237 |
); |
238 |
|
239 |
is( |
240 |
$discharge2->cancellation_reason, |
241 |
'PATRON_MISTAKE', |
242 |
'The cancellation reason is properly set using borrowernumber' |
243 |
); |
244 |
|
245 |
is( |
246 |
dt_from_string( $discharge2->cancelled )->ymd, |
247 |
dt_from_string->ymd, |
248 |
'The cancellation date is properly set using borrowernumber' |
249 |
); |
250 |
|
251 |
try { |
252 |
Koha::Patron::Discharge::cancel( |
253 |
{ |
254 |
cancellation_reason => 'PATRON_MISTAKE', |
255 |
} |
256 |
); |
257 |
ok( 0, 'Cancel must be called with one parameter' ); |
258 |
} catch { |
259 |
ok( $_->isa('Koha::Exceptions::BadParameter'), "Cancel must be called with one parameter" ); |
260 |
}; |
261 |
|
262 |
try { |
263 |
Koha::Patron::Discharge::cancel( |
264 |
{ |
265 |
discharge_id => $discharge->discharge_id, |
266 |
borrowernumber => $patron2->borrowernumber, |
267 |
} |
268 |
); |
269 |
ok( 0, 'Discharge and borrowernumber, if both provided, must fit' ); |
270 |
} catch { |
271 |
ok( $_->isa('Koha::Exceptions::BadParameter'), "Discharge and borrowernumber, if both provided, must fit" ); |
272 |
}; |
273 |
|
274 |
try { |
275 |
Koha::Patron::Discharge::is_cancelled( {} ); |
276 |
ok( 0, 'There must be a discharge_id in parameters to is_cancelled' ); |
277 |
} catch { |
278 |
ok( $_->isa('Koha::Exceptions::BadParameter'), "There must be a discharge_id in parameters to is_cancelled" ); |
279 |
}; |
280 |
|
281 |
try { |
282 |
Koha::Patron::Discharge::is_cancelled( |
283 |
{ |
284 |
discharge_id => -1, |
285 |
} |
286 |
); |
287 |
ok( 0, 'Discharge called in is_cancelled must exist' ); |
288 |
} catch { |
289 |
ok( $_->isa('Koha::Exceptions::BadParameter'), "Discharge called in is_cancelled must exist" ); |
290 |
}; |
291 |
|
180 |
# Verify that the discharge works multiple times |
292 |
# Verify that the discharge works multiple times |
181 |
Koha::Patron::Discharge::request( { borrowernumber => $patron->borrowernumber } ); |
293 |
Koha::Patron::Discharge::request( { borrowernumber => $patron->borrowernumber } ); |
182 |
is( scalar(Koha::Patron::Discharge::get_pendings), 1, 'There is a pending discharge request (second time)' ); |
294 |
is( scalar(Koha::Patron::Discharge::get_pendings), 1, 'There is a pending discharge request (second time)' ); |
183 |
- |
|
|