From a6466f1f3b02915f0c4e578ce13455ad3aacf46c Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 20 Feb 2019 13:26:18 -0300 Subject: [PATCH] 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 Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Patron/Category.pm | 15 +++++++ t/db_dependent/Koha/Patron/Category.t | 60 ++++++++++++++++++++++++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Koha/Patron/Category.pm b/Koha/Patron/Category.pm index f614d5b0bc..261b232d33 100644 --- a/Koha/Patron/Category.pm +++ b/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 diff --git a/t/db_dependent/Koha/Patron/Category.t b/t/db_dependent/Koha/Patron/Category.t index 1b4938e9f9..06fe7ecace 100644 --- a/t/db_dependent/Koha/Patron/Category.t +++ b/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; + }; +}; -- 2.39.5