|
Lines 20-25
Link Here
|
| 20 |
use Modern::Perl; |
20 |
use Modern::Perl; |
| 21 |
|
21 |
|
| 22 |
use Test::More tests => 10; |
22 |
use Test::More tests => 10; |
|
|
23 |
use Time::Fake; |
| 23 |
|
24 |
|
| 24 |
use C4::Context; |
25 |
use C4::Context; |
| 25 |
use Koha::Database; |
26 |
use Koha::Database; |
|
Lines 61-88
is( $retrieved_category_1->checkprevcheckout, 'inherit', 'Koha::Patron::Category
Link Here
|
| 61 |
is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' ); |
62 |
is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category->store should default checkprevcheckout to inherit' ); |
| 62 |
|
63 |
|
| 63 |
subtest 'get_expiry_date' => sub { |
64 |
subtest 'get_expiry_date' => sub { |
| 64 |
plan tests => 5; |
65 |
plan tests => 19; |
| 65 |
my $next_month = dt_from_string->add( months => 1 ); |
66 |
|
| 66 |
my $next_year = dt_from_string->add( months => 12 ); |
67 |
my $enrolementperioddate = dt_from_string()->add( months => 12); |
| 67 |
my $yesterday = dt_from_string->add( days => -1 ); |
|
|
| 68 |
my $category = Koha::Patron::Category->new({ |
68 |
my $category = Koha::Patron::Category->new({ |
| 69 |
categorycode => 'mycat', |
69 |
categorycode => 'mycat', |
| 70 |
category_type => 'A', |
70 |
category_type => 'A', |
| 71 |
description => 'mycatdesc', |
71 |
description => 'mycatdesc', |
| 72 |
enrolmentperiod => undef, |
72 |
enrolmentperiod => undef, |
| 73 |
enrolmentperioddate => $next_month, |
73 |
enrolmentperioddate => $enrolementperioddate, |
| 74 |
})->store; |
74 |
})->store; |
| 75 |
is( $category->get_expiry_date, $next_month, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' ); |
|
|
| 76 |
is( $category->get_expiry_date( $next_year ), $next_month, 'Without enrolmentperiod, ->get_expiry_date should return enrolmentperiodadate even if a parameter is given' ); |
| 77 |
|
| 78 |
$category->enrolmentperiod( 12 )->store; |
| 79 |
is( t::lib::Dates::compare($category->get_expiry_date, $next_year), 0, 'With enrolmentperiod defined and no parameter, ->get_expiry_date should return today + enrolmentperiod' ); |
| 80 |
is( t::lib::Dates::compare($category->get_expiry_date( $yesterday ), $next_year->clone->add( days => -1 )), 0, 'With enrolmentperiod defined and a date given in parameter, ->get_expiry_date should take this date + enrolmentperiod' ); |
| 81 |
|
75 |
|
| 82 |
my $hardcoded_date = '2000-01-31'; |
76 |
my $hardcoded_date = '2000-01-31'; |
| 83 |
is( t::lib::Dates::compare($category->get_expiry_date( $hardcoded_date ), dt_from_string( $hardcoded_date )->add( months => 12 )), 0, 'get_expiry_date accepts strings as well' ); |
77 |
is( $category->get_expiry_date, $enrolementperioddate, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' ); |
|
|
78 |
is( $category->get_expiry_date( $hardcoded_date ), $enrolementperioddate, 'Without enrolmentperiod, ->get_expiry_date should return enrolmentperiodadate even if a parameter is given' ); |
| 84 |
|
79 |
|
|
|
80 |
$category->enrolmentperiod( 12 )->store; |
| 81 |
is( t::lib::Dates::compare($category->get_expiry_date( $hardcoded_date ), dt_from_string( $hardcoded_date )->add( months => 12 )), 0, 'get_expiry_date accepts strings as well' ); |
| 85 |
$category->delete; |
82 |
$category->delete; |
|
|
83 |
|
| 84 |
for my $date ( '2016-03-31', '2016-11-30', '2019-01-31', '2019-03-01', '2020-02-28', '2020-01-31', '2020-02-29', dt_from_string()->truncate( to => 'day') ) { |
| 85 |
my $dt = dt_from_string( $date, 'iso' ); |
| 86 |
Time::Fake->offset( $dt->epoch ); |
| 87 |
|
| 88 |
$enrolementperioddate = $dt->clone->add( months => 1 , end_of_month => 'limit' )->truncate( to => 'day' ); |
| 89 |
$category = Koha::Patron::Category->new({ |
| 90 |
categorycode => 'mycat', |
| 91 |
category_type => 'A', |
| 92 |
description => 'mycatdesc', |
| 93 |
enrolmentperiod => 12, |
| 94 |
enrolmentperioddate => $enrolementperioddate, |
| 95 |
})->store; |
| 96 |
|
| 97 |
my $a_year_later = $dt->clone->add( months => 12, end_of_month => 'limit' )->truncate( to => 'day' ); |
| 98 |
my $a_day_earlier = $dt->clone->subtract( days => 1, end_of_month => 'limit' )->truncate( to => 'day' ); |
| 99 |
my $a_day_earlier_plus_a_year = $a_day_earlier->clone->add( months => 12, end_of_month => 'limit' )->truncate( to => 'day' ); |
| 100 |
|
| 101 |
is( t::lib::Dates::compare($category->get_expiry_date, $a_year_later), 0, 'With enrolmentperiod defined and no parameter, ->get_expiry_date should return today + enrolmentperiod' ); |
| 102 |
is( t::lib::Dates::compare($category->get_expiry_date( $a_day_earlier ), $a_day_earlier_plus_a_year), 0, 'With enrolmentperiod defined and a date given in parameter, ->get_expiry_date should take this date + enrolmentperiod' ); |
| 103 |
|
| 104 |
$category->delete; |
| 105 |
Time::Fake->reset; |
| 106 |
} |
| 86 |
}; |
107 |
}; |
| 87 |
|
108 |
|
| 88 |
subtest 'BlockExpiredPatronOpacActions' => sub { |
109 |
subtest 'BlockExpiredPatronOpacActions' => sub { |
| 89 |
- |
|
|