|
Lines 19-25
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 8; |
22 |
use Test::More tests => 9; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
|
24 |
|
| 25 |
use C4::Biblio; |
25 |
use C4::Biblio; |
|
Lines 691-693
subtest 'Tests for itemtype' => sub {
Link Here
|
| 691 |
|
691 |
|
| 692 |
$schema->storage->txn_rollback; |
692 |
$schema->storage->txn_rollback; |
| 693 |
}; |
693 |
}; |
| 694 |
- |
694 |
|
|
|
695 |
subtest 'get_transfers' => sub { |
| 696 |
plan tests => 16; |
| 697 |
$schema->storage->txn_begin; |
| 698 |
|
| 699 |
my $item = $builder->build_sample_item(); |
| 700 |
|
| 701 |
my $transfers = $item->get_transfers(); |
| 702 |
is(ref($transfers), 'Koha::Item::Transfers', 'Koha::Item->get_transfer should return a Koha::Item::Transfers object' ); |
| 703 |
is($transfers->count, 0, 'When no transfers exist, the Koha::Item:Transfers object should be empty'); |
| 704 |
|
| 705 |
my $library_to = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 706 |
|
| 707 |
my $transfer_1 = $builder->build_object( |
| 708 |
{ |
| 709 |
class => 'Koha::Item::Transfers', |
| 710 |
value => { |
| 711 |
itemnumber => $item->itemnumber, |
| 712 |
frombranch => $item->holdingbranch, |
| 713 |
tobranch => $library_to->branchcode, |
| 714 |
reason => 'Manual', |
| 715 |
datesent => undef, |
| 716 |
datearrived => undef, |
| 717 |
datecancelled => undef, |
| 718 |
daterequested => \'NOW()' |
| 719 |
} |
| 720 |
} |
| 721 |
); |
| 722 |
|
| 723 |
$transfers = $item->get_transfers(); |
| 724 |
is($transfers->count, 1, 'When one transfer has been reqeusted, the Koha::Item:Transfers object should contain one result'); |
| 725 |
|
| 726 |
my $transfer_2 = $builder->build_object( |
| 727 |
{ |
| 728 |
class => 'Koha::Item::Transfers', |
| 729 |
value => { |
| 730 |
itemnumber => $item->itemnumber, |
| 731 |
frombranch => $item->holdingbranch, |
| 732 |
tobranch => $library_to->branchcode, |
| 733 |
reason => 'Manual', |
| 734 |
datesent => undef, |
| 735 |
datearrived => undef, |
| 736 |
datecancelled => undef, |
| 737 |
daterequested => \'NOW()' |
| 738 |
} |
| 739 |
} |
| 740 |
); |
| 741 |
|
| 742 |
my $transfer_3 = $builder->build_object( |
| 743 |
{ |
| 744 |
class => 'Koha::Item::Transfers', |
| 745 |
value => { |
| 746 |
itemnumber => $item->itemnumber, |
| 747 |
frombranch => $item->holdingbranch, |
| 748 |
tobranch => $library_to->branchcode, |
| 749 |
reason => 'Manual', |
| 750 |
datesent => undef, |
| 751 |
datearrived => undef, |
| 752 |
datecancelled => undef, |
| 753 |
daterequested => \'NOW()' |
| 754 |
} |
| 755 |
} |
| 756 |
); |
| 757 |
|
| 758 |
$transfers = $item->get_transfers(); |
| 759 |
is($transfers->count, 3, 'When there are multiple open transfer requests, the Koha::Item::Transfers object contains them all'); |
| 760 |
my $result_1 = $transfers->next; |
| 761 |
my $result_2 = $transfers->next; |
| 762 |
my $result_3 = $transfers->next; |
| 763 |
is( $result_1->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfers returns the oldest transfer request first'); |
| 764 |
is( $result_2->branchtransfer_id, $transfer_2->branchtransfer_id, 'Koha::Item->get_transfers returns the newer transfer request second'); |
| 765 |
is( $result_3->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the newest transfer request last'); |
| 766 |
|
| 767 |
$transfer_2->datesent(\'NOW()')->store; |
| 768 |
$transfers = $item->get_transfers(); |
| 769 |
is($transfers->count, 3, 'When one transfer is set to in_transit, the Koha::Item::Transfers object still contains them all'); |
| 770 |
$result_1 = $transfers->next; |
| 771 |
$result_2 = $transfers->next; |
| 772 |
$result_3 = $transfers->next; |
| 773 |
is( $result_1->branchtransfer_id, $transfer_2->branchtransfer_id, 'Koha::Item->get_transfers returns the active transfer request first'); |
| 774 |
is( $result_2->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfers returns the other transfers oldest to newest'); |
| 775 |
is( $result_3->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the other transfers oldest to newest'); |
| 776 |
|
| 777 |
$transfer_2->datearrived(\'NOW()')->store; |
| 778 |
$transfers = $item->get_transfers(); |
| 779 |
is($transfers->count, 2, 'Once a transfer is recieved, it no longer appears in the list from ->get_transfers()'); |
| 780 |
$result_1 = $transfers->next; |
| 781 |
$result_2 = $transfers->next; |
| 782 |
is( $result_1->branchtransfer_id, $transfer_1->branchtransfer_id, 'Koha::Item->get_transfers returns the other transfers oldest to newest'); |
| 783 |
is( $result_2->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the other transfers oldest to newest'); |
| 784 |
|
| 785 |
$transfer_1->datecancelled(\'NOW()')->store; |
| 786 |
$transfers = $item->get_transfers(); |
| 787 |
is($transfers->count, 1, 'Once a transfer is cancelled, it no longer appears in the list from ->get_transfers()'); |
| 788 |
$result_1 = $transfers->next; |
| 789 |
is( $result_1->branchtransfer_id, $transfer_3->branchtransfer_id, 'Koha::Item->get_transfers returns the only transfer that remains'); |
| 790 |
|
| 791 |
$schema->storage->txn_rollback; |
| 792 |
}; |