From e55b627603450313954b98704e73d0baa3ed56f9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 31 Jan 2019 16:27:10 -0300 Subject: [PATCH] Bug 21890: Add can_any_reset_password() to the Categories TT plugin This patch introduces a method to the Koha::Template::Plugin::Categories TT plugin. This methods queries for categories filtering them by effective_reset_password flag set, and returns a boolean representing the fact that there's at least one category allowed. To test: - Apply this patch - Run: $ kshell k$ prove t/db_dependent/Template/Plugin/Categories.t => SUCCESS: Tests pass! - Sign off :-D Caveat: this patch/tests require the schema to be updated Signed-off-by: Liz Rea Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- Koha/Template/Plugin/Categories.pm | 11 +++++++++ t/db_dependent/Template/Plugin/Categories.t | 26 ++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/Categories.pm b/Koha/Template/Plugin/Categories.pm index 97165001e4..f12c660faf 100644 --- a/Koha/Template/Plugin/Categories.pm +++ b/Koha/Template/Plugin/Categories.pm @@ -33,6 +33,12 @@ sub GetName { return Koha::Patron::Categories->find( $categorycode )->description; } +sub can_any_reset_password { + return ( grep { $_->effective_reset_password } @{ Koha::Patron::Categories->search->as_list } ) + ? 1 + : 0; +} + 1; =head1 NAME @@ -57,6 +63,11 @@ the following TT code: [% Categories.all() %] In a template, you can get the name of a patron category using [% Categories.GetName( categorycode ) %]. +=head2 can_any_reset_password + +Returns I is any patron category has the I evaluate to I. +Returns I otherwise. + =head1 AUTHOR Jonathan Druart diff --git a/t/db_dependent/Template/Plugin/Categories.t b/t/db_dependent/Template/Plugin/Categories.t index 6ea75f8d5f..93384deda4 100644 --- a/t/db_dependent/Template/Plugin/Categories.t +++ b/t/db_dependent/Template/Plugin/Categories.t @@ -17,7 +17,8 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; +use t::lib::Mocks; use t::lib::TestBuilder; use Koha::Patron::Categories; @@ -57,3 +58,26 @@ is( Koha::Template::Plugin::Categories->GetName( $schema->storage->txn_rollback; +subtest 'can_any_reset_password() tests' => sub { + + plan tests => 3; + + $schema->storage->txn_begin; + + # Make sure all existing categories have reset_password set to 0 + Koha::Patron::Categories->update({ reset_password => 0 }); + + ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' ); + + t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 ); + + my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { reset_password => 1 } }); + + ok( Koha::Template::Plugin::Categories->new->can_any_reset_password, 'There\'s at least a category that is allowed to reset password' ); + + $category->reset_password( undef )->store; + + ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' ); + + $schema->storage->txn_rollback; +}; -- 2.39.5