3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 5;
22 use t::lib::TestBuilder;
24 use Koha::Patron::Categories;
28 use Koha::Template::Plugin::Categories;
30 my $schema = Koha::Database->new->schema;
31 $schema->storage->txn_begin;
33 # Delete all categories
34 Koha::Checkouts->search->delete;
35 Koha::Patrons->search->delete;
36 Koha::Patron::Categories->search->delete;
38 my $builder = t::lib::TestBuilder->new;
40 is( Koha::Template::Plugin::Categories->new->all->count,
41 0, '->all returns 0 results if no categories defined' );
43 # Create sample categories
44 my $category_1 = $builder->build( { source => 'Category' } );
45 my @categories = Koha::Template::Plugin::Categories->new->all;
46 is( scalar(@categories), 1, '->all returns all defined categories' );
48 my $category_2 = $builder->build( { source => 'Category' } );
49 @categories = Koha::Template::Plugin::Categories->new->all;
50 is( scalar(@categories), 2, '->all returns all defined categories' );
52 is( Koha::Template::Plugin::Categories->GetName(
53 $category_1->{categorycode}
55 $category_1->{description},
56 '->GetName returns the right description'
59 $schema->storage->txn_rollback;
61 subtest 'can_any_reset_password() tests' => sub {
65 $schema->storage->txn_begin;
67 # Make sure all existing categories have reset_password set to 0
68 Koha::Patron::Categories->update({ reset_password => 0 });
70 ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' );
72 t::lib::Mocks::mock_preference( 'OpacResetPassword', 0 );
74 my $category = $builder->build_object({ class => 'Koha::Patron::Categories', value => { reset_password => 1 } });
76 ok( Koha::Template::Plugin::Categories->new->can_any_reset_password, 'There\'s at least a category that is allowed to reset password' );
78 $category->reset_password( undef )->store;
80 ok( !Koha::Template::Plugin::Categories->new->can_any_reset_password, 'No category is allowed to reset password' );
82 $schema->storage->txn_rollback;