View | Details | Raw Unified | Return to bug 27281
Collapse All | Expand All

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

Return to bug 27281