Lines 7-13
use CGI qw ( -utf8 );
Link Here
|
7 |
use Test::MockObject; |
7 |
use Test::MockObject; |
8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
9 |
use List::MoreUtils qw/all any none/; |
9 |
use List::MoreUtils qw/all any none/; |
10 |
use Test::More tests => 20; |
10 |
use Test::More tests => 21; |
11 |
use Test::Warn; |
11 |
use Test::Warn; |
12 |
use t::lib::Mocks; |
12 |
use t::lib::Mocks; |
13 |
use t::lib::TestBuilder; |
13 |
use t::lib::TestBuilder; |
Lines 1350-1355
subtest 'AutoLocation' => sub {
Link Here
|
1350 |
|
1350 |
|
1351 |
}; |
1351 |
}; |
1352 |
|
1352 |
|
|
|
1353 |
subtest 'AutoSelfCheckAllowed' => sub { |
1354 |
plan tests => 5; |
1355 |
|
1356 |
my $query = CGI->new; |
1357 |
my $auth = Test::MockModule->new('C4::Auth'); |
1358 |
$auth->mock( 'safe_exit', sub { return } ); |
1359 |
|
1360 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckAllowed', 0 ); |
1361 |
|
1362 |
# Pref is off, cannot access sco |
1363 |
{ |
1364 |
# checkauth will redirect and safe_exit if not authenticated and not authorized |
1365 |
local *STDOUT; |
1366 |
my $stdout; |
1367 |
open STDOUT, '>', \$stdout; |
1368 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
1369 |
{ |
1370 |
template_name => "sco/sco-main.tt", |
1371 |
query => $query, |
1372 |
type => "opac", |
1373 |
flagsrequired => { self_check => "self_checkout_module" }, |
1374 |
} |
1375 |
); |
1376 |
like( $stdout, qr{<title>\s*Log in to your account} ); |
1377 |
close STDOUT; |
1378 |
}; |
1379 |
|
1380 |
# Pref is on from here |
1381 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckAllowed', 1 ); |
1382 |
|
1383 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckID', '' ); |
1384 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckPass', '' ); |
1385 |
|
1386 |
# Credential prefs are empty, cannot access sco |
1387 |
{ |
1388 |
# checkauth will redirect and safe_exit if not authenticated and not authorized |
1389 |
local *STDOUT; |
1390 |
my $stdout; |
1391 |
open STDOUT, '>', \$stdout; |
1392 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
1393 |
{ |
1394 |
template_name => "sco/sco-main.tt", |
1395 |
query => $query, |
1396 |
type => "opac", |
1397 |
flagsrequired => { self_check => "self_checkout_module" }, |
1398 |
} |
1399 |
); |
1400 |
like( $stdout, qr{<title>\s*Log in to your account} ); |
1401 |
close STDOUT; |
1402 |
}; |
1403 |
|
1404 |
my $sco_patron = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 0 } } ); |
1405 |
my $password = set_weak_password($sco_patron); |
1406 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckID', $sco_patron->userid ); |
1407 |
t::lib::Mocks::mock_preference( 'AutoSelfCheckPass', $password ); |
1408 |
|
1409 |
# Credential pref are good but patron does not have the self_checkout_module subpermission |
1410 |
{ |
1411 |
# checkauth will redirect and safe_exit if not authenticated and not authorized |
1412 |
local *STDOUT; |
1413 |
my $stdout; |
1414 |
open STDOUT, '>', \$stdout; |
1415 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
1416 |
{ |
1417 |
template_name => "sco/sco-main.tt", |
1418 |
query => $query, |
1419 |
type => "opac", |
1420 |
flagsrequired => { self_check => "self_checkout_module" }, |
1421 |
} |
1422 |
); |
1423 |
like( $stdout, qr{<title>\s*Log in to your account} ); |
1424 |
close STDOUT; |
1425 |
}; |
1426 |
|
1427 |
# All good from now |
1428 |
C4::Context->dbh->do( |
1429 |
q| |
1430 |
INSERT INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?) |
1431 |
|, undef, $sco_patron->borrowernumber, 23, 'self_checkout_module' |
1432 |
); |
1433 |
my ( $template, $loggedinuser, $cookies ) = get_template_and_user( |
1434 |
{ |
1435 |
template_name => "sco/sco-main.tt", |
1436 |
query => $query, |
1437 |
type => "opac", |
1438 |
flagsrequired => { self_check => "self_checkout_module" }, |
1439 |
} |
1440 |
); |
1441 |
is( $template->{VARS}->{logged_in_user}->id, $sco_patron->id ); |
1442 |
is( $loggedinuser, $sco_patron->id ); |
1443 |
}; |
1444 |
|
1353 |
sub set_weak_password { |
1445 |
sub set_weak_password { |
1354 |
my ($patron) = @_; |
1446 |
my ($patron) = @_; |
1355 |
my $password = 'password'; |
1447 |
my $password = 'password'; |
1356 |
- |
|
|