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 460-466
subtest 'store() tests' => sub {
Link Here
|
460 |
}; |
460 |
}; |
461 |
|
461 |
|
462 |
subtest 'delete() tests' => sub { |
462 |
subtest 'delete() tests' => sub { |
463 |
plan tests => 3; |
463 |
plan tests => 2; |
464 |
|
464 |
|
465 |
$schema->storage->txn_begin; |
465 |
$schema->storage->txn_begin; |
466 |
|
466 |
|
Lines 500-505
subtest 'delete() tests' => sub {
Link Here
|
500 |
'Koha::Booking->delete should have deleted the booking' |
500 |
'Koha::Booking->delete should have deleted the booking' |
501 |
); |
501 |
); |
502 |
|
502 |
|
|
|
503 |
$schema->storage->txn_rollback; |
504 |
}; |
505 |
|
506 |
subtest 'edit() tests' => sub { |
507 |
plan tests => 1; |
508 |
|
509 |
$schema->storage->txn_begin; |
510 |
|
511 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
512 |
my $biblio = $builder->build_sample_biblio; |
513 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
514 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
515 |
my $end_0 = $start_0->clone->add( days => 6 ); |
516 |
|
517 |
$item_1->bookable(1)->store; |
518 |
|
519 |
my $booking = Koha::Booking->new( |
520 |
{ |
521 |
patron_id => $patron->borrowernumber, |
522 |
biblio_id => $biblio->biblionumber, |
523 |
item_id => $item_1->itemnumber, |
524 |
pickup_library_id => $item_1->homebranch, |
525 |
start_date => $start_0, |
526 |
end_date => $end_0, |
527 |
} |
528 |
)->store; |
529 |
|
530 |
my $booking_to_edit = Koha::Bookings->find( $booking->booking_id ); |
531 |
$booking_to_edit->edit( { status => 'completed' } ); |
532 |
|
533 |
is( |
534 |
$booking_to_edit->unblessed->{status}, 'completed', |
535 |
'Koha::Booking->edit should edit booking with passed params' |
536 |
); |
537 |
|
538 |
$schema->storage->txn_rollback; |
539 |
}; |
540 |
|
541 |
subtest 'cancel() tests' => sub { |
542 |
plan tests => 1; |
543 |
|
544 |
$schema->storage->txn_begin; |
545 |
|
546 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
547 |
my $biblio = $builder->build_sample_biblio; |
548 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
549 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
550 |
my $end_0 = $start_0->clone->add( days => 6 ); |
551 |
my $original_notices_count = Koha::Notice::Messages->search( |
552 |
{ |
553 |
letter_code => 'BOOKING_CANCELLATION', |
554 |
borrowernumber => $patron->borrowernumber, |
555 |
} |
556 |
)->count; |
557 |
|
558 |
$item_1->bookable(1)->store; |
559 |
|
560 |
my $booking = Koha::Booking->new( |
561 |
{ |
562 |
patron_id => $patron->borrowernumber, |
563 |
biblio_id => $biblio->biblionumber, |
564 |
item_id => $item_1->itemnumber, |
565 |
pickup_library_id => $item_1->homebranch, |
566 |
start_date => $start_0, |
567 |
end_date => $end_0, |
568 |
} |
569 |
)->store; |
570 |
|
571 |
my $booking_to_cancel = Koha::Bookings->find( $booking->booking_id ); |
572 |
$booking_to_cancel->cancel( { send_letter => 1 } ); |
573 |
|
503 |
subtest 'notice trigger' => sub { |
574 |
subtest 'notice trigger' => sub { |
504 |
plan tests => 1; |
575 |
plan tests => 1; |
505 |
|
576 |
|
Lines 512-520
subtest 'delete() tests' => sub {
Link Here
|
512 |
is( |
583 |
is( |
513 |
$post_notices_count, |
584 |
$post_notices_count, |
514 |
$original_notices_count + 1, |
585 |
$original_notices_count + 1, |
515 |
'Koha::Booking->delete should have enqueued a BOOKING_CANCELLATION email' |
586 |
'Koha::Booking->cancel should have enqueued a BOOKING_CANCELLATION email' |
516 |
); |
587 |
); |
517 |
}; |
588 |
}; |
518 |
|
589 |
|
519 |
$schema->storage->txn_rollback; |
590 |
$schema->storage->txn_rollback; |
520 |
}; |
591 |
}; |
|
|
592 |
|
593 |
subtest 'set_status() tests' => sub { |
594 |
plan tests => 3; |
595 |
|
596 |
$schema->storage->txn_begin; |
597 |
|
598 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
599 |
my $biblio = $builder->build_sample_biblio; |
600 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
601 |
my $start_0 = dt_from_string->subtract( days => 2 )->truncate( to => 'day' ); |
602 |
my $end_0 = $start_0->clone->add( days => 6 ); |
603 |
|
604 |
$item_1->bookable(1)->store; |
605 |
|
606 |
my $booking = Koha::Booking->new( |
607 |
{ |
608 |
patron_id => $patron->borrowernumber, |
609 |
biblio_id => $biblio->biblionumber, |
610 |
item_id => $item_1->itemnumber, |
611 |
pickup_library_id => $item_1->homebranch, |
612 |
start_date => $start_0, |
613 |
end_date => $end_0, |
614 |
status => 'new', |
615 |
} |
616 |
)->store; |
617 |
|
618 |
my $booking_with_old_status = Koha::Bookings->find( $booking->booking_id ); |
619 |
$booking_with_old_status->set_status('completed'); |
620 |
is( $booking_with_old_status->unblessed->{status}, 'completed', 'Booking status is now "completed"' ); |
621 |
|
622 |
$booking_with_old_status->set_status('cancelled'); |
623 |
is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is now "cancelled"' ); |
624 |
|
625 |
subtest 'unauthorized status' => sub { |
626 |
plan tests => 2; |
627 |
|
628 |
eval { $booking_with_old_status->set_status('blah'); }; |
629 |
|
630 |
if ($@) { |
631 |
like( |
632 |
$@, qr/Invalid status: blah/, |
633 |
'An error is raised for unauthorized status' |
634 |
); |
635 |
} else { |
636 |
fail('Expected an error but none was raised'); |
637 |
} |
638 |
|
639 |
# Status unchanged |
640 |
is( $booking_with_old_status->unblessed->{status}, 'cancelled', 'Booking status is still "cancelled"' ); |
641 |
}; |
642 |
|
643 |
$schema->storage->txn_rollback; |
644 |
}; |