View | Details | Raw Unified | Return to bug 21890
Collapse All | Expand All

(-)a/Koha/Template/Plugin/Categories.pm (+9 lines)
Lines 33-38 sub GetName { Link Here
33
    return Koha::Patron::Categories->find( $categorycode )->description;
33
    return Koha::Patron::Categories->find( $categorycode )->description;
34
}
34
}
35
35
36
sub can_any_reset_password {
37
    return ( Koha::Patron::Categories->search( { can_reset_password => 1 } )->count > 0 );
38
}
39
36
1;
40
1;
37
41
38
=head1 NAME
42
=head1 NAME
Lines 57-62 the following TT code: [% Categories.all() %] Link Here
57
In a template, you can get the name of a patron category using
61
In a template, you can get the name of a patron category using
58
[% Categories.GetName( categorycode ) %].
62
[% Categories.GetName( categorycode ) %].
59
63
64
=head2 can_any_reset_password
65
66
Returns I<true> is any patron category has the I<can_reset_password> flag set. Returns
67
I<false> otherwise.
68
60
=head1 AUTHOR
69
=head1 AUTHOR
61
70
62
Jonathan Druart <jonathan.druart@biblibre.com>
71
Jonathan Druart <jonathan.druart@biblibre.com>
(-)a/t/db_dependent/Template/Plugin/Categories.t (-2 / +18 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 4;
20
use Test::More tests => 5;
21
use t::lib::TestBuilder;
21
use t::lib::TestBuilder;
22
22
23
use Koha::Patron::Categories;
23
use Koha::Patron::Categories;
Lines 57-59 is( Koha::Template::Plugin::Categories->GetName( Link Here
57
57
58
$schema->storage->txn_rollback;
58
$schema->storage->txn_rollback;
59
59
60
- 
60
subtest 'can_any_reset_password() tests' => sub {
61
62
    plan tests => 2;
63
64
    $schema->storage->txn_begin;
65
66
    # Make sure all existing categories have can_reset_password set to 0
67
    Koha::Patron::Categories->update({ can_reset_password => 0 });
68
69
    ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' );
70
71
    $builder->build_object({ class => 'Koha::Patron::Categories', value => { can_reset_password => 1 } });
72
73
    ok( Koha::Template::Plugin::Categories->new->can_any_reset_password, 'There\'s at least a category that is allowed to reset password' );
74
75
    $schema->storage->txn_rollback;
76
};

Return to bug 21890