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

(-)a/Koha/Patron/Category.pm (+17 lines)
Lines 224-229 sub get_expiry_date { Link Here
224
    }
224
    }
225
}
225
}
226
226
227
=head3 effective_reset_password
228
229
Returns if patrons in this category can reset their password. If set in $self->reset_password
230
or, if undef, falls back to the OpacResetPassword system preference.
231
232
=cut
233
234
sub effective_reset_password {
235
    my ($self) = @_;
236
237
    return ( defined $self->reset_password )
238
        ? $self->reset_password
239
        : C4::Context->preference('OpacResetPassword');
240
}
241
242
=head2 Internal methods
243
227
=head3 type
244
=head3 type
228
245
229
=cut
246
=cut
(-)a/t/db_dependent/Koha/Patron/Category.t (-1 / +88 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2019 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
26
27
use Koha::Database;
28
29
my $schema  = Koha::Database->new->schema;
30
my $builder = t::lib::TestBuilder->new;
31
32
subtest 'effective_reset_password() tests' => sub {
33
34
    plan tests => 2;
35
36
    subtest 'specific overrides global' => sub {
37
38
        plan tests => 4;
39
40
        $schema->storage->txn_begin;
41
42
        my $category = $builder->build_object({
43
            class => 'Koha::Patron::Categories',
44
            value => {
45
                reset_password => 1
46
            }
47
        });
48
49
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
50
        ok( $category->effective_reset_password, 'OpacResetPassword unset, but category has the flag set to 1' );
51
52
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
53
        ok( $category->effective_reset_password, 'OpacResetPassword set and category has the flag set to 1' );
54
55
        # disable
56
        $category->reset_password( 0 )->store->discard_changes;
57
58
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
59
        ok( !$category->effective_reset_password, 'OpacResetPassword unset, but category has the flag set to 0' );
60
61
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
62
        ok( !$category->effective_reset_password, 'OpacResetPassword set and category has the flag set to 0' );
63
64
        $schema->storage->txn_rollback;
65
    };
66
67
    subtest 'no specific rule, global applies' => sub {
68
69
        plan tests => 2;
70
71
        $schema->storage->txn_begin;
72
73
        my $category = $builder->build_object({
74
            class => 'Koha::Patron::Categories',
75
            value => {
76
                reset_password => undef
77
            }
78
        });
79
80
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
81
        ok( !$category->effective_reset_password, 'OpacResetPassword set to 0 used' );
82
83
        t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
84
        ok( $category->effective_reset_password, 'OpacResetPassword set to 1 used' );
85
86
        $schema->storage->txn_rollback;
87
    };
88
};

Return to bug 21890