|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
|
| 3 |
# This file is part of Koha. |
| 4 |
# |
| 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 |
| 8 |
# version. |
| 9 |
# |
| 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. |
| 13 |
# |
| 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>. |
| 16 |
|
| 17 |
use Modern::Perl; |
| 18 |
|
| 19 |
use Test::More tests => 5; |
| 20 |
use Test::Exception; |
| 21 |
|
| 22 |
use File::Basename; |
| 23 |
|
| 24 |
use C4::Items; |
| 25 |
|
| 26 |
use t::lib::Mocks; |
| 27 |
use t::lib::TestBuilder; |
| 28 |
|
| 29 |
BEGIN { |
| 30 |
# Mock pluginsdir before loading Plugins module |
| 31 |
my $path = dirname(__FILE__) . '/../../../lib'; |
| 32 |
t::lib::Mocks::mock_config( 'pluginsdir', $path ); |
| 33 |
|
| 34 |
use_ok('Koha::Plugins'); |
| 35 |
use_ok('Koha::Plugins::Handler'); |
| 36 |
use_ok('Koha::Plugin::Test'); |
| 37 |
use_ok('Koha::Patron'); |
| 38 |
} |
| 39 |
|
| 40 |
my $schema = Koha::Database->new->schema; |
| 41 |
my $builder = t::lib::TestBuilder->new; |
| 42 |
|
| 43 |
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 ); |
| 44 |
t::lib::Mocks::mock_config( 'enable_plugins', 1 ); |
| 45 |
|
| 46 |
subtest 'check_password hook tests' => sub { |
| 47 |
|
| 48 |
plan tests => 5; |
| 49 |
|
| 50 |
$schema->storage->txn_begin; |
| 51 |
|
| 52 |
my $plugins = Koha::Plugins->new; |
| 53 |
$plugins->InstallPlugins; |
| 54 |
|
| 55 |
my $plugin = Koha::Plugin::Test->new->enable; |
| 56 |
|
| 57 |
my $library = $builder->build( { source => 'Branch' } ); |
| 58 |
my $category = $builder->build( { source => 'Category' } ); |
| 59 |
my $patron = Koha::Patron->new( |
| 60 |
{ |
| 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', |
| 67 |
password => "exploder", |
| 68 |
} |
| 69 |
); |
| 70 |
|
| 71 |
throws_ok { $patron->store } 'Koha::Exceptions::Password::Plugin', |
| 72 |
'Exception raised for adding patron with bad password'; |
| 73 |
$patron->password('1234'); |
| 74 |
ok( $patron->store, 'Patron created with good password' ); |
| 75 |
|
| 76 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', '0' ); |
| 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'); |
| 81 |
|
| 82 |
$schema->storage->txn_rollback; |
| 83 |
Koha::Plugins::Methods->delete; |
| 84 |
}; |
| 85 |
|
| 86 |
1; |