Lines 16-101
Link Here
|
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
16 |
# along with Koha; if not, see <http://www.gnu.org/licenses>. |
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
use Test::More tests => 1; |
20 |
use Test::More tests => 4; |
|
|
21 |
|
22 |
use Test::MockModule; |
23 |
use Test::Exception; |
24 |
use Test::Warn; |
25 |
|
26 |
use Koha::Patrons; |
27 |
use Koha::Patron::Allowlist; |
20 |
use Koha::Patron::Allowlist; |
28 |
|
21 |
|
29 |
use t::lib::Mocks; |
22 |
subtest 'Patron::Allowlist' => sub { |
|
|
23 |
plan tests => 12; |
30 |
|
24 |
|
31 |
subtest '_get_all_fields' => sub { |
25 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1', gonenoaddress => 1, unexist => 2 }; |
32 |
my @columns = Koha::Patrons->columns; |
|
|
33 |
is_deeply( |
34 |
\@columns, |
35 |
[ Koha::Patron::Allowlist->_get_all_fields ], |
36 |
'All DB columns must be listed in _get_all_fields' |
37 |
); |
38 |
}; |
39 |
|
40 |
subtest 'Staff Allowlist' => sub { |
41 |
plan tests => 4; |
42 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' }; |
43 |
my $allowlist = Koha::Patron::Allowlist->new({ interface => 'staff' }); |
26 |
my $allowlist = Koha::Patron::Allowlist->new({ interface => 'staff' }); |
44 |
warning_like { |
27 |
my $blocked = $allowlist->apply({ input => $input }); |
45 |
$allowlist->apply({ input => $input, }); |
|
|
46 |
} qr{Forbidden - Tried to modify 'flags' with '1' from}; |
47 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
48 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
49 |
is( $input->{flags}, undef, 'flags filtered' ); |
50 |
}; |
51 |
|
52 |
subtest 'Public Allowlist' => sub { |
53 |
plan tests => 4; |
54 |
my $input = { firstname => 'test firstname', surname => 'test surname', flags => '1' }; |
55 |
my $allowlist = Koha::Patron::Allowlist->new(); |
56 |
warning_like { |
57 |
$allowlist->apply({ input => $input, }); |
58 |
} qr{Forbidden - Tried to modify 'flags' with '1' from}; |
59 |
|
28 |
|
60 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
29 |
is( $blocked->{unexist}, 2, "Unexist got blocked" ); |
61 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
30 |
is( $input->{unexist}, undef, 'unexist filtered' ); |
|
|
31 |
is( $blocked->{flags}, 1, "Flags got blocked" ); |
62 |
is( $input->{flags}, undef, 'flags filtered' ); |
32 |
is( $input->{flags}, undef, 'flags filtered' ); |
63 |
}; |
|
|
64 |
|
65 |
subtest 'additional_deny_list' => sub { |
66 |
plan tests => 10; |
67 |
|
68 |
my $input = { firstname => 'test firstname', surname => 'test surname' }; |
69 |
my $allowlist = Koha::Patron::Allowlist->new(); |
70 |
|
71 |
$allowlist->apply({ |
72 |
input => $input, |
73 |
additional_deny_list => [], |
74 |
}); |
75 |
|
76 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
33 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
77 |
is( $input->{surname}, 'test surname', 'surname filtered' ); |
34 |
is( $input->{surname}, 'test surname', 'surname preserved' ); |
78 |
is( $input->{flags}, undef, 'flags filtered' ); |
35 |
is( $input->{gonenoaddress}, 1, 'gonenoaddress preserved on staff' ); |
79 |
|
36 |
|
80 |
$allowlist->apply({ |
37 |
$input = { firstname => 'test firstname', surname => 'test surname', flags => '1', gonenoaddress => 1, unexist => 2 }; |
81 |
input => $input, |
38 |
my $opacallowlist = Koha::Patron::Allowlist->new; |
82 |
additional_deny_list => ['not_here'], |
39 |
$blocked = $opacallowlist->apply({ input => $input }); |
83 |
}); |
40 |
is( $blocked->{unexist}, 2, "Unexist got blocked on opac too"); |
84 |
|
41 |
is( $blocked->{flags}, 1, "Flags got blocked on opac too" ); |
85 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
42 |
is( $blocked->{gonenoaddress}, 1, "Gonenoaddress got blocked on opac now" ); |
86 |
is( $input->{surname}, 'test surname', 'surname filtered' ); |
43 |
is( $input->{gonenoaddress}, undef, 'gonenoaddress filtered, opac' ); |
87 |
is( $input->{flags}, undef, 'flags filtered' ); |
44 |
is( $input->{surname}, 'test surname', 'surname preserved, opac' ); |
88 |
|
|
|
89 |
warning_like { |
90 |
$allowlist->apply({ |
91 |
input => $input, |
92 |
additional_deny_list => ['surname'], |
93 |
}); |
94 |
} |
95 |
qr{Forbidden - Tried to modify 'surname' with 'test surname' from}; |
96 |
|
97 |
is( $input->{firstname}, 'test firstname', 'firstname preserved' ); |
98 |
is( $input->{surname}, undef, 'surname filtered' ); |
99 |
is( $input->{flags}, undef, 'flags filtered' ); |
100 |
|
101 |
}; |
45 |
}; |
102 |
- |
46 |
|
|
|
47 |
#subtest 'Additional adds or removes' => sub { |
48 |
# |