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 my $plugin = Koha
::Plugin
::Test
->new->enable;
56 my $library = $builder->build( { source
=> 'Branch' } );
57 my $category = $builder->build( { source
=> 'Category' } );
58 my $patron = Koha
::Patron
->new(
60 cardnumber
=> 'test_cn_1',
61 branchcode
=> $library->{branchcode
},
62 categorycode
=> $category->{categorycode
},
63 surname
=> 'surname for patron1',
64 firstname
=> 'firstname for patron1',
65 userid
=> 'a_nonexistent_userid_1',
66 password
=> "exploder",
70 throws_ok
{ $patron->store } 'Koha::Exceptions::Password::Plugin',
71 'Exception raised for adding patron with bad password';
72 $patron->password('12345678');
73 ok
( $patron->store, 'Patron created with good password' );
75 t
::lib
::Mocks
::mock_preference
( 'RequireStrongPassword', '0' );
76 t
::lib
::Mocks
::mock_preference
( 'minPasswordLength', '3' );
77 throws_ok
{ $patron->set_password({ password
=> 'explosion' }) } 'Koha::Exceptions::Password::Plugin',
78 'Exception raised for update patron password with bad string';
79 ok
( $patron->set_password({ password
=> '4321' }), 'Patron password updated with good string' );
80 ok
( $patron->set_password({ password
=> 'explosion', skip_validation
=> 1}), 'Patron password updated via skip validation');
82 $schema->storage->txn_rollback;
83 Koha
::Plugins
::Methods
->delete;