|
Lines 19-30
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 2; |
22 |
use Test::More tests => 4; |
| 23 |
use Test::Warn; |
23 |
use Test::Warn; |
| 24 |
|
24 |
|
| 25 |
use C4::Reserves; |
25 |
use C4::Reserves; |
| 26 |
use Koha::Holds; |
26 |
use Koha::AuthorisedValueCategory; |
| 27 |
use Koha::Database; |
27 |
use Koha::Database; |
|
|
28 |
use Koha::Holds; |
| 28 |
|
29 |
|
| 29 |
use t::lib::Mocks; |
30 |
use t::lib::Mocks; |
| 30 |
use t::lib::TestBuilder; |
31 |
use t::lib::TestBuilder; |
|
Lines 252-257
subtest 'cancel' => sub {
Link Here
|
| 252 |
|
253 |
|
| 253 |
}; |
254 |
}; |
| 254 |
|
255 |
|
|
|
256 |
subtest 'cancel with reason' => sub { |
| 257 |
plan tests => 7; |
| 258 |
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); |
| 259 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 260 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); |
| 261 |
my $item_info = { |
| 262 |
biblionumber => $biblioitem->biblionumber, |
| 263 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
| 264 |
homebranch => $library->branchcode, |
| 265 |
holdingbranch => $library->branchcode, |
| 266 |
itype => $itemtype->itemtype, |
| 267 |
}; |
| 268 |
my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } ); |
| 269 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 270 |
t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); |
| 271 |
|
| 272 |
my $patron = $builder->build_object( |
| 273 |
{ |
| 274 |
class => 'Koha::Patrons', |
| 275 |
value => { branchcode => $library->branchcode, } |
| 276 |
} |
| 277 |
); |
| 278 |
|
| 279 |
my $reserve_id = C4::Reserves::AddReserve( |
| 280 |
{ |
| 281 |
branchcode => $library->branchcode, |
| 282 |
borrowernumber => $patron->borrowernumber, |
| 283 |
biblionumber => $item->biblionumber, |
| 284 |
priority => 1, |
| 285 |
itemnumber => $item->itemnumber, |
| 286 |
} |
| 287 |
); |
| 288 |
|
| 289 |
my $hold = Koha::Holds->find($reserve_id); |
| 290 |
|
| 291 |
ok($reserve_id, "Hold created"); |
| 292 |
ok($hold, "Hold found"); |
| 293 |
|
| 294 |
my $av = Koha::AuthorisedValue->new( { category => 'HOLD_CANCELLATION', authorised_value => 'TEST_REASON' } )->store; |
| 295 |
Koha::Notice::Templates->search({ code => 'HOLD_CANCELLATION'})->delete(); |
| 296 |
my $notice = Koha::Notice::Template->new({ |
| 297 |
name => 'Hold cancellation', |
| 298 |
module => 'reserves', |
| 299 |
code => 'HOLD_CANCELLATION', |
| 300 |
title => 'Hold cancelled', |
| 301 |
content => 'Your hold was cancelled.', |
| 302 |
message_transport_type => 'email', |
| 303 |
branchcode => q{}, |
| 304 |
})->store(); |
| 305 |
|
| 306 |
$hold->cancel({cancellation_reason => 'TEST_REASON'}); |
| 307 |
|
| 308 |
$hold = Koha::Holds->find($reserve_id); |
| 309 |
is( $hold, undef, 'Hold is not in the reserves table'); |
| 310 |
$hold = Koha::Old::Holds->find($reserve_id); |
| 311 |
ok( $hold, 'Hold was found in the old reserves table'); |
| 312 |
|
| 313 |
my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'}); |
| 314 |
ok( $message, 'Found hold cancellation message'); |
| 315 |
is( $message->subject, 'Hold cancelled', 'Message has correct title' ); |
| 316 |
is( $message->content, 'Your hold was cancelled.', 'Message has correct content'); |
| 317 |
|
| 318 |
$notice->delete; |
| 319 |
$av->delete; |
| 320 |
$message->delete; |
| 321 |
}; |
| 322 |
|
| 323 |
subtest 'cancel all with reason' => sub { |
| 324 |
plan tests => 7; |
| 325 |
my $biblioitem = $builder->build_object( { class => 'Koha::Biblioitems' } ); |
| 326 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 327 |
my $itemtype = $builder->build_object( { class => 'Koha::ItemTypes', value => { rentalcharge => 0 } } ); |
| 328 |
my $item_info = { |
| 329 |
biblionumber => $biblioitem->biblionumber, |
| 330 |
biblioitemnumber => $biblioitem->biblioitemnumber, |
| 331 |
homebranch => $library->branchcode, |
| 332 |
holdingbranch => $library->branchcode, |
| 333 |
itype => $itemtype->itemtype, |
| 334 |
}; |
| 335 |
my $item = $builder->build_object( { class => 'Koha::Items', value => $item_info } ); |
| 336 |
my $manager = $builder->build_object( { class => "Koha::Patrons" } ); |
| 337 |
t::lib::Mocks::mock_userenv( { patron => $manager, branchcode => $manager->branchcode } ); |
| 338 |
|
| 339 |
my $patron = $builder->build_object( |
| 340 |
{ |
| 341 |
class => 'Koha::Patrons', |
| 342 |
value => { branchcode => $library->branchcode, } |
| 343 |
} |
| 344 |
); |
| 345 |
|
| 346 |
my $reserve_id = C4::Reserves::AddReserve( |
| 347 |
{ |
| 348 |
branchcode => $library->branchcode, |
| 349 |
borrowernumber => $patron->borrowernumber, |
| 350 |
biblionumber => $item->biblionumber, |
| 351 |
priority => 1, |
| 352 |
itemnumber => $item->itemnumber, |
| 353 |
} |
| 354 |
); |
| 355 |
|
| 356 |
my $hold = Koha::Holds->find($reserve_id); |
| 357 |
|
| 358 |
ok($reserve_id, "Hold created"); |
| 359 |
ok($hold, "Hold found"); |
| 360 |
|
| 361 |
my $av = Koha::AuthorisedValue->new( { category => 'HOLD_CANCELLATION', authorised_value => 'TEST_REASON' } )->store; |
| 362 |
Koha::Notice::Templates->search({ code => 'HOLD_CANCELLATION'})->delete(); |
| 363 |
my $notice = Koha::Notice::Template->new({ |
| 364 |
name => 'Hold cancellation', |
| 365 |
module => 'reserves', |
| 366 |
code => 'HOLD_CANCELLATION', |
| 367 |
title => 'Hold cancelled', |
| 368 |
content => 'Your hold was cancelled.', |
| 369 |
message_transport_type => 'email', |
| 370 |
branchcode => q{}, |
| 371 |
})->store(); |
| 372 |
|
| 373 |
ModReserveCancelAll($item->id, $patron->id, 'TEST_REASON'); |
| 374 |
|
| 375 |
$hold = Koha::Holds->find($reserve_id); |
| 376 |
is( $hold, undef, 'Hold is not in the reserves table'); |
| 377 |
$hold = Koha::Old::Holds->find($reserve_id); |
| 378 |
ok( $hold, 'Hold was found in the old reserves table'); |
| 379 |
|
| 380 |
my $message = Koha::Notice::Messages->find({ borrowernumber => $patron->id, letter_code => 'HOLD_CANCELLATION'}); |
| 381 |
ok( $message, 'Found hold cancellation message'); |
| 382 |
is( $message->subject, 'Hold cancelled', 'Message has correct title' ); |
| 383 |
is( $message->content, 'Your hold was cancelled.', 'Message has correct content'); |
| 384 |
|
| 385 |
$av->delete; |
| 386 |
$message->delete; |
| 387 |
}; |
| 388 |
|
| 255 |
$schema->storage->txn_rollback; |
389 |
$schema->storage->txn_rollback; |
| 256 |
|
390 |
|
| 257 |
1; |
391 |
1; |
| 258 |
- |
|
|