|
Lines 19-28
Link Here
|
| 19 |
|
19 |
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 11; |
22 |
use Test::More tests => 13; |
| 23 |
use Test::Exception; |
23 |
use Test::Exception; |
| 24 |
use Test::Warn; |
24 |
use Test::Warn; |
| 25 |
|
25 |
|
|
|
26 |
use Koha::CirculationRules; |
| 26 |
use Koha::Database; |
27 |
use Koha::Database; |
| 27 |
use Koha::DateUtils qw(dt_from_string); |
28 |
use Koha::DateUtils qw(dt_from_string); |
| 28 |
use Koha::ArticleRequests; |
29 |
use Koha::ArticleRequests; |
|
Lines 820-825
subtest 'article_requests() tests' => sub {
Link Here
|
| 820 |
|
821 |
|
| 821 |
$schema->storage->txn_begin; |
822 |
$schema->storage->txn_begin; |
| 822 |
|
823 |
|
|
|
824 |
my $library = $builder->build_object({ class => 'Koha::Libraries' }); |
| 825 |
t::lib::Mocks::mock_userenv( { branchcode => $library->id } ); |
| 826 |
|
| 823 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
827 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 824 |
|
828 |
|
| 825 |
my $article_requests = $patron->article_requests; |
829 |
my $article_requests = $patron->article_requests; |
|
Lines 907-912
subtest 'safe_to_delete() tests' => sub {
Link Here
|
| 907 |
ok( $patron->safe_to_delete, 'Can delete, all conditions met' ); |
911 |
ok( $patron->safe_to_delete, 'Can delete, all conditions met' ); |
| 908 |
my $messages = $patron->safe_to_delete->messages; |
912 |
my $messages = $patron->safe_to_delete->messages; |
| 909 |
is_deeply( $messages, [], 'Patron can be deleted, no messages' ); |
913 |
is_deeply( $messages, [], 'Patron can be deleted, no messages' ); |
|
|
914 |
}; |
| 915 |
|
| 916 |
subtest 'article_request_fee() tests' => sub { |
| 917 |
|
| 918 |
plan tests => 3; |
| 919 |
|
| 920 |
$schema->storage->txn_begin; |
| 921 |
|
| 922 |
# Cleanup, to avoid interference |
| 923 |
Koha::CirculationRules->search( { rule_name => 'article_request_fee' } )->delete; |
| 924 |
|
| 925 |
t::lib::Mocks::mock_preference( 'ArticleRequests', 1 ); |
| 926 |
|
| 927 |
my $item = $builder->build_sample_item; |
| 928 |
|
| 929 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 930 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 931 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 932 |
|
| 933 |
# Rule that should never be picked, because the patron's category is always picked |
| 934 |
Koha::CirculationRules->set_rule( |
| 935 |
{ categorycode => undef, |
| 936 |
branchcode => undef, |
| 937 |
rule_name => 'article_request_fee', |
| 938 |
rule_value => 1, |
| 939 |
} |
| 940 |
); |
| 941 |
|
| 942 |
is( $patron->article_request_fee( { library_id => $library_2->id } ), 1, 'library_id used correctly' ); |
| 943 |
|
| 944 |
Koha::CirculationRules->set_rule( |
| 945 |
{ categorycode => $patron->categorycode, |
| 946 |
branchcode => undef, |
| 947 |
rule_name => 'article_request_fee', |
| 948 |
rule_value => 2, |
| 949 |
} |
| 950 |
); |
| 951 |
|
| 952 |
Koha::CirculationRules->set_rule( |
| 953 |
{ categorycode => $patron->categorycode, |
| 954 |
branchcode => $library_1->id, |
| 955 |
rule_name => 'article_request_fee', |
| 956 |
rule_value => 3, |
| 957 |
} |
| 958 |
); |
| 959 |
|
| 960 |
is( $patron->article_request_fee( { library_id => $library_2->id } ), 2, 'library_id used correctly' ); |
| 961 |
|
| 962 |
t::lib::Mocks::mock_userenv( { branchcode => $library_1->id } ); |
| 963 |
|
| 964 |
is( $patron->article_request_fee(), 3, 'env used correctly' ); |
| 965 |
|
| 966 |
$schema->storage->txn_rollback; |
| 967 |
}; |
| 968 |
|
| 969 |
subtest 'add_article_request_fee_if_needed() tests' => sub { |
| 970 |
|
| 971 |
plan tests => 12; |
| 972 |
|
| 973 |
$schema->storage->txn_begin; |
| 974 |
|
| 975 |
my $amount = 0; |
| 976 |
|
| 977 |
my $patron_mock = Test::MockModule->new('Koha::Patron'); |
| 978 |
$patron_mock->mock( 'article_request_fee', sub { return $amount; } ); |
| 979 |
|
| 980 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 981 |
|
| 982 |
is( $patron->article_request_fee, $amount, 'article_request_fee mocked' ); |
| 983 |
|
| 984 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 985 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 986 |
my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 987 |
my $item = $builder->build_sample_item; |
| 988 |
|
| 989 |
t::lib::Mocks::mock_userenv( |
| 990 |
{ branchcode => $library_1->id, patron => $staff } ); |
| 991 |
|
| 992 |
my $debit = $patron->add_article_request_fee_if_needed(); |
| 993 |
is( $debit, undef, 'No fee, no debit line' ); |
| 994 |
|
| 995 |
# positive value |
| 996 |
$amount = 1; |
| 997 |
|
| 998 |
$debit = $patron->add_article_request_fee_if_needed({ item_id => $item->id }); |
| 999 |
is( ref($debit), 'Koha::Account::Line', 'Debit object type correct' ); |
| 1000 |
is( $debit->amount, $amount, |
| 1001 |
'amount set to $patron->article_request_fee value' ); |
| 1002 |
is( $debit->manager_id, $staff->id, |
| 1003 |
'manager_id set to userenv session user' ); |
| 1004 |
is( $debit->branchcode, $library_1->id, |
| 1005 |
'branchcode set to userenv session library' ); |
| 1006 |
is( $debit->debit_type_code, 'ARTICLE_REQUEST', |
| 1007 |
'debit_type_code set correctly' ); |
| 1008 |
is( $debit->itemnumber, $item->id, |
| 1009 |
'itemnumber set correctly' ); |
| 1010 |
|
| 1011 |
$amount = 100; |
| 1012 |
|
| 1013 |
$debit = $patron->add_article_request_fee_if_needed({ library_id => $library_2->id }); |
| 1014 |
is( ref($debit), 'Koha::Account::Line', 'Debit object type correct' ); |
| 1015 |
is( $debit->amount, $amount, |
| 1016 |
'amount set to $patron->article_request_fee value' ); |
| 1017 |
is( $debit->branchcode, $library_2->id, |
| 1018 |
'branchcode set to userenv session library' ); |
| 1019 |
is( $debit->itemnumber, undef, |
| 1020 |
'itemnumber set correctly to undef' ); |
| 910 |
|
1021 |
|
| 911 |
$schema->storage->txn_rollback; |
1022 |
$schema->storage->txn_rollback; |
| 912 |
}; |
1023 |
}; |
| 913 |
- |
|
|