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

(-)a/t/db_dependent/HoldsQueue.t (-22 / +208 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 48;
11
use Test::More tests => 51;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Calendar;
14
use C4::Calendar;
Lines 794-826 Koha::Holds->find( $reserve_id )->cancel; Link Here
794
# End testing hold itemtype limit
794
# End testing hold itemtype limit
795
795
796
796
797
# Test Local Holds Priority - Bug 18001
797
subtest "Test Local Holds Priority - Bib level" => sub {
798
t::lib::Mocks::mock_preference('LocalHoldsPriority', 1);
798
    plan tests => 2;
799
t::lib::Mocks::mock_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
799
800
t::lib::Mocks::mock_preference('LocalHoldsPriorityItemControl', 'homebranch');
800
    Koha::Biblios->delete();
801
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
802
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
803
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
804
    my $branch  = $builder->build_object( { class => 'Koha::Libraries' } );
805
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
806
    my $local_patron = $builder->build_object(
807
        {
808
            class => "Koha::Patrons",
809
            value => {
810
                branchcode => $branch->branchcode
811
            }
812
        }
813
    );
814
    my $other_patron = $builder->build_object(
815
        {
816
            class => "Koha::Patrons",
817
            value => {
818
                branchcode => $branch2->branchcode
819
            }
820
        }
821
    );
822
    my $biblio = $builder->build_sample_biblio();
823
    my $item   = $builder->build_sample_item(
824
        {
825
            biblionumber  => $biblio->biblionumber,
826
            library    => $branch->branchcode,
827
        }
828
    );
801
829
802
$dbh->do("DELETE FROM tmp_holdsqueue");
830
    my $reserve_id =
803
$dbh->do("DELETE FROM hold_fill_targets");
831
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
804
$dbh->do("DELETE FROM reserves");
832
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
833
    my $reserve_id2 =
834
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
835
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, undef, undef, undef );
836
837
    C4::HoldsQueue::CreateQueue();
838
839
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
840
    is( $queue_rs->count(), 1,
841
        "Hold queue contains one hold" );
842
    is(
843
        $queue_rs->next->borrowernumber,
844
        $local_patron->borrowernumber,
845
        "We should pick the local hold over the next available"
846
    );
847
};
805
848
806
$item = Koha::Items->find( { biblionumber => $biblionumber } );
849
subtest "Test Local Holds Priority - Item level" => sub {
807
$item->holdingbranch( $item->homebranch );
850
    plan tests => 2;
808
$item->store();
851
852
    Koha::Biblios->delete();
853
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
854
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
855
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
856
    my $branch  = $builder->build_object( { class => 'Koha::Libraries' } );
857
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
858
    my $local_patron = $builder->build_object(
859
        {
860
            class => "Koha::Patrons",
861
            value => {
862
                branchcode => $branch->branchcode
863
            }
864
        }
865
    );
866
    my $other_patron = $builder->build_object(
867
        {
868
            class => "Koha::Patrons",
869
            value => {
870
                branchcode => $branch2->branchcode
871
            }
872
        }
873
    );
874
    my $biblio = $builder->build_sample_biblio();
875
    my $item   = $builder->build_sample_item(
876
        {
877
            biblionumber  => $biblio->biblionumber,
878
            library    => $branch->branchcode,
879
        }
880
    );
809
881
810
my $item2 = Koha::Item->new( $item->unblessed );
882
    my $reserve_id =
811
$item2->itemnumber( undef );
883
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
812
$item2->store();
884
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, $item->id, undef, undef );
885
    my $reserve_id2 =
886
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
887
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, $item->id, undef, undef );
813
888
814
my $item3 = Koha::Item->new( $item->unblessed );
889
    C4::HoldsQueue::CreateQueue();
