Bug 20912: Move calculation to Koha::Fees
[koha.git] / t / db_dependent / Koha / Fees.t
blobdb16a8236c00bec510e788d79bea4d286ce8c555
1 #!/usr/bin/perl
3 # Copyright 2018 ByWater Solutions
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 3 of the License, or (at your option) any later
10 # version.
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 use Modern::Perl;
22 use Test::More tests => 2;
24 use t::lib::Mocks;
25 use t::lib::TestBuilder;
27 use Data::Dumper;
29 use C4::Calendar;
30 use Koha::DateUtils qw(dt_from_string);
32 BEGIN {
33 use_ok('Koha::Fees');
36 my $builder = t::lib::TestBuilder->new();
38 my $patron_category = $builder->build_object(
40 class => 'Koha::Patron::Categories',
41 value => {
42 category_type => 'P',
43 enrolmentfee => 0,
47 my $library = $builder->build_object(
49 class => 'Koha::Libraries',
52 my $biblio = $builder->build_object(
54 class => 'Koha::Biblios',
57 my $itemtype = $builder->build_object(
59 class => 'Koha::ItemTypes',
60 value => {
61 rental_charge_daily => '0.00',
62 rentalcharge => '0.00',
63 processfee => '0.00',
64 defaultreplacecost => '0.00',
68 my $item = $builder->build_object(
70 class => 'Koha::Items',
71 value => {
72 biblionumber => $biblio->id,
73 homebranch => $library->id,
74 holdingbranch => $library->id,
75 itype => $itemtype->id,
79 my $patron = $builder->build_object(
81 class => 'Koha::Patrons',
82 value => {
83 dateexpiry => '9999-12-31',
84 categorycode => $patron_category->id,
89 my $dt_from = dt_from_string();
90 my $dt_to = dt_from_string()->add( days => 6 );
92 my $fees = Koha::Fees->new(
94 patron => $patron,
95 library => $library,
96 item => $item,
97 to_date => $dt_to,
98 from_date => $dt_from,
102 subtest 'Koha::ItemType::rental_charge_daily tests' => sub {
103 plan tests => 4;
105 $itemtype->rental_charge_daily(1.00);
106 $itemtype->store();
107 is( $itemtype->rental_charge_daily,
108 1.00, 'Daily return charge stored correctly' );
110 t::lib::Mocks::mock_preference( 'finesCalendar', 'ignoreCalendar' );
111 my $charge = $fees->rental_charge_daily();
112 is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = ignoreCalendar' );
114 t::lib::Mocks::mock_preference( 'finesCalendar', 'noFinesWhenClosed' );
115 $charge = $fees->rental_charge_daily();
116 is( $charge, 6.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed' );
118 my $calendar = C4::Calendar->new( branchcode => $library->id );
119 $calendar->insert_week_day_holiday(
120 weekday => 3,
121 title => 'Test holiday',
122 description => 'Test holiday'
124 $charge = $fees->rental_charge_daily();
125 is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' );