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

(-)a/Koha/Patron/Category.pm (+15 lines)
Lines 239-244 sub effective_reset_password { Link Here
239
        : C4::Context->preference('OpacResetPassword');
239
        : C4::Context->preference('OpacResetPassword');
240
}
240
}
241
241
242
=head3 effective_change_password
243
244
Returns if patrons in this category can change their password. If set in $self->change_password
245
or, if undef, falls back to the OpacPasswordChange system preference.
246
247
=cut
248
249
sub effective_change_password {
250
    my ($self) = @_;
251
252
    return ( defined $self->change_password )
253
        ? $self->change_password
254
        : C4::Context->preference('OpacPasswordChange');
255
}
256
242
=head2 Internal methods
257
=head2 Internal methods
243
258
244
=head3 type
259
=head3 type
(-)a/t/db_dependent/Koha/Patron/Category.t (-2 / +59 lines)
Lines 19-25 Link Here
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
21
22
use Test::More tests => 1;
22
use Test::More tests => 2;
23
23
24
use t::lib::TestBuilder;
24
use t::lib::TestBuilder;
25
use t::lib::Mocks;
25
use t::lib::Mocks;
Lines 86-88 subtest 'effective_reset_password() tests' => sub { Link Here
86
        $schema->storage->txn_rollback;
86
        $schema->storage->txn_rollback;
87
    };
87
    };
88
};
88
};
89
- 
89
90
subtest 'effective_change_password() tests' => sub {
91
92
    plan tests => 2;
93
94
    subtest 'specific overrides global' => sub {
95
96
        plan tests => 4;
97
98
        $schema->storage->txn_begin;
99
100
        my $category = $builder->build_object({
101
            class => 'Koha::Patron::Categories',
102
            value => {
103
                change_password => 1
104
            }
105
        });
106
107
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
108
        ok( $category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 1' );
109
110
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
111
        ok( $category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 1' );
112
113
        # disable
114
        $category->change_password( 0 )->store->discard_changes;
115
116
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
117
        ok( !$category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 0' );
118
119
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
120
        ok( !$category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 0' );
121
122
        $schema->storage->txn_rollback;
123
    };
124
125
    subtest 'no specific rule, global applies' => sub {
126
127
        plan tests => 2;
128
129
        $schema->storage->txn_begin;
130
131
        my $category = $builder->build_object({
132
            class => 'Koha::Patron::Categories',
133
            value => {
134
                change_password => undef
135
            }
136
        });
137
138
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
139
        ok( !$category->effective_change_password, 'OpacPasswordChange set to 0 used' );
140
141
        t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
142
        ok( $category->effective_change_password, 'OpacPasswordChange set to 1 used' );
143
144
        $schema->storage->txn_rollback;
145
    };
146
};

Return to bug 10796