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 |
}; |