Lines 592-601
subtest 'filter_by_current & filter_by_cancelled' => sub {
Link Here
|
592 |
|
592 |
|
593 |
subtest 'cancel() tests' => sub { |
593 |
subtest 'cancel() tests' => sub { |
594 |
|
594 |
|
595 |
plan tests => 32; |
595 |
plan tests => 38; |
596 |
|
596 |
|
597 |
$schema->storage->txn_begin; |
597 |
$schema->storage->txn_begin; |
598 |
|
598 |
|
|
|
599 |
my $reason = 'Some reason'; |
600 |
|
599 |
# Scenario: |
601 |
# Scenario: |
600 |
# * order with one item attached |
602 |
# * order with one item attached |
601 |
# * the item is on loan |
603 |
# * the item is on loan |
Lines 627-640
subtest 'cancel() tests' => sub {
Link Here
|
627 |
# Add a checkout so cancelling fails because od 'book_on_loan' |
629 |
# Add a checkout so cancelling fails because od 'book_on_loan' |
628 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
630 |
C4::Circulation::AddIssue( $patron->unblessed, $item->barcode ); |
629 |
|
631 |
|
630 |
my $result = $order->cancel({ reason => 'Some reason' }); |
632 |
my $result = $order->cancel({ reason => $reason }); |
631 |
# refresh the order object |
633 |
# refresh the order object |
632 |
$order->discard_changes; |
634 |
$order->discard_changes; |
633 |
|
635 |
|
634 |
is( $result, $order, 'self is returned' ); |
636 |
is( $result, $order, 'self is returned' ); |
635 |
is( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' ); |
637 |
is( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' ); |
636 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is not undef' ); |
638 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is not undef' ); |
637 |
is( $order->cancellationreason, 'Some reason', 'cancellationreason is set' ); |
639 |
is( $order->cancellationreason, $reason, 'cancellationreason is set' ); |
638 |
is( ref(Koha::Items->find($item->id)), 'Koha::Item', 'The item is present' ); |
640 |
is( ref(Koha::Items->find($item->id)), 'Koha::Item', 'The item is present' ); |
639 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' ); |
641 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' ); |
640 |
my @messages = @{ $order->messages }; |
642 |
my @messages = @{ $order->messages }; |
Lines 651-662
subtest 'cancel() tests' => sub {
Link Here
|
651 |
C4::Circulation::AddReturn( $item->barcode ); |
653 |
C4::Circulation::AddReturn( $item->barcode ); |
652 |
|
654 |
|
653 |
$order->reset_messages; |
655 |
$order->reset_messages; |
654 |
$order->cancel({ reason => 'Some reason' }) |
656 |
$order->cancel({ reason => $reason }) |
655 |
->discard_changes; |
657 |
->discard_changes; |
656 |
|
658 |
|
657 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
659 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
658 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
660 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
659 |
is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); |
661 |
is( $order->cancellationreason, $reason, 'cancellationreason is undef' ); |
660 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
662 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
661 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' ); |
663 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is present' ); |
662 |
@messages = @{ $order->messages }; |
664 |
@messages = @{ $order->messages }; |
Lines 686-697
subtest 'cancel() tests' => sub {
Link Here
|
686 |
)->reset_messages; |
688 |
)->reset_messages; |
687 |
$order->add_item( $item_1->id ); |
689 |
$order->add_item( $item_1->id ); |
688 |
|
690 |
|
689 |
$order->cancel({ reason => 'Some reason', delete_biblio => 1 }) |
691 |
$order->cancel({ reason => $reason, delete_biblio => 1 }) |
690 |
->discard_changes; |
692 |
->discard_changes; |
691 |
|
693 |
|
692 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
694 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
693 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
695 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
694 |
is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); |
696 |
is( $order->cancellationreason, $reason, 'cancellationreason is undef' ); |
695 |
is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' ); |
697 |
is( Koha::Items->find($item_1->id), undef, 'The item is no longer present' ); |
696 |
is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' ); |
698 |
is( ref(Koha::Items->find($item_2->id)), 'Koha::Item', 'The item is still present' ); |
697 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
699 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
Lines 734-745
subtest 'cancel() tests' => sub {
Link Here
|
734 |
} |
736 |
} |
735 |
); |
737 |
); |
736 |
|
738 |
|
737 |
$order->cancel({ reason => 'Some reason', delete_biblio => 1 }) |
739 |
$order->cancel({ reason => $reason, delete_biblio => 1 }) |
738 |
->discard_changes; |
740 |
->discard_changes; |
739 |
|
741 |
|
740 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
742 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
741 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
743 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
742 |
is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); |
744 |
is( $order->cancellationreason, $reason, 'cancellationreason is undef' ); |
743 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
745 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
744 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
746 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
745 |
@messages = @{ $order->messages }; |
747 |
@messages = @{ $order->messages }; |
Lines 778-793
subtest 'cancel() tests' => sub {
Link Here
|
778 |
} |
780 |
} |
779 |
); |
781 |
); |
780 |
|
782 |
|
781 |
$order->cancel({ reason => 'Some reason', delete_biblio => 1 }) |
783 |
$order->cancel({ reason => $reason, delete_biblio => 1 }) |
782 |
->discard_changes; |
784 |
->discard_changes; |
783 |
|
785 |
|
784 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
786 |
is( $order->orderstatus, 'cancelled', 'Order is marked as cancelled' ); |
785 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
787 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is set' ); |
786 |
is( $order->cancellationreason, 'Some reason', 'cancellationreason is undef' ); |
788 |
is( $order->cancellationreason, $reason, 'cancellationreason is undef' ); |
787 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
789 |
is( Koha::Items->find($item->id), undef, 'The item is no longer present' ); |
788 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
790 |
is( ref(Koha::Biblios->find($biblio_id)), 'Koha::Biblio', 'The biblio is still present' ); |
789 |
@messages = @{ $order->messages }; |
791 |
@messages = @{ $order->messages }; |
790 |
is( $messages[0]->message, 'error_delbiblio', 'Cannot delete biblio and it gets notified' ); |
792 |
is( $messages[0]->message, 'error_delbiblio', 'Cannot delete biblio and it gets notified' ); |
791 |
|
793 |
|
|
|
794 |
# Scenario: |
795 |
# * order with one item attached |
796 |
# * delete_biblio is passed |
797 |
# => order is cancelled |
798 |
# => item in order is removed |
799 |
# => biblio in order is removed |
800 |
|
801 |
$item = $builder->build_sample_item; |
802 |
$biblio_id = $item->biblio->id; |
803 |
$order = $builder->build_object( |
804 |
{ |
805 |
class => 'Koha::Acquisition::Orders', |
806 |
value => { |
807 |
orderstatus => 'new', |
808 |
biblionumber => $item->biblio->id, |
809 |
datecancellationprinted => undef, |
810 |
cancellationreason => undef, |
811 |
} |
812 |
} |
813 |
); |
814 |
$order->add_item( $item->id ); |
815 |
|
816 |
$order->cancel({ reason => $reason, delete_biblio => 1 }); |
817 |
# refresh the order object |
818 |
$order->discard_changes; |
819 |
|
820 |
is( $order->orderstatus, 'cancelled', 'Order is not marked as cancelled' ); |
821 |
isnt( $order->datecancellationprinted, undef, 'datecancellationprinted is not undef' ); |
822 |
is( $order->cancellationreason, $reason, 'cancellationreason is set' ); |
823 |
is( Koha::Items->find($item->id), undef, 'The item is not present' ); |
824 |
is( Koha::Biblios->find($biblio_id), undef, 'The biblio is not present' ); |
825 |
@messages = @{ $order->messages }; |
826 |
is( scalar @messages, 0, 'No errors' ); |
827 |
|
792 |
$schema->storage->txn_rollback; |
828 |
$schema->storage->txn_rollback; |
793 |
}; |
829 |
}; |
794 |
- |
|
|