|
Lines 42-47
$dbh->do(q|DELETE FROM borrowers|);
Link Here
|
| 42 |
#$dbh->do(q|DELETE FROM branches|); |
42 |
#$dbh->do(q|DELETE FROM branches|); |
| 43 |
$dbh->do(q|DELETE FROM categories|); |
43 |
$dbh->do(q|DELETE FROM categories|); |
| 44 |
$dbh->do(q|DELETE FROM accountlines|); |
44 |
$dbh->do(q|DELETE FROM accountlines|); |
|
|
45 |
$dbh->do(q|DELETE FROM itemtypes WHERE parent_type IS NOT NULL|); |
| 45 |
$dbh->do(q|DELETE FROM itemtypes|); |
46 |
$dbh->do(q|DELETE FROM itemtypes|); |
| 46 |
Koha::CirculationRules->search()->delete(); |
47 |
Koha::CirculationRules->search()->delete(); |
| 47 |
|
48 |
|
|
Lines 812-818
subtest 'empty string means unlimited' => sub {
Link Here
|
| 812 |
}; |
813 |
}; |
| 813 |
|
814 |
|
| 814 |
subtest 'itemtype group tests' => sub { |
815 |
subtest 'itemtype group tests' => sub { |
| 815 |
plan tests => 17; |
816 |
plan tests => 20; |
| 816 |
|
817 |
|
| 817 |
t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' ); |
818 |
t::lib::Mocks::mock_preference( 'CircControl', 'ItemHomeLibrary' ); |
| 818 |
Koha::CirculationRules->set_rules( |
819 |
Koha::CirculationRules->set_rules( |
|
Lines 821-827
subtest 'itemtype group tests' => sub {
Link Here
|
| 821 |
categorycode => '*', |
822 |
categorycode => '*', |
| 822 |
itemtype => '*', |
823 |
itemtype => '*', |
| 823 |
rules => { |
824 |
rules => { |
| 824 |
maxissueqty => '', |
825 |
maxissueqty => '5', |
| 825 |
maxonsiteissueqty => '', |
826 |
maxonsiteissueqty => '', |
| 826 |
issuelength => 1, |
827 |
issuelength => 1, |
| 827 |
firstremind => 1, # 1 day of grace |
828 |
firstremind => 1, # 1 day of grace |
|
Lines 886-895
subtest 'itemtype group tests' => sub {
Link Here
|
| 886 |
itype => $child_itype_1->{itemtype} |
887 |
itype => $child_itype_1->{itemtype} |
| 887 |
} |
888 |
} |
| 888 |
); |
889 |
); |
|
|
890 |
my $checkout_item = $builder->build_sample_item( |
| 891 |
{ |
| 892 |
homebranch => $branch->{branchcode}, |
| 893 |
holdingbranch => $branch->{branchcode}, |
| 894 |
itype => $parent_itype->{itemtype} |
| 895 |
} |
| 896 |
); |
| 889 |
|
897 |
|
| 890 |
my $all_iq_rule = $builder->build( |
898 |
my $all_iq_rule = $builder->build_object( |
| 891 |
{ |
899 |
{ |
| 892 |
source => 'CirculationRule', |
900 |
class => 'Koha::CirculationRules', |
| 893 |
value => { |
901 |
value => { |
| 894 |
branchcode => $branch->{branchcode}, |
902 |
branchcode => $branch->{branchcode}, |
| 895 |
categorycode => $category->{categorycode}, |
903 |
categorycode => $category->{categorycode}, |
|
Lines 903-918
subtest 'itemtype group tests' => sub {
Link Here
|
| 903 |
undef, 'Checkout allowed, using all rule of 1' ); |
911 |
undef, 'Checkout allowed, using all rule of 1' ); |
| 904 |
|
912 |
|
| 905 |
#Checkout an item |
913 |
#Checkout an item |
| 906 |
my $issue = |
914 |
my $issue = C4::Circulation::AddIssue( $patron, $checkout_item->barcode, dt_from_string() ); |
| 907 |
C4::Circulation::AddIssue( $patron, $item->barcode, dt_from_string() ); |
|
|
| 908 |
like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); |
915 |
like( $issue->issue_id, qr|^\d+$|, 'The issue should have been inserted' ); |
| 909 |
|
916 |
|
| 910 |
#Patron has 1 checkout of child itype1 |
917 |
#Patron has 1 checkout of parent itemtype {{{{ child itype1 |
| 911 |
|
918 |
|
| 912 |
my $parent_iq_rule = $builder->build( |
919 |
my $parent_iq_rule = $builder->build_object( |
| 913 |
{ |
920 |
{ |
| 914 |
source => 'CirculationRule', |
921 |
class => 'Koha::CirculationRules', |
| 915 |
value => { |
922 |
value => { |
| 916 |
branchcode => $branch->{branchcode}, |
923 |
branchcode => $branch->{branchcode}, |
| 917 |
categorycode => $category->{categorycode}, |
924 |
categorycode => $category->{categorycode}, |
| 918 |
itemtype => $parent_itype->{itemtype}, |
925 |
itemtype => $parent_itype->{itemtype}, |
|
Lines 922-929
subtest 'itemtype group tests' => sub {
Link Here
|
| 922 |
} |
929 |
} |
| 923 |
); |
930 |
); |
| 924 |
|
931 |
|
| 925 |
is( C4::Circulation::TooMany( $patron, $item ), |
932 |
is( |
| 926 |
undef, 'Checkout allowed, using parent type rule of 2' ); |
933 |
C4::Circulation::TooMany( $patron, $item ), |
|
|
934 |
undef, 'Checkout allowed, using parent type rule of 2' |
| 935 |
); |
| 936 |
|
| 937 |
$all_iq_rule->rule_value(5)->store; |
| 938 |
$parent_iq_rule->rule_value(1)->store; |
| 939 |
|
| 940 |
my $data = C4::Circulation::TooMany( $patron, $item ); |
| 941 |
my $rule = delete $data->{circulation_rule}; |
| 942 |
is( ref $rule, 'Koha::CirculationRule', 'Circulation rule was returned' ); |
| 943 |
is_deeply( |
| 944 |
$data, |
| 945 |
{ |
| 946 |
reason => 'TOO_MANY_CHECKOUTS', |
| 947 |
count => 1, |
| 948 |
max_allowed => 1, |
| 949 |
}, |
| 950 |
'Checkout not allowed, using parent type rule of 1' |
| 951 |
); |
| 952 |
|
| 953 |
$parent_iq_rule->rule_value(2)->store; |
| 954 |
|
| 955 |
is( |
| 956 |
C4::Circulation::TooMany( $patron, $item ), |
| 957 |
undef, 'Checkout allowed, using specific type of 1 and only parent type checked out' |
| 958 |
); |
| 959 |
|
| 960 |
$checkout_item->itype( $child_itype_1->{itemtype} )->store; |
| 927 |
|
961 |
|
| 928 |
my $child1_iq_rule = $builder->build_object( |
962 |
my $child1_iq_rule = $builder->build_object( |
| 929 |
{ |
963 |
{ |
|
Lines 938-945
subtest 'itemtype group tests' => sub {
Link Here
|
| 938 |
} |
972 |
} |
| 939 |
); |
973 |
); |
| 940 |
|
974 |
|
| 941 |
my $data = C4::Circulation::TooMany( $patron, $item ); |
975 |
$data = C4::Circulation::TooMany( $patron, $item ); |
| 942 |
my $rule = delete $data->{circulation_rule}; |
976 |
$rule = delete $data->{circulation_rule}; |
| 943 |
is( ref $rule, 'Koha::CirculationRule', 'Circulation rule was returned' ); |
977 |
is( ref $rule, 'Koha::CirculationRule', 'Circulation rule was returned' ); |
| 944 |
is_deeply( |
978 |
is_deeply( |
| 945 |
$data, |
979 |
$data, |
|
Lines 1017-1025
subtest 'itemtype group tests' => sub {
Link Here
|
| 1017 |
); |
1051 |
); |
| 1018 |
|
1052 |
|
| 1019 |
#increase parent type to greater than specific |
1053 |
#increase parent type to greater than specific |
| 1020 |
my $circ_rule_object = |
1054 |
# my $circ_rule_object = |
| 1021 |
Koha::CirculationRules->find( $parent_iq_rule->{id} ); |
1055 |
# Koha::CirculationRules->find( $parent_iq_rule->{id} ); |
| 1022 |
$circ_rule_object->rule_value(4)->store(); |
1056 |
# $circ_rule_object->rule_value(4)->store(); |
|
|
1057 |
$parent_iq_rule->rule_value(4)->store(); |
| 1058 |
|
| 1023 |
|
1059 |
|
| 1024 |
is( C4::Circulation::TooMany( $patron, $item_1 ), |
1060 |
is( C4::Circulation::TooMany( $patron, $item_1 ), |
| 1025 |
undef, 'Checkout allowed, using specific type rule of 3' ); |
1061 |
undef, 'Checkout allowed, using specific type rule of 3' ); |
| 1026 |
- |
|
|