Browse Source

Bug 10796: Add Koha::Patron::Category->effective_change_password method

This method checks whether the local $self->change_password is set to
override the OpacPasswordChange syspref (i.e. if it is set to a
bool) or undef, in which case it falls back to the value of the syspref

To test:
- Apply this patches
- Make sure the DB is updated:
  $ updatedatabase
- Update the schema files:
  $ dbic
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/Patron/Category.t
=> SUCCESS: Tests pass!
- Sign off :-D

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
19.05.x
Tomás Cohen Arazi 5 years ago
committed by Nick Clemens
parent
commit
a6466f1f3b
  1. 15
      Koha/Patron/Category.pm
  2. 60
      t/db_dependent/Koha/Patron/Category.t

15
Koha/Patron/Category.pm

@ -239,6 +239,21 @@ sub effective_reset_password {
: C4::Context->preference('OpacResetPassword');
}
=head3 effective_change_password
Returns if patrons in this category can change their password. If set in $self->change_password
or, if undef, falls back to the OpacPasswordChange system preference.
=cut
sub effective_change_password {
my ($self) = @_;
return ( defined $self->change_password )
? $self->change_password
: C4::Context->preference('OpacPasswordChange');
}
=head2 Internal methods
=head3 type

60
t/db_dependent/Koha/Patron/Category.t

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::More tests => 1;
use Test::More tests => 2;
use t::lib::TestBuilder;
use t::lib::Mocks;
@ -86,3 +86,61 @@ subtest 'effective_reset_password() tests' => sub {
$schema->storage->txn_rollback;
};
};
subtest 'effective_change_password() tests' => sub {
plan tests => 2;
subtest 'specific overrides global' => sub {
plan tests => 4;
$schema->storage->txn_begin;
my $category = $builder->build_object({
class => 'Koha::Patron::Categories',
value => {
change_password => 1
}
});
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
ok( $category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 1' );
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
ok( $category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 1' );
# disable
$category->change_password( 0 )->store->discard_changes;
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
ok( !$category->effective_change_password, 'OpacPasswordChange unset, but category has the flag set to 0' );
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
ok( !$category->effective_change_password, 'OpacPasswordChange set and category has the flag set to 0' );
$schema->storage->txn_rollback;
};
subtest 'no specific rule, global applies' => sub {
plan tests => 2;
$schema->storage->txn_begin;
my $category = $builder->build_object({
class => 'Koha::Patron::Categories',
value => {
change_password => undef
}
});
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 0 );
ok( !$category->effective_change_password, 'OpacPasswordChange set to 0 used' );
t::lib::Mocks::mock_preference( 'OpacPasswordChange', 1 );
ok( $category->effective_change_password, 'OpacPasswordChange set to 1 used' );
$schema->storage->txn_rollback;
};
};

Loading…
Cancel
Save