Lines 7-13
use t::lib::TestBuilder;
Link Here
|
7 |
|
7 |
|
8 |
use C4::Context; |
8 |
use C4::Context; |
9 |
|
9 |
|
10 |
use Test::More tests => 58; |
10 |
use Test::More tests => 60; |
11 |
use MARC::Record; |
11 |
use MARC::Record; |
12 |
|
12 |
|
13 |
use C4::Biblio; |
13 |
use C4::Biblio; |
Lines 24-31
use Koha::IssuingRules;
Link Here
|
24 |
use Koha::Item::Transfer::Limits; |
24 |
use Koha::Item::Transfer::Limits; |
25 |
use Koha::Items; |
25 |
use Koha::Items; |
26 |
use Koha::Libraries; |
26 |
use Koha::Libraries; |
|
|
27 |
use Koha::Library::Groups; |
27 |
use Koha::Patrons; |
28 |
use Koha::Patrons; |
28 |
|
29 |
|
|
|
30 |
use Data::Dumper; |
31 |
|
29 |
BEGIN { |
32 |
BEGIN { |
30 |
use FindBin; |
33 |
use FindBin; |
31 |
use lib $FindBin::Bin; |
34 |
use lib $FindBin::Bin; |
Lines 262-267
t::lib::Mocks::mock_preference('item-level_itypes', 1);
Link Here
|
262 |
|
265 |
|
263 |
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item |
266 |
# if IndependentBranches is OFF, a $branch_1 patron can reserve an $branch_2 item |
264 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
267 |
t::lib::Mocks::mock_preference('IndependentBranches', 0); |
|
|
268 |
|
265 |
ok( |
269 |
ok( |
266 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK', |
270 |
CanItemBeReserved($borrowernumbers[0], $foreign_itemnumber)->{status} eq 'OK', |
267 |
'$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)' |
271 |
'$branch_1 patron allowed to reserve $branch_2 item with IndependentBranches OFF (bug 2394)' |
Lines 670-672
subtest 'CanItemBeReserved / holds_per_day tests' => sub {
Link Here
|
670 |
|
674 |
|
671 |
$schema->storage->txn_rollback; |
675 |
$schema->storage->txn_rollback; |
672 |
}; |
676 |
}; |
673 |
- |
677 |
|
|
|
678 |
subtest 'CanItemBeReserved / branch_not_in_hold_group' => sub { |
679 |
plan tests => 9; |
680 |
|
681 |
$schema->storage->txn_begin; |
682 |
|
683 |
# Cleanup database |
684 |
Koha::Holds->search->delete; |
685 |
$dbh->do('DELETE FROM issues'); |
686 |
$dbh->do('DELETE FROM issuingrules'); |
687 |
$dbh->do( |
688 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
689 |
VALUES (?, ?, ?, ?)}, |
690 |
{}, |
691 |
'*', '*', '*', 25 |
692 |
); |
693 |
$dbh->do('DELETE FROM branch_item_rules'); |
694 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
695 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
696 |
$dbh->do('DELETE FROM default_circ_rules'); |
697 |
|
698 |
Koha::Items->search->delete; |
699 |
Koha::Biblios->search->delete; |
700 |
|
701 |
# Create item types |
702 |
my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
703 |
my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
704 |
|
705 |
# Create libraries |
706 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
707 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
708 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
709 |
|
710 |
# Create library groups hierarchy |
711 |
my $rootgroup = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } ); |
712 |
my $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); |
713 |
my $group2 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode} } ); |
714 |
|
715 |
# Create 2 patrons |
716 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library1->branchcode} } ); |
717 |
my $patron3 = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library3->branchcode} } ); |
718 |
|
719 |
# Create 3 biblios with items |
720 |
my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype }); |
721 |
my ( undef, undef, $itemnumber_1 ) = AddItem( |
722 |
{ homebranch => $library1->branchcode, |
723 |
holdingbranch => $library1->branchcode |
724 |
}, |
725 |
$biblio_1->biblionumber |
726 |
); |
727 |
my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype2->itemtype }); |
728 |
my ( undef, undef, $itemnumber_2 ) = AddItem( |
729 |
{ homebranch => $library2->branchcode, |
730 |
holdingbranch => $library2->branchcode |
731 |
}, |
732 |
$biblio_2->biblionumber |
733 |
); |
734 |
my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype }); |
735 |
my ( undef, undef, $itemnumber_3 ) = AddItem( |
736 |
{ homebranch => $library1->branchcode, |
737 |
holdingbranch => $library1->branchcode |
738 |
}, |
739 |
$biblio_3->biblionumber |
740 |
); |
741 |
|
742 |
# Test 1: Patron 3 can place hold |
743 |
is_deeply( |
744 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
745 |
{ status => 'OK' }, |
746 |
'Patron can place hold if no circ_rules where defined' |
747 |
); |
748 |
|
749 |
# Insert default circ rule of holds allowed only from local hold group for all libraries |
750 |
$dbh->do( |
751 |
q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch) |
752 |
VALUES (?,?,?)}, |
753 |
{}, |
754 |
3, 'any', 'any' |
755 |
); |
756 |
|
757 |
# Test 2: Patron 1 can place hold |
758 |
is_deeply( |
759 |
CanItemBeReserved( $patron1->borrowernumber, $itemnumber_2 ), |
760 |
{ status => 'OK' }, |
761 |
'Patron can place hold because patron\'s home library is part of hold group' |
762 |
); |
763 |
|
764 |
# Test 3: Patron 3 cannot place hold |
765 |
is_deeply( |
766 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
767 |
{ status => 'branchNotInHoldGroup' }, |
768 |
'Patron cannot place hold because patron\'s home library is not part of hold group' |
769 |
); |
770 |
|
771 |
# Cleanup default_cirt_rules |
772 |
$dbh->do('DELETE FROM default_circ_rules'); |
773 |
|
774 |
# Insert default circ rule to "any" for library 2 |
775 |
$dbh->do( |
776 |
q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch) |
777 |
VALUES (?,?,?,?)}, |
778 |
{}, |
779 |
$library2->branchcode, 2, 'any', 'any' |
780 |
); |
781 |
|
782 |
# Test 4: Patron 3 can place hold |
783 |
is_deeply( |
784 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
785 |
{ status => 'OK' }, |
786 |
'Patron can place hold if holdallowed is set to "any" for library 2' |
787 |
); |
788 |
|
789 |
# Update default circ rule to "hold group" for library 2 |
790 |
$dbh->do( |
791 |
q{UPDATE default_branch_circ_rules set holdallowed = ? |
792 |
WHERE branchcode = ?}, |
793 |
{}, |
794 |
3, $library2->branchcode |
795 |
); |
796 |
|
797 |
# Test 5: Patron 3 cannot place hold |
798 |
is_deeply( |
799 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
800 |
{ status => 'branchNotInHoldGroup' }, |
801 |
'Patron cannot place hold if holdallowed is set to "hold group" for library 2' |
802 |
); |
803 |
|
804 |
# Cleanup default_branch_cirt_rules |
805 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
806 |
|
807 |
# Insert default item rule to "any" for itemtype 2 |
808 |
$dbh->do( |
809 |
q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch) |
810 |
VALUES (?,?,?,?)}, |
811 |
{}, |
812 |
$itemtype2->itemtype, 2, 'any', 'any' |
813 |
); |
814 |
|
815 |
# Test 6: Patron 3 can place hold |
816 |
is_deeply( |
817 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
818 |
{ status => 'OK' }, |
819 |
'Patron can place hold if holdallowed is set to "any" for itemtype 2' |
820 |
); |
821 |
|
822 |
# Update default item rule to "hold group" for itemtype 2 |
823 |
$dbh->do( |
824 |
q{UPDATE default_branch_item_rules set holdallowed = ? |
825 |
WHERE itemtype = ?}, |
826 |
{}, |
827 |
3, $itemtype2->itemtype |
828 |
); |
829 |
|
830 |
# Test 7: Patron 3 cannot place hold |
831 |
is_deeply( |
832 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
833 |
{ status => 'branchNotInHoldGroup' }, |
834 |
'Patron cannot place hold if holdallowed is set to "hold group" for itemtype 2' |
835 |
); |
836 |
|
837 |
# Cleanup default_branch_item_rules |
838 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
839 |
|
840 |
# Insert branch item rule to "any" for itemtype 2 and library 2 |
841 |
$dbh->do( |
842 |
q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch) |
843 |
VALUES (?,?,?,?,?)}, |
844 |
{}, |
845 |
$library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any' |
846 |
); |
847 |
|
848 |
# Test 8: Patron 3 can place hold |
849 |
is_deeply( |
850 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
851 |
{ status => 'OK' }, |
852 |
'Patron can place hold if holdallowed is set to "any" for itemtype 2 and library 2' |
853 |
); |
854 |
|
855 |
# Update branch item rule to "hold group" for itemtype 2 and library 2 |
856 |
$dbh->do( |
857 |
q{UPDATE branch_item_rules set holdallowed = ? |
858 |
WHERE branchcode = ? and itemtype = ?}, |
859 |
{}, |
860 |
3, $library2->branchcode, $itemtype2->itemtype |
861 |
); |
862 |
|
863 |
# Test 9: Patron 3 cannot place hold |
864 |
is_deeply( |
865 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2 ), |
866 |
{ status => 'branchNotInHoldGroup' }, |
867 |
'Patron cannot place hold if holdallowed is set to "hold group" for itemtype 2 and library 2' |
868 |
); |
869 |
|
870 |
$schema->storage->txn_rollback; |
871 |
|
872 |
}; |
873 |
|
874 |
subtest 'CanItemBeReserved / pickup_not_in_hold_group' => sub { |
875 |
plan tests => 9; |
876 |
|
877 |
$schema->storage->txn_begin; |
878 |
|
879 |
# Cleanup database |
880 |
Koha::Holds->search->delete; |
881 |
$dbh->do('DELETE FROM issues'); |
882 |
$dbh->do('DELETE FROM issuingrules'); |
883 |
$dbh->do( |
884 |
q{INSERT INTO issuingrules (categorycode, branchcode, itemtype, reservesallowed) |
885 |
VALUES (?, ?, ?, ?)}, |
886 |
{}, |
887 |
'*', '*', '*', 25 |
888 |
); |
889 |
$dbh->do('DELETE FROM branch_item_rules'); |
890 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
891 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
892 |
$dbh->do('DELETE FROM default_circ_rules'); |
893 |
|
894 |
Koha::Items->search->delete; |
895 |
Koha::Biblios->search->delete; |
896 |
|
897 |
# Create item types |
898 |
my $itemtype1 = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
899 |
my $itemtype2 = $builder->build_object( { class => 'Koha::ItemTypes' } ); |
900 |
|
901 |
# Create libraries |
902 |
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
903 |
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
904 |
my $library3 = $builder->build_object( { class => 'Koha::Libraries' } ); |
905 |
|
906 |
# Create library groups hierarchy |
907 |
my $rootgroup = $builder->build_object( { class => 'Koha::Library::Groups', value => {ft_local_hold_group => 1} } ); |
908 |
my $group1 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library1->branchcode}} ); |
909 |
my $group2 = $builder->build_object( { class => 'Koha::Library::Groups', value => {parent_id => $rootgroup->id, branchcode => $library2->branchcode} } ); |
910 |
|
911 |
# Create 2 patrons |
912 |
my $patron1 = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library1->branchcode} } ); |
913 |
my $patron3 = $builder->build_object( { class => 'Koha::Patrons', value => {branchcode => $library3->branchcode} } ); |
914 |
|
915 |
# Create 3 biblios with items |
916 |
my $biblio_1 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype }); |
917 |
my ( undef, undef, $itemnumber_1 ) = AddItem( |
918 |
{ homebranch => $library1->branchcode, |
919 |
holdingbranch => $library1->branchcode |
920 |
}, |
921 |
$biblio_1->biblionumber |
922 |
); |
923 |
my $biblio_2 = $builder->build_sample_biblio({ itemtype => $itemtype2->itemtype }); |
924 |
my ( undef, undef, $itemnumber_2 ) = AddItem( |
925 |
{ homebranch => $library2->branchcode, |
926 |
holdingbranch => $library2->branchcode |
927 |
}, |
928 |
$biblio_2->biblionumber |
929 |
); |
930 |
my $biblio_3 = $builder->build_sample_biblio({ itemtype => $itemtype1->itemtype }); |
931 |
my ( undef, undef, $itemnumber_3 ) = AddItem( |
932 |
{ homebranch => $library1->branchcode, |
933 |
holdingbranch => $library1->branchcode |
934 |
}, |
935 |
$biblio_3->biblionumber |
936 |
); |
937 |
|
938 |
# Test 1: Patron 3 can place hold |
939 |
is_deeply( |
940 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
941 |
{ status => 'OK' }, |
942 |
'Patron can place hold if no circ_rules where defined' |
943 |
); |
944 |
|
945 |
# Insert default circ rule of holds allowed only from local hold group for all libraries |
946 |
$dbh->do( |
947 |
q{INSERT INTO default_circ_rules (holdallowed, hold_fulfillment_policy, returnbranch) |
948 |
VALUES (?,?,?)}, |
949 |
{}, |
950 |
2, 'holdgroup', 'any' |
951 |
); |
952 |
|
953 |
# Test 2: Patron 1 can place hold |
954 |
is_deeply( |
955 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library1->branchcode ), |
956 |
{ status => 'OK' }, |
957 |
'Patron can place hold because pickup location is part of hold group' |
958 |
); |
959 |
|
960 |
# Test 3: Patron 3 cannot place hold |
961 |
is_deeply( |
962 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
963 |
{ status => 'pickupNotInHoldGroup' }, |
964 |
'Patron cannot place hold because pickup location is not part of hold group' |
965 |
); |
966 |
|
967 |
# Cleanup default_cirt_rules |
968 |
$dbh->do('DELETE FROM default_circ_rules'); |
969 |
|
970 |
# Insert default circ rule to "any" for library 2 |
971 |
$dbh->do( |
972 |
q{INSERT INTO default_branch_circ_rules (branchcode, holdallowed, hold_fulfillment_policy, returnbranch) |
973 |
VALUES (?,?,?,?)}, |
974 |
{}, |
975 |
$library2->branchcode, 2, 'any', 'any' |
976 |
); |
977 |
|
978 |
# Test 4: Patron 3 can place hold |
979 |
is_deeply( |
980 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
981 |
{ status => 'OK' }, |
982 |
'Patron can place hold if default_branch_circ_rules is set to "any" for library 2' |
983 |
); |
984 |
|
985 |
# Update default circ rule to "hold group" for library 2 |
986 |
$dbh->do( |
987 |
q{UPDATE default_branch_circ_rules set hold_fulfillment_policy = ? |
988 |
WHERE branchcode = ?}, |
989 |
{}, |
990 |
'holdgroup', $library2->branchcode |
991 |
); |
992 |
|
993 |
# Test 5: Patron 3 cannot place hold |
994 |
is_deeply( |
995 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
996 |
{ status => 'pickupNotInHoldGroup' }, |
997 |
'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for library 2' |
998 |
); |
999 |
|
1000 |
# Cleanup default_branch_cirt_rules |
1001 |
$dbh->do('DELETE FROM default_branch_circ_rules'); |
1002 |
|
1003 |
# Insert default item rule to "any" for itemtype 2 |
1004 |
$dbh->do( |
1005 |
q{INSERT INTO default_branch_item_rules (itemtype, holdallowed, hold_fulfillment_policy, returnbranch) |
1006 |
VALUES (?,?,?,?)}, |
1007 |
{}, |
1008 |
$itemtype2->itemtype, 2, 'any', 'any' |
1009 |
); |
1010 |
|
1011 |
# Test 6: Patron 3 can place hold |
1012 |
is_deeply( |
1013 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
1014 |
{ status => 'OK' }, |
1015 |
'Patron can place hold if hold_fulfillment_policy is set to "any" for itemtype 2' |
1016 |
); |
1017 |
|
1018 |
# Update default item rule to "hold group" for itemtype 2 |
1019 |
$dbh->do( |
1020 |
q{UPDATE default_branch_item_rules set hold_fulfillment_policy = ? |
1021 |
WHERE itemtype = ?}, |
1022 |
{}, |
1023 |
'holdgroup', $itemtype2->itemtype |
1024 |
); |
1025 |
|
1026 |
# Test 7: Patron 3 cannot place hold |
1027 |
is_deeply( |
1028 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
1029 |
{ status => 'pickupNotInHoldGroup' }, |
1030 |
'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2' |
1031 |
); |
1032 |
|
1033 |
# Cleanup default_branch_item_rules |
1034 |
$dbh->do('DELETE FROM default_branch_item_rules'); |
1035 |
|
1036 |
# Insert branch item rule to "any" for itemtype 2 and library 2 |
1037 |
$dbh->do( |
1038 |
q{INSERT INTO branch_item_rules (branchcode, itemtype, holdallowed, hold_fulfillment_policy, returnbranch) |
1039 |
VALUES (?,?,?,?,?)}, |
1040 |
{}, |
1041 |
$library2->branchcode, $itemtype2->itemtype, 2, 'any', 'any' |
1042 |
); |
1043 |
|
1044 |
# Test 8: Patron 3 can place hold |
1045 |
is_deeply( |
1046 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
1047 |
{ status => 'OK' }, |
1048 |
'Patron can place hold if hold_fulfillment_policy is set to "any" for itemtype 2 and library 2' |
1049 |
); |
1050 |
|
1051 |
# Update branch item rule to "hold group" for itemtype 2 and library 2 |
1052 |
$dbh->do( |
1053 |
q{UPDATE branch_item_rules set hold_fulfillment_policy = ? |
1054 |
WHERE branchcode = ? and itemtype = ?}, |
1055 |
{}, |
1056 |
'holdgroup', $library2->branchcode, $itemtype2->itemtype |
1057 |
); |
1058 |
|
1059 |
# Test 9: Patron 3 cannot place hold |
1060 |
is_deeply( |
1061 |
CanItemBeReserved( $patron3->borrowernumber, $itemnumber_2, $library3->branchcode ), |
1062 |
{ status => 'pickupNotInHoldGroup' }, |
1063 |
'Patron cannot place hold if hold_fulfillment_policy is set to "hold group" for itemtype 2 and library 2' |
1064 |
); |
1065 |
|
1066 |
$schema->storage->txn_rollback; |
1067 |
}; |