Bug 20912: (QA follow-up) Move Fees to Charges::
[koha.git] / t / db_dependent / Koha / Charges / Fees.t
1 #!/usr/bin/perl
2 #
3 # Copyright 2018 ByWater Solutions
4 #
5 # This file is part of Koha.
6 #
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.
11 #
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.
15 #
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.
19
20 use Modern::Perl;
21
22 use Test::More tests => 2;
23
24 use t::lib::Mocks;
25 use t::lib::TestBuilder;
26
27 use Data::Dumper;
28
29 use C4::Calendar;
30 use Koha::DateUtils qw(dt_from_string);
31
32 BEGIN {
33     use_ok('Koha::Charges::Fees');
34 }
35
36 my $builder = t::lib::TestBuilder->new();
37
38 my $patron_category = $builder->build_object(
39     {
40         class => 'Koha::Patron::Categories',
41         value => {
42             category_type => 'P',
43             enrolmentfee  => 0,
44         }
45     }
46 );
47 my $library = $builder->build_object(
48     {
49         class => 'Koha::Libraries',
50     }
51 );
52 my $biblio = $builder->build_object(
53     {
54         class => 'Koha::Biblios',
55     }
56 );
57 my $itemtype = $builder->build_object(
58     {
59         class => 'Koha::ItemTypes',
60         value => {
61             rental_charge_daily => '0.00',
62             rentalcharge        => '0.00',
63             processfee          => '0.00',
64             defaultreplacecost  => '0.00',
65         },
66     }
67 );
68 my $item = $builder->build_object(
69     {
70         class => 'Koha::Items',
71         value => {
72             biblionumber  => $biblio->id,
73             homebranch    => $library->id,
74             holdingbranch => $library->id,
75             itype         => $itemtype->id,
76         }
77     }
78 );
79 my $patron = $builder->build_object(
80     {
81         class => 'Koha::Patrons',
82         value => {
83             dateexpiry   => '9999-12-31',
84             categorycode => $patron_category->id,
85         }
86     }
87 );
88
89 my $dt_from = dt_from_string();
90 my $dt_to = dt_from_string()->add( days => 6 );
91
92 my $fees = Koha::Charges::Fees->new(
93     {
94         patron    => $patron,
95         library   => $library,
96         item      => $item,
97         to_date   => $dt_to,
98         from_date => $dt_from,
99     }
100 );
101
102 subtest 'Koha::ItemType::rental_charge_daily tests' => sub {
103     plan tests => 4;
104
105     $itemtype->rental_charge_daily(1.00);
106     $itemtype->store();
107     is( $itemtype->rental_charge_daily,
108         1.00, 'Daily return charge stored correctly' );
109
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' );
113
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' );
117
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'
123     );
124     $charge = $fees->rental_charge_daily();
125     is( $charge, 5.00, 'Daily rental charge calculated correctly with finesCalendar = noFinesWhenClosed and closed Wednesdays' );
126 };