3 # Copyright 2019 Koha Development team
5 # This file is part of Koha
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.
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.
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>.
22 use Test::More tests => 2;
24 use t::lib::TestBuilder;
29 my $schema = Koha::Database->new->schema;
30 my $builder = t::lib::TestBuilder->new;
32 subtest 'effective_reset_password() tests' => sub {
36 subtest 'specific overrides global' => sub {
40 $schema->storage->txn_begin;
42 my $category = $builder->build_object({
43 class => 'Koha::Patron::Categories',
49 t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
50 ok( $category->effective_reset_password, 'OpacResetPassword unset, but category has the flag set to 1' );
52 t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
53 ok( $category->effective_reset_password, 'OpacResetPassword set and category has the flag set to 1' );
56 $category->reset_password( 0 )->store->discard_changes;
58 t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
59 ok( !$category->effective_reset_password, 'OpacResetPassword unset, but category has the flag set to 0' );
61 t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
62 ok( !$category->effective_reset_password, 'OpacResetPassword set and category has the flag set to 0' );
64 $schema->storage->txn_rollback;
67 subtest 'no specific rule, global applies' => sub {
71 $schema->storage->txn_begin;
73 my $category = $builder->build_object({
74 class => 'Koha::Patron::Categories',
76 reset_password => undef
80 t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
81 ok( !$category->effective_reset_password, 'OpacResetPassword set to 0 used' );
83 t::lib::Mocks::mock_preference( 'OpacResetPassword', 1 );
84 ok( $category->effective_reset_password, 'OpacResetPassword set to 1 used' );
86 $schema->storage->txn_rollback;
90 subtest 'effective_change_password() tests' => sub {
94 subtest 'specific overrides global' => sub {
98 $schema->storage->txn_begin;
100 my $category = $builder->build_object({
101 class => 'Koha::Patron::Categories',
107 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
108 ok( $category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 1' );
110 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
111 ok( $category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 1' );
114 $category->change_password( 0 )->store->discard_changes;
116 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
117 ok( !$category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 0' );
119 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
120 ok( !$category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 0' );
122 $schema->storage->txn_rollback;
125 subtest 'no specific rule, global applies' => sub {
129 $schema->storage->txn_begin;
131 my $category = $builder->build_object({
132 class => 'Koha::Patron::Categories',
134 change_password => undef
138 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
139 ok( !$category->effective_change_password, 'OpacPasswordChange set to 0 used' );
141 t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
142 ok( $category->effective_change_password, 'OpacPasswordChange set to 1 used' );
144 $schema->storage->txn_rollback;