Line 0
Link Here
|
|
|
1 |
#!/usr/bin/perl |
2 |
|
3 |
# This file is part of Koha. |
4 |
# |
5 |
# Koha is free software; you can redistribute it and/or modify it |
6 |
# under the terms of the GNU General Public License as published by |
7 |
# the Free Software Foundation; either version 3 of the License, or |
8 |
# (at your option) any later version. |
9 |
# |
10 |
# Koha is distributed in the hope that it will be useful, but |
11 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
# GNU General Public License for more details. |
14 |
# |
15 |
# You should have received a copy of the GNU General Public License |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
18 |
use Modern::Perl; |
19 |
use Test::More tests => 2; |
20 |
|
21 |
use Koha::Allowlist; |
22 |
use Koha::Patron::Allowlist; |
23 |
|
24 |
subtest 'Allowlist' => sub { |
25 |
plan tests => 7; |
26 |
|
27 |
my $allowlist = Koha::Allowlist->new; |
28 |
$allowlist->load; |
29 |
is( $allowlist->apply, undef, 'No input returns undef' ); |
30 |
is( %{$allowlist->apply({ input => {} })}, 0, 'Empty hash returns nothing blocked' ); |
31 |
|
32 |
my @input = ( col1 => 1, col2 => 2, col3 => 3, col4 => 4 ); |
33 |
my $blocked = $allowlist->apply({ input => { @input } }); |
34 |
is( keys %$blocked, 4, 'Empty list blocks all' ); |
35 |
$allowlist->add( 'col1' ); |
36 |
$blocked = $allowlist->apply({ input => { @input } }); |
37 |
is( keys %$blocked, 3, 'One field allowed' ); |
38 |
is( $blocked->{col1}, undef, 'And that is col1' ); |
39 |
$allowlist->remove( 'col1' ); |
40 |
$blocked = $allowlist->apply({ input => { @input } }); |
41 |
is( keys %$blocked, 4, 'Back to 4 after removing col1' ); |
42 |
$allowlist->add( 'col2' ); |
43 |
$allowlist->unload; |
44 |
$blocked = $allowlist->apply({ input => { @input } }); |
45 |
is( keys %$blocked, 4, 'Same after unloading' ); |
46 |
}; |
47 |
|
48 |
subtest 'Patron::Allowlist' => sub { |
49 |
plan tests => 12; |
50 |
|
51 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1', gonenoaddress => 1, unexist => 2 }; |
52 |
my $allowlist = Koha::Patron::Allowlist->new({ interface => 'staff' }); |
53 |
$allowlist->load; |
54 |
my $blocked = $allowlist->apply({ input => $input }); |
55 |
|
56 |
is( $blocked->{unexist}, 2, "Unexist got blocked" ); |
57 |
is( $input->{unexist}, undef, 'unexist filtered' ); |
58 |
is( $blocked->{flags}, 1, "Flags got blocked" ); |
59 |
is( $input->{flags}, undef, 'flags filtered' ); |
60 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
61 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
62 |
is( $input->{gonenoaddress}, 1, 'gonenoaddress preserved on staff' ); |
63 |
|
64 |
$input = { firstname => 'test firstname', surname => 'test surname', flags => '1', gonenoaddress => 1, unexist => 2 }; |
65 |
my $opacallowlist = Koha::Patron::Allowlist->new; |
66 |
$opacallowlist->load; |
67 |
$blocked = $opacallowlist->apply({ input => $input }); |
68 |
is( $blocked->{unexist}, 2, "Unexist got blocked on opac too"); |
69 |
is( $blocked->{flags}, 1, "Flags got blocked on opac too" ); |
70 |
is( $blocked->{gonenoaddress}, 1, "Gonenoaddress got blocked on opac now" ); |
71 |
is( $input->{gonenoaddress}, undef, 'gonenoaddress filtered, opac' ); |
72 |
is( $input->{surname}, 'test surname', 'surname preserved, opac' ); |
73 |
}; |