View | Details | Raw Unified | Return to bug 22446
Collapse All | Expand All

(-)a/t/db_dependent/Koha/Patron/Categories.t (-22 / +30 lines)
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 62-88 is( $retrieved_category_2->checkprevcheckout, 'inherit', 'Koha::Patron::Category Link Here
62
63
63
subtest 'get_expiry_date' => sub {
64
subtest 'get_expiry_date' => sub {
64
    plan tests => 5;
65
    plan tests => 5;
65
    my $next_month = dt_from_string->add( months => 1 );
66
    for my $date ( '2016-03-31', '2016-11-30', '2019-01-31', '2019-03-01', dt_from_string() ) {
66
    my $next_year = dt_from_string->add( months => 12 );
67
        subtest "get_expiry_date with today=$date" => sub {
67
    my $yesterday = dt_from_string->add( days => -1 );
68
            plan tests => 5;
68
    my $category = Koha::Patron::Category->new({
69
            my $dt = dt_from_string( $date, 'iso' );
69
        categorycode => 'mycat',
70
            Time::Fake->offset( $dt->epoch );
70
        category_type => 'A',
71
71
        description  => 'mycatdesc',
72
            my $next_month = dt_from_string->add( months => 1 );
72
        enrolmentperiod => undef,
73
            my $next_year = dt_from_string->add( months => 12 );
73
        enrolmentperioddate => $next_month,
74
            my $yesterday = dt_from_string->add( days => -1 );
74
    })->store;
75
            my $category = Koha::Patron::Category->new({
75
    is( $category->get_expiry_date, $next_month, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' );
76
                categorycode => 'mycat',
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
                category_type => 'A',
77
78
                description  => 'mycatdesc',
78
    $category->enrolmentperiod( 12 )->store;
79
                enrolmentperiod => undef,
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
                enrolmentperioddate => $next_month,
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
            })->store;
81
82
            is( $category->get_expiry_date, $next_month, 'Without enrolmentperiod and parameter, ->get_expiry_date should return enrolmentperioddate' );
82
    my $hardcoded_date = '2000-01-31';
83
            is( $category->get_expiry_date( $next_year ), $next_month, 'Without enrolmentperiod, ->get_expiry_date should return enrolmentperiodadate even if a parameter is given' );
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'  );
84
84
85
            $category->enrolmentperiod( 12 )->store;
85
    $category->delete;
86
            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' );
87
            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' );
88
89
            my $hardcoded_date = '2000-01-31';
90
            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'  );
91
92
            $category->delete;
93
        };
94
    }
86
};
95
};
87
96
88
subtest 'BlockExpiredPatronOpacActions' => sub {
97
subtest 'BlockExpiredPatronOpacActions' => sub {
89
- 

Return to bug 22446