Lines 19-28
Link Here
|
19 |
|
19 |
|
20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
21 |
|
21 |
|
22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 12; |
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 846-848
subtest 'article_requests() tests' => sub {
Link Here
|
846 |
|
850 |
|
847 |
$schema->storage->txn_rollback; |
851 |
$schema->storage->txn_rollback; |
848 |
}; |
852 |
}; |
849 |
- |
853 |
|
|
|
854 |
subtest 'article_request_fee() tests' => sub { |
855 |
|
856 |
plan tests => 3; |
857 |
|
858 |
$schema->storage->txn_begin; |
859 |
|
860 |
# Cleanup, to avoid interference |
861 |
Koha::CirculationRules->search( { rule_name => 'article_request_fee' } )->delete; |
862 |
|
863 |
t::lib::Mocks::mock_preference( 'ArticleRequests', 1 ); |
864 |
|
865 |
my $item = $builder->build_sample_item; |
866 |
|
867 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
868 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
869 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
870 |
|
871 |
# Rule that should never be picked, because the patron's category is always picked |
872 |
Koha::CirculationRules->set_rule( |
873 |
{ categorycode => undef, |
874 |
branchcode => undef, |
875 |
rule_name => 'article_request_fee', |
876 |
rule_value => 1, |
877 |
} |
878 |
); |
879 |
|
880 |
is( $patron->article_request_fee( { library_id => $library_2->id } ), 1, 'library_id used correctly' ); |
881 |
|
882 |
Koha::CirculationRules->set_rule( |
883 |
{ categorycode => $patron->categorycode, |
884 |
branchcode => undef, |
885 |
rule_name => 'article_request_fee', |
886 |
rule_value => 2, |
887 |
} |
888 |
); |
889 |
|
890 |
Koha::CirculationRules->set_rule( |
891 |
{ categorycode => $patron->categorycode, |
892 |
branchcode => $library_1->id, |
893 |
rule_name => 'article_request_fee', |
894 |
rule_value => 3, |
895 |
} |
896 |
); |
897 |
|
898 |
is( $patron->article_request_fee( { library_id => $library_2->id } ), 2, 'library_id used correctly' ); |
899 |
|
900 |
t::lib::Mocks::mock_userenv( { branchcode => $library_1->id } ); |
901 |
|
902 |
is( $patron->article_request_fee(), 3, 'env used correctly' ); |
903 |
|
904 |
$schema->storage->txn_rollback; |
905 |
}; |
906 |
|
907 |
subtest 'add_article_request_fee_if_needed() tests' => sub { |
908 |
|
909 |
plan tests => 12; |
910 |
|
911 |
$schema->storage->txn_begin; |
912 |
|
913 |
my $amount = 0; |
914 |
|
915 |
my $patron_mock = Test::MockModule->new('Koha::Patron'); |
916 |
$patron_mock->mock( 'article_request_fee', sub { return $amount; } ); |
917 |
|
918 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
919 |
|
920 |
is( $patron->article_request_fee, $amount, 'article_request_fee mocked' ); |
921 |
|
922 |
my $library_1 = $builder->build_object( { class => 'Koha::Libraries' } ); |
923 |
my $library_2 = $builder->build_object( { class => 'Koha::Libraries' } ); |
924 |
my $staff = $builder->build_object( { class => 'Koha::Patrons' } ); |
925 |
my $item = $builder->build_sample_item; |
926 |
|
927 |
t::lib::Mocks::mock_userenv( |
928 |
{ branchcode => $library_1->id, patron => $staff } ); |
929 |
|
930 |
my $debit = $patron->add_article_request_fee_if_needed(); |
931 |
is( $debit, undef, 'No fee, no debit line' ); |
932 |
|
933 |
# positive value |
934 |
$amount = 1; |
935 |
|
936 |
$debit = $patron->add_article_request_fee_if_needed({ item_id => $item->id }); |
937 |
is( ref($debit), 'Koha::Account::Line', 'Debit object type correct' ); |
938 |
is( $debit->amount, $amount, |
939 |
'amount set to $patron->article_request_fee value' ); |
940 |
is( $debit->manager_id, $staff->id, |
941 |
'manager_id set to userenv session user' ); |
942 |
is( $debit->branchcode, $library_1->id, |
943 |
'branchcode set to userenv session library' ); |
944 |
is( $debit->debit_type_code, 'ARTICLE_REQUEST', |
945 |
'debit_type_code set correctly' ); |
946 |
is( $debit->itemnumber, $item->id, |
947 |
'itemnumber set correctly' ); |
948 |
|
949 |
$amount = 100; |
950 |
|
951 |
$debit = $patron->add_article_request_fee_if_needed({ library_id => $library_2->id }); |
952 |
is( ref($debit), 'Koha::Account::Line', 'Debit object type correct' ); |
953 |
is( $debit->amount, $amount, |
954 |
'amount set to $patron->article_request_fee value' ); |
955 |
is( $debit->branchcode, $library_2->id, |
956 |
'branchcode set to userenv session library' ); |
957 |
is( $debit->itemnumber, undef, |
958 |
'itemnumber set correctly to undef' ); |
959 |
|
960 |
$schema->storage->txn_rollback; |
961 |
}; |