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

(-)a/t/db_dependent/Koha/Patrons.t (-2 / +47 lines)
Lines 19-30 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 6;
22
use Test::More tests => 7;
23
use Test::Warn;
23
use Test::Warn;
24
24
25
use Koha::Patron;
25
use Koha::Patron;
26
use Koha::Patrons;
26
use Koha::Patrons;
27
use Koha::Database;
27
use Koha::Database;
28
use Koha::DateUtils;
29
use Koha::Virtualshelves;
28
30
29
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
30
use t::lib::Mocks;
32
use t::lib::Mocks;
Lines 127-132 subtest 'update_password' => sub { Link Here
127
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' );
129
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->update_password should not have logged' );
128
};
130
};
129
131
132
subtest 'extend_subscription' => sub {
133
    plan tests => 6;
134
    my $a_month_ago                = dt_from_string->add( months => -1 )->truncate( to => 'day' );
135
    my $a_year_later               = dt_from_string->add( months => 12 )->truncate( to => 'day' );
136
    my $a_year_later_minus_a_month = dt_from_string->add( months => 11 )->truncate( to => 'day' );
137
    my $patron_category = $builder->build(
138
        {   source => 'Category',
139
            value  => {
140
                enrolmentperiod     => 12,
141
                enrolmentperioddate => undef,
142
            }
143
        }
144
    );
145
    my $patron = $builder->build(
146
        {   source => 'Borrower',
147
            value  => {
148
                dateexpiry   => $a_month_ago,
149
                categorycode => $patron_category->{categorycode},
150
            }
151
        }
152
    );
153
    my $retrieved_patron = Koha::Patrons->find( $patron->{borrowernumber} );
154
155
    t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'dateexpiry' );
156
    t::lib::Mocks::mock_preference( 'BorrowersLog',              1 );
157
    my $expiry_date = $retrieved_patron->extend_subscription;
158
    is( $expiry_date, $a_year_later_minus_a_month, );
159
    my $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry;
160
    is( dt_from_string($retrieved_expiry_date), $a_year_later_minus_a_month );
161
    my $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
162
    is( $number_of_logs, 1, 'With BorrowerLogs, Koha::Patron->extend_subscription should have logged' );
163
164
    t::lib::Mocks::mock_preference( 'BorrowerRenewalPeriodBase', 'now' );
165
    t::lib::Mocks::mock_preference( 'BorrowersLog',              0 );
166
    $expiry_date = $retrieved_patron->extend_subscription;
167
    is( $expiry_date, $a_year_later, );
168
    $retrieved_expiry_date = Koha::Patrons->find( $patron->{borrowernumber} )->dateexpiry;
169
    is( dt_from_string($retrieved_expiry_date), $a_year_later );
170
    $number_of_logs = $schema->resultset('ActionLog')->search( { module => 'MEMBERS', action => 'RENEW', object => $retrieved_patron->borrowernumber } )->count;
171
    is( $number_of_logs, 1, 'Without BorrowerLogs, Koha::Patron->extend_subscription should not have logged' );
172
173
    $retrieved_patron->delete;
174
};
175
130
$retrieved_patron_1->delete;
176
$retrieved_patron_1->delete;
131
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
177
is( Koha::Patrons->search->count, $nb_of_patrons + 1, 'Delete should have deleted the patron' );
132
178
133
- 

Return to bug 16911