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

(-)a/t/db_dependent/HoldsQueue.t (-22 / +155 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 => 50;
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 );
805
836
806
$item = Koha::Items->find( { biblionumber => $biblionumber } );
837
    C4::HoldsQueue::CreateQueue();
807
$item->holdingbranch( $item->homebranch );
808
$item->store();
809
838
810
my $item2 = Koha::Item->new( $item->unblessed );
839
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
811
$item2->itemnumber( undef );
840
    is( $queue_rs->count(), 1,
812
$item2->store();
841
        "Hold queue contains one hold from chosen from three possible items" );
842
    is(
843
        $queue_rs->next->borrowernumber,
844
        $local_patron->borrowernumber,
845
        "We should pick the local hold over the next available"
846
    );
847
};
813
848
814
my $item3 = Koha::Item->new( $item->unblessed );
849
subtest "Test Local Holds Priority - Item level" => sub {
815
$item3->itemnumber( undef );
850
    plan tests => 2;
816
$item3->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
    );
817
881
818
$reserve_id = AddReserve( $item->homebranch, $borrowernumber, $biblionumber, '', 1, undef, undef, undef, undef, undef, undef, undef );
882
    my $reserve_id =
883
      AddReserve( $branch2->branchcode, $other_patron->borrowernumber,
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 );
819
888
820
C4::HoldsQueue::CreateQueue();
889
    C4::HoldsQueue::CreateQueue();
890
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 from chosen from three possible items" );
895
    is(
896
        $q->borrowernumber,
897
        $local_patron->borrowernumber,
898
        "We should pick the local hold over the next available"
899
    );
900
};
901
902
subtest "Test Local Holds Priority - Bug 18001" => sub {
903
    plan tests => 1;
904
905
    $dbh->do("DELETE FROM tmp_holdsqueue");
906
    $dbh->do("DELETE FROM hold_fill_targets");
907
    $dbh->do("DELETE FROM reserves");
908
    $dbh->do("DELETE FROM issuingrules");
909
    $dbh->do("DELETE FROM circulation_rules");
910
    Koha::Biblios->delete();
911
912
    t::lib::Mocks::mock_preference( 'LocalHoldsPriority', 1 );
913
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityPatronControl', 'PickupLibrary' );
914
    t::lib::Mocks::mock_preference( 'LocalHoldsPriorityItemControl', 'homebranch' );
915
    my $branch  = $builder->build_object( { class => 'Koha::Libraries' } );
916
    my $branch2 = $builder->build_object( { class => 'Koha::Libraries' } );
917
    my $patron  = $builder->build_object(
918
        {
919
            class => "Koha::Patrons",
920
            value => {
921
                branchcode => $branch->branchcode
922
            }
923
        }
924
    );
925
    my $biblio = $builder->build_sample_biblio();
926
    my $item1  = $builder->build_sample_item(
927
        {
928
            biblionumber => $biblio->biblionumber,
929
            library      => $branch->branchcode,
930
        }
931
    );
932
    my $item2 = $builder->build_sample_item(
933
        {
934
            biblionumber => $biblio->biblionumber,
935
            library      => $branch->branchcode,
936
        }
937
    );
938
939
    my $item3 = $builder->build_sample_item(
940
        {
941
            biblionumber => $biblio->biblionumber,
942
            library      => $branch->branchcode,
943
        }
944
    );
945
946
    $reserve_id =
947
      AddReserve( $item1->homebranch, $patron->borrowernumber, $biblio->id, '',
948
        1, undef, undef, undef, undef, undef, undef, undef );
949
950
    C4::HoldsQueue::CreateQueue();
951
952
    my $queue_rs = $schema->resultset('TmpHoldsqueue');
953
954
    is( $queue_rs->count(), 1,
955
        "Hold queue contains one hold from chosen from three possible items" );
956
};
821
957
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
958
825
subtest 'Trivial test for UpdateTransportCostMatrix' => sub {
959
subtest 'Trivial test for UpdateTransportCostMatrix' => sub {
826
    plan tests => 1;
960
    plan tests => 1;
827
- 

Return to bug 23934