|
Line 0
Link Here
|
| 0 |
- |
1 |
#!/usr/bin/perl |
|
|
2 |
# |
| 3 |
# This Koha test module is a stub! |
| 4 |
|
| 5 |
use Modern::Perl; |
| 6 |
|
| 7 |
use CGI qw ( -utf8 ); |
| 8 |
|
| 9 |
use t::lib::Mocks; |
| 10 |
use t::lib::TestBuilder; |
| 11 |
use Test::MockObject; |
| 12 |
use Test::MockModule; |
| 13 |
|
| 14 |
use C4::Auth qw(checkpw); |
| 15 |
|
| 16 |
use Test::More tests => 1; |
| 17 |
|
| 18 |
my $schema = Koha::Database->schema; |
| 19 |
my $builder = t::lib::TestBuilder->new; |
| 20 |
my $dbh = C4::Context->dbh; |
| 21 |
|
| 22 |
t::lib::Mocks::mock_preference( 'SessionStorage', 'tmp' ); |
| 23 |
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 0 ); |
| 24 |
|
| 25 |
$schema->storage->txn_begin; |
| 26 |
|
| 27 |
subtest 'no_set_userenv parameter tests' => sub { |
| 28 |
|
| 29 |
plan tests => 12; |
| 30 |
|
| 31 |
my $library = $builder->build_object( { class => 'Koha::Libraries' } ); |
| 32 |
my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); |
| 33 |
my $password = 'password'; |
| 34 |
|
| 35 |
t::lib::Mocks::mock_preference( 'RequireStrongPassword', 0 ); |
| 36 |
$patron->set_password({ password => $password }); |
| 37 |
|
| 38 |
ok( checkpw( $dbh, $patron->userid, $password, undef, undef, 1 ), 'checkpw returns true' ); |
| 39 |
is( C4::Context->userenv, undef, 'Userenv should be undef as required' ); |
| 40 |
C4::Context->_new_userenv('DUMMY SESSION'); |
| 41 |
|
| 42 |
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', ''); |
| 43 |
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' ); |
| 44 |
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' ); |
| 45 |
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' ); |
| 46 |
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' ); |
| 47 |
#isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' ); |
| 48 |
|
| 49 |
t::lib::Mocks::mock_preference( 'UseKohaPlugins', 1 ); |
| 50 |
my @result = checkpw( $dbh, $patron->{userid}, 'wrong_password', undef, undef, 1 ); |
| 51 |
is( $result[0], 0, 'With TestAuth plugin, checkpw returns 0' ); |
| 52 |
is( $result[1], undef, 'With TestAuth plugin, checkpw returns empty cardnumber' ); |
| 53 |
is( $result[2], undef, 'With TestAuth plugin, checkpw returns empty userid' ); |
| 54 |
@result = checkpw( $dbh, 'test', 'test', undef, undef, 1 ); |
| 55 |
is( $result[0], 1, 'With TestAuth plugin, checkpw returns 1' ); |
| 56 |
is( $result[1], 'test', 'With TestAuth plugin, checkpw returns test cardnumber' ); |
| 57 |
is( $result[2], 'test', 'With TestAuth plugin, checkpw returns test userid' ); |
| 58 |
} |