815
$item3->itemnumber( undef );
816
$item3->store();
817
890
818
$reserve_id = AddReserve( $item->homebranch, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
891
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
892
    my $q = $queue_rs->next;
893
    is( $queue_rs->count(), 1,
894
        "Hold queue contains one hold" );
895
    is(
896
        $q->borrowernumber,
897
        $local_patron->borrowernumber,
898
        "We should pick the local hold over the next available"
899
    );
900
};
819
901
820
C4::HoldsQueue::CreateQueue();
902
subtest "Test Local Holds Priority - Item level hold over Record level hold (Bug 23934)" => sub {
903
    plan tests => 2;
904
905
    Koha::Biblios->delete();
906
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
907
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
908
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
909
    my $branch  = $builder->build_object( { class => 'Koha::Libraries' } );
910
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
911
    my $local_patron = $builder->build_object(
912
        {
913
            class => "Koha::Patrons",
914
            value => {
915
                branchcode => $branch->branchcode
916
            }
917
        }
918
    );
919
    my $other_patron = $builder->build_object(
920
        {
921
            class => "Koha::Patrons",
922
            value => {
923
                branchcode => $branch2->branchcode
924
            }
925
        }
926
    );
927
    my $biblio = $builder->build_sample_biblio();
928
    my $item   = $builder->build_sample_item(
929
        {
930
            biblionumber  => $biblio->biblionumber,
931
            library    => $branch->branchcode,
932
        }
933
    );
934
935
    my $reserve_id =
936
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
937
        $biblio->biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
938
    my $reserve_id2 =
939
      AddReserve( $item->homebranch, $local_patron->borrowernumber,
940
        $biblio->biblionumber, '', 2, undef, undef, undef, undef, $item->id, undef, undef );
941
942
    C4::HoldsQueue::CreateQueue();
943
944
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
945
    my $q = $queue_rs->next;
946
    is( $queue_rs->count(), 1,
947
        "Hold queue contains one hold" );
948
    is(
949
        $q->borrowernumber,
950
        $local_patron->borrowernumber,
951
        "We should pick the local hold over the next available"
952
    );
953
};
954
955
subtest "Test Local Holds Priority - Ensure no duplicate requests in holds queue (Bug 18001)" => sub {
956
    plan tests => 1;
957
958
    $dbh->do("DELETE FROM tmp_holdsqueue");
959
    $dbh->do("DELETE FROM hold_fill_targets");
960
    $dbh->do("DELETE FROM reserves");
961
    $dbh->do("DELETE FROM issuingrules");
962
    $dbh->do("DELETE FROM circulation_rules");
963
    Koha::Biblios->delete();
964
965
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
966
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
967
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
968
    my $branch  = $builder->build_object( { class => 'Koha::Libraries' } );
969
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
970
    my $patron  = $builder->build_object(
971
        {
972
            class => "Koha::Patrons",
973
            value => {
974
                branchcode => $branch->branchcode
975
            }
976
        }
977
    );
978
    my $biblio = $builder->build_sample_biblio();
979
    my $item1  = $builder->build_sample_item(
980
        {
981
            biblionumber => $biblio->biblionumber,
982
            library      => $branch->branchcode,
983
        }
984
    );
985
    my $item2 = $builder->build_sample_item(
986
        {
987
            biblionumber => $biblio->biblionumber,
988
            library      => $branch->branchcode,
989
        }
990
    );
991
992
    my $item3 = $builder->build_sample_item(
993
        {
994
            biblionumber => $biblio->biblionumber,
995
            library      => $branch->branchcode,
996
        }
997
    );
998
999
    $reserve_id =
1000
      AddReserve( $item1->homebranch, $patron->borrowernumber, $biblio->id, '',
1001
        1, undef, undef, undef, undef, undef, undef, undef );
1002
1003
    C4::HoldsQueue::CreateQueue();
1004
1005
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
1006
1007
    is( $queue_rs->count(), 1,
1008
        "Hold queue contains one hold from chosen from three possible items" );
1009
};
821
1010
822
my $queue_rs = $schema->resultset('TmpHoldsqueue');
823
is( $queue_rs->count(), 1, "Hold queue contains one hold from chosen from three possible items" );
824
1011
825
subtest 'Trivial test for UpdateTransportCostMatrix' => sub {
1012
subtest 'Trivial test for UpdateTransportCostMatrix' => sub {
826
    plan tests => 1;
1013
    plan tests => 1;
827
- 

Return to bug 23934