From 6e26423a99ac9a2531dff27b7272cda80e767b18 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Fri, 23 Apr 2021 23:17:39 +0000 Subject: [PATCH] Bug 27946: Add tests Signed-off-by: Marcel de Rooy --- t/db_dependent/ArticleRequests.t | 79 +++++++++++++++++++++++++++++++- t/lib/TestBuilder.pm | 1 + 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/t/db_dependent/ArticleRequests.t b/t/db_dependent/ArticleRequests.t index 3f0ec37cd3..f27ef8bf48 100755 --- a/t/db_dependent/ArticleRequests.t +++ b/t/db_dependent/ArticleRequests.t @@ -19,7 +19,7 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 54; +use Test::More tests => 55; use t::lib::TestBuilder; use t::lib::Mocks; @@ -252,4 +252,81 @@ subtest 'may_article_request' => sub { $cache->clear_from_cache( Koha::CirculationRules::GUESSED_ITEMTYPES_KEY ); }; +subtest 'article request fee' => sub { + plan tests => 10; + + t::lib::Mocks::mock_preference('ArticleRequests', 1); + + my $item = $builder->build_sample_item; + + my $category = $builder->build_object( + { + class => 'Koha::Patron::Categories', + value => { + article_request_fee => undef + } + } + ); + my $patron = $builder->build_object( + { + class => 'Koha::Patrons', + value => { + categorycode => $category->categorycode + }, + } + ); + $patron->account->lines->delete(); + + my $article_request_1 = Koha::ArticleRequest->new( + { + borrowernumber => $patron->id, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + title => 'an article request', + } + )->store(); + + is($patron->account->balance, 0, 'There are no account lines'); + is($patron->article_requests_current->count, 1, 'There is one current article request'); + + $category->article_request_fee(10)->store(); + + my $article_request_2 = Koha::ArticleRequest->new( + { + borrowernumber => $patron->id, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + title => 'an second article request', + } + )->store(); + + is($patron->account->balance, 10, 'Patron owes 10'); + is($patron->article_requests_current->count, 2, 'There are 2 current article requests'); + + $category->article_request_fee(20)->store(); + + my $article_request_3 = Koha::ArticleRequest->new( + { + borrowernumber => $patron->id, + biblionumber => $item->biblionumber, + itemnumber => $item->itemnumber, + title => 'an third article request', + } + )->store(); + + is($patron->account->balance, 30, 'Patron owes 30'); + is($patron->article_requests_current->count, 3, 'There are 3 current article requests'); + + $article_request_2->cancel(); + + is($patron->account->balance, 20, 'Patron owes 20'); + is($patron->article_requests_current->count, 2, 'There are 2 current article requests'); + + $article_request_3->cancel(); + + is($patron->account->balance, 0, 'There are no account lines'); + is($patron->article_requests_current->count, 1, 'There is one current article request'); + +}; + $schema->storage->txn_rollback(); diff --git a/t/lib/TestBuilder.pm b/t/lib/TestBuilder.pm index e8b0dbf126..27ce564009 100644 --- a/t/lib/TestBuilder.pm +++ b/t/lib/TestBuilder.pm @@ -570,6 +570,7 @@ sub _gen_default_values { category_type => sub { return [ qw( A C S I P ) ]->[int(rand(5))] }, min_password_length => undef, require_strong_password => undef, + article_request_fee => undef, }, Branch => { pickup_location => 0, -- 2.25.1