3 # This Koha test module is a stub!
4 # Add more tests here!!!
10 use List::MoreUtils qw/all any none/;
11 use Test::More tests => 6;
13 use Koha::AuthUtils qw/hash_password/;
19 my $dbh = C4::Context->dbh;
22 $dbh->{AutoCommit} = 0;
23 $dbh->{RaiseError} = 1;
26 # get_template_and_user tests
28 { # Tests for the language URL parameter
31 my ($query,$authnotrequired,$flagsrequired,$type) = @_;
33 my $userid = 'cobain';
35 # we don't need to bother about permissions for this test
37 superlibrarian => 1, acquisition => 0,
38 borrow => 0, borrowers => 0,
39 catalogue => 1, circulate => 0,
40 coursereserves => 0, editauthorities => 0,
41 editcatalogue => 0, management => 0,
42 parameters => 0, permissions => 0,
43 plugins => 0, reports => 0,
44 reserveforothers => 0, serials => 0,
45 staffaccess => 0, tools => 0,
49 my $session_cookie = $query->cookie(
55 return ( $userid, $session_cookie, $sessionID, $flags );
58 # Mock checkauth, build the scenario
59 my $auth = new Test::MockModule( 'C4::Auth' );
60 $auth->mock( 'checkauth', \&MockedCheckauth );
62 # Make sure 'EnableOpacSearchHistory' is set
63 C4::Context->set_preference('EnableOpacSearchHistory',1);
64 # Enable es-ES for the OPAC and staff interfaces
65 C4::Context->set_preference('opaclanguages','en,es-ES');
66 C4::Context->set_preference('language','en,es-ES');
68 # we need a session cookie
69 $ENV{"SERVER_PORT"} = 80;
70 $ENV{"HTTP_COOKIE"} = 'CGISESSID=nirvana';
73 $query->param('language','es-ES');
75 my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
77 template_name => "about.tmpl",
81 flagsrequired => { catalogue => 1 },
86 ok ( ( all { ref($_) eq 'CGI::Cookie' } @$cookies ),
87 'BZ9735: the cookies array is flat' );
89 # new query, with non-existent language (we only have en and es-ES)
90 $query->param('language','tomas');
92 ( $template, $loggedinuser, $cookies ) = get_template_and_user(
94 template_name => "about.tmpl",
98 flagsrequired => { catalogue => 1 },
103 ok( ( none { $_->name eq 'KohaOpacLanguage' and $_->value eq 'tomas' } @$cookies ),
104 'BZ9735: invalid language, it is not set');
106 ok( ( any { $_->name eq 'KohaOpacLanguage' and $_->value eq 'en' } @$cookies ),
107 'BZ9735: invalid language, then default to en');
110 my $hash1 = hash_password('password');
111 my $hash2 = hash_password('password');
113 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
114 ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');