3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 3 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along
15 # with Koha; if not, see <http://www.gnu.org/licenses>.
19 use Test::More tests => 5;
27 use t::lib::TestBuilder;
30 # Mock pluginsdir before loading Plugins module
31 my $path = dirname(__FILE__) . '/../../../lib';
32 t::lib::Mocks::mock_config( 'pluginsdir', $path );
34 use_ok('Koha::Plugins');
35 use_ok('Koha::Plugins::Handler');
36 use_ok('Koha::Plugin::Test');
37 use_ok('Koha::Patron');
40 my $schema = Koha::Database->new->schema;
41 my $builder = t::lib::TestBuilder->new;
43 t::lib::Mocks::mock_config( 'enable_plugins', 1 );
45 subtest 'check_password hook tests' => sub {
49 $schema->storage->txn_begin;
51 my $plugins = Koha::Plugins->new;
52 $plugins->InstallPlugins;
54 # Test Plugin enforces a 4 digit numeric pin for passwords
55 my $plugin = Koha::Plugin::Test->new->enable;
57 my $library = $builder->build( { source => 'Branch' } );
58 my $category = $builder->build( { source => 'Category' } );
59 my $patron = Koha::Patron->new(
61 cardnumber => 'test_cn_1',
62 branchcode => $library->{branchcode},
63 categorycode => $category->{categorycode},
64 surname => 'surname for patron1',
65 firstname => 'firstname for patron1',
66 userid => 'a_nonexistent_userid_1',
70 # store hook (add action)
71 $patron->password('exploder');
72 throws_ok { $patron->store } 'Koha::Exceptions::Password::Plugin',
73 'Plugin Exception raised for adding patron with bad password';
74 $patron->password('1234');
75 ok( $patron->store, 'Patron created with good password' );
77 $patron->discard_changes;
78 $patron->password('87654321');
80 isnt($patron->password, '87654321', 'Koha::Patron->store silently drops changes to password');
82 # set_password hook (update action)
83 t::lib::Mocks::mock_preference( 'RequireStrongPassword', '0' );
84 t::lib::Mocks::mock_preference( 'minPasswordLength', '4' ); # Testing Plugin validation, not internal validation
85 throws_ok { $patron->set_password({ password => 'explosion' }) } 'Koha::Exceptions::Password::Plugin',
86 'Exception raised for update patron password with bad string';
87 ok( $patron->set_password({ password => '4321' }), 'Patron password updated with good string' );
88 ok( $patron->set_password({ password => 'explosion', skip_validation => 1}), 'Patron password updated via skip validation');
90 $schema->storage->txn_rollback;
91 Koha::Plugins::Methods->delete;