Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
|
20 |
use Test::More tests => 1; |
21 |
use Test::Exception; |
22 |
|
23 |
use t::lib::TestBuilder; |
24 |
|
25 |
use Koha::DateUtils qw(dt_from_string output_pref); |
26 |
|
27 |
my $schema = Koha::Database->new->schema; |
28 |
my $builder = t::lib::TestBuilder->new; |
29 |
|
30 |
subtest 'shift_due_date() tests' => sub { |
31 |
|
32 |
plan tests => 10; |
33 |
|
34 |
$schema->storage->txn_begin; |
35 |
|
36 |
my $checkout = $builder->build_object( |
37 |
{ |
38 |
class => 'Koha::Checkouts', |
39 |
value => { |
40 |
date_due => '2020-04-01 13:06:16' |
41 |
} |
42 |
} |
43 |
); |
44 |
|
45 |
throws_ok |
46 |
{ $checkout->shift_due_date({ hard_due_date => 'cat', days => 'dog' }) } |
47 |
'Koha::Exceptions::BadParameter', |
48 |
'Passing both params makes it raise an exception'; |
49 |
|
50 |
is( "$@", "Called with both 'days' and 'hard_due_date'. Only one can be used.", 'Exception stringified correctly' ); |
51 |
|
52 |
throws_ok |
53 |
{ $checkout->shift_due_date({ }) } |
54 |
'Koha::Exceptions::BadParameter', |
55 |
'Passing no params makes it raise an exception'; |
56 |
|
57 |
is( "$@", "At least one parameter needs to be passed", 'Exception stringified correctly' ); |
58 |
|
59 |
throws_ok |
60 |
{ $checkout->shift_due_date({ hard_due_date => 'cat' }) } |
61 |
'Koha::Exceptions::WrongParameter', |
62 |
'Passing an invalid param type makes it raise an exception'; |
63 |
|
64 |
is( "$@", "'hard_due_date' must be a DateTime object", 'Exception stringified correctly' ); |
65 |
|
66 |
throws_ok |
67 |
{ $checkout->shift_due_date({ days => 'dog' }) } |
68 |
'Koha::Exceptions::WrongParameter', |
69 |
'Passing an invalid param type makes it raise an exception'; |
70 |
|
71 |
is( "$@", "'days' must be an integer", 'Exception stringified correctly' ); |
72 |
|
73 |
my $hard_due_date = dt_from_string( '2020-04-13' ); |
74 |
$checkout->shift_due_date({ hard_due_date => $hard_due_date }); |
75 |
|
76 |
is( |
77 |
output_pref({ dt => dt_from_string($checkout->date_due) }), |
78 |
output_pref({ dt => dt_from_string('2020-04-13 13:06:16') }) |
79 |
); |
80 |
|
81 |
$checkout->shift_due_date({ days => 3 }); |
82 |
is( |
83 |
output_pref({ dt => dt_from_string($checkout->date_due) }), |
84 |
output_pref({ dt => dt_from_string('2020-04-16 13:06:16') }) |
85 |
); |
86 |
|
87 |
$schema->storage->txn_rollback; |
88 |
}; |