|
Lines 20-26
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
use utf8; |
21 |
use utf8; |
| 22 |
|
22 |
|
| 23 |
use Test::More tests => 3; |
23 |
use Test::More tests => 6; |
| 24 |
|
24 |
|
| 25 |
use Test::Exception; |
25 |
use Test::Exception; |
| 26 |
|
26 |
|
|
Lines 326-332
subtest 'store() tests' => sub {
Link Here
|
| 326 |
}; |
326 |
}; |
| 327 |
|
327 |
|
| 328 |
subtest 'delete() tests' => sub { |
328 |
subtest 'delete() tests' => sub { |
| 329 |
plan tests => 3; |
329 |
plan tests => 2; |
| 330 |
|
330 |
|
| 331 |
$schema->storage->txn_begin; |
331 |
$schema->storage->txn_begin; |
| 332 |
|
332 |
|
|
Lines 365-370
subtest 'delete() tests' => sub {
Link Here
|
| 365 |
'Koha::Booking->delete should have deleted the booking' |
365 |
'Koha::Booking->delete should have deleted the booking' |
| 366 |
); |
366 |
); |
| 367 |
|
367 |
|
|
|
368 |
$schema->storage->txn_rollback; |
| 369 |
}; |
| 370 |
|
| 371 |
subtest 'edit() tests' => sub { |
| 372 |
plan tests => 1; |
| 373 |
|
| 374 |
$schema->storage->txn_begin; |
| 375 |
|
| 376 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 377 |
my $biblio = $builder->build_sample_biblio; |
| 378 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 379 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
| 380 |
my $end_0 = $start_0->clone->add( days => 6 ); |
| 381 |
|
| 382 |
$item_1->bookable(1)->store; |
| 383 |
|
| 384 |
my $booking = Koha::Booking->new( |
| 385 |
{ |
| 386 |
patron_id => $patron->borrowernumber, |
| 387 |
biblio_id => $biblio->biblionumber, |
| 388 |
item_id => $item_1->itemnumber, |
| 389 |
pickup_library_id => $item_1->homebranch, |
| 390 |
start_date => $start_0, |
| 391 |
end_date => $end_0, |
| 392 |
} |
| 393 |
)->store; |
| 394 |
|
| 395 |
my $booking_to_edit = Koha::Bookings->find( $booking->booking_id ); |
| 396 |
$booking_to_edit->edit( { status => 'completed' } ); |
| 397 |
|
| 398 |
is( |
| 399 |
$booking_to_edit->unblessed->{status}, 'completed', |
| 400 |
'Koha::Booking->edit should edit booking with passed params' |
| 401 |
); |
| 402 |
|
| 403 |
$schema->storage->txn_rollback; |
| 404 |
}; |
| 405 |
|
| 406 |
subtest 'cancel() tests' => sub { |
| 407 |
plan tests => 1; |
| 408 |
|
| 409 |
$schema->storage->txn_begin; |
| 410 |
|
| 411 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 412 |
my $biblio = $builder->build_sample_biblio; |
| 413 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 414 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
| 415 |
my $end_0 = $start_0->clone->add( days => 6 ); |
| 416 |
my $original_notices_count = Koha::Notice::Messages->search( |
| 417 |
{ |
| 418 |
letter_code => 'BOOKING_CANCELLATION', |
| 419 |
borrowernumber => $patron->borrowernumber, |
| 420 |
} |
| 421 |
)->count; |
| 422 |
|
| 423 |
$item_1->bookable(1)->store; |
| 424 |
|
| 425 |
my $booking = Koha::Booking->new( |
| 426 |
{ |
| 427 |
patron_id => $patron->borrowernumber, |
| 428 |
biblio_id => $biblio->biblionumber, |
| 429 |
item_id => $item_1->itemnumber, |
| 430 |
pickup_library_id => $item_1->homebranch, |
| 431 |
start_date => $start_0, |
| 432 |
end_date => $end_0, |
| 433 |
} |
| 434 |
)->store; |
| 435 |
|
| 436 |
my $booking_to_cancel = Koha::Bookings->find( $booking->booking_id ); |
| 437 |
$booking_to_cancel->cancel( { send_letter => 1 } ); |
| 438 |
|
| 368 |
subtest 'notice trigger' => sub { |
439 |
subtest 'notice trigger' => sub { |
| 369 |
plan tests => 1; |
440 |
plan tests => 1; |
| 370 |
|
441 |
|
|
Lines 377-385
subtest 'delete() tests' => sub {
Link Here
|
| 377 |
is( |
448 |
is( |
| 378 |
$post_notices_count, |
449 |
$post_notices_count, |
| 379 |
$original_notices_count + 1, |
450 |
$original_notices_count + 1, |
| 380 |
'Koha::Booking->delete should have enqueued a BOOKING_CANCELLATION email' |
451 |
'Koha::Booking->cancel should have enqueued a BOOKING_CANCELLATION email' |
| 381 |
); |
452 |
); |
| 382 |
}; |
453 |
}; |
| 383 |
|
454 |
|
| 384 |
$schema->storage->txn_rollback; |
455 |
$schema->storage->txn_rollback; |
| 385 |
}; |
456 |
}; |
|
|
457 |
|
| 458 |
subtest 'set_status() tests' => sub { |
| 459 |
plan tests => 3; |
| 460 |
|
| 461 |
$schema->storage->txn_begin; |
| 462 |
|
| 463 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 464 |
my $biblio = $builder->build_sample_biblio; |
| 465 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 466 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
| 467 |
my $end_0 = $start_0->clone->add( days => 6 ); |
| 468 |
|
| 469 |
$item_1->bookable(1)->store; |
| 470 |
|
| 471 |
my $booking = Koha::Booking->new( |
| 472 |
{ |
| 473 |
patron_id => $patron->borrowernumber, |
| 474 |
biblio_id => $biblio->biblionumber, |
| 475 |
item_id => $item_1->itemnumber, |
| 476 |
pickup_library_id => $item_1->homebranch, |
| 477 |
start_date => $start_0, |
| 478 |
end_date => $end_0, |
| 479 |
status => 'new', |
| 480 |
} |
| 481 |
)->store; |
| 482 |
|
| 483 |
my $booking_with_old_status = Koha::Bookings->find( $booking->booking_id ); |
| 484 |
$booking_with_old_status->set_status('completed'); |
| 485 |
is( $booking_with_old_status->unblessed->{status}, 'completed', 'Booking status is now "completed"' ); |
| 486 |
|
| 487 |
$booking_with_old_status->set_status('cancelled'); |
| 488 |
is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is now "cancelled"' ); |
| 489 |
|
| 490 |
subtest 'unauthorized status' => sub { |
| 491 |
plan tests => 2; |
| 492 |
|
| 493 |
eval { $booking_with_old_status->set_status('blah'); }; |
| 494 |
|
| 495 |
if ($@) { |
| 496 |
like( |
| 497 |
$@, qr/Invalid status: blah/, |
| 498 |
'An error is raised for unauthorized status' |
| 499 |
); |
| 500 |
} else { |
| 501 |
fail('Expected an error but none was raised'); |
| 502 |
} |
| 503 |
|
| 504 |
# Status unchanged |
| 505 |
is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is still "cancelled"' ); |
| 506 |
}; |
| 507 |
|
| 508 |
$schema->storage->txn_rollback; |
| 509 |
}; |