From 36d6dec267acfb0cbe2e34082681aac4b929d879 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 that have the can_reset_password flag set, and returns a boolean representing the fact that there's at least one category with the flag set. 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 --- Koha/Template/Plugin/Categories.pm | 9 +++++++++ t/db_dependent/Template/Plugin/Categories.t | 20 +++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/Koha/Template/Plugin/Categories.pm b/Koha/Template/Plugin/Categories.pm index 97165001e4..6f012c0a32 100644 --- a/Koha/Template/Plugin/Categories.pm +++ b/Koha/Template/Plugin/Categories.pm @@ -33,6 +33,10 @@ sub GetName { return Koha::Patron::Categories->find( $categorycode )->description; } +sub can_any_reset_password { + return ( Koha::Patron::Categories->search( { can_reset_password => 1 } )->count > 0 ); +} + 1; =head1 NAME @@ -57,6 +61,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 flag set. 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..65f1f8669c 100644 --- a/t/db_dependent/Template/Plugin/Categories.t +++ b/t/db_dependent/Template/Plugin/Categories.t @@ -17,7 +17,7 @@ use Modern::Perl; -use Test::More tests => 4; +use Test::More tests => 5; use t::lib::TestBuilder; use Koha::Patron::Categories; @@ -57,3 +57,21 @@ is( Koha::Template::Plugin::Categories->GetName( $schema->storage->txn_rollback; +subtest 'can_any_reset_password() tests' => sub { + + plan tests => 2; + + $schema->storage->txn_begin; + + # Make sure all existing categories have can_reset_password set to 0 + Koha::Patron::Categories->update({ can_reset_password => 0 }); + + ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' ); + + $builder->build_object({ class => 'Koha::Patron::Categories', value => { can_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' ); + + $schema->storage->txn_rollback; +}; + -- 2.20.1