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
=> 13;
15 use Koha
::AuthUtils qw
/hash_password/;
21 my $dbh = C4
::Context
->dbh;
24 $dbh->{AutoCommit
} = 0;
25 $dbh->{RaiseError
} = 1;
28 # get_template_and_user tests
30 { # Tests for the language URL parameter
33 my ($query,$authnotrequired,$flagsrequired,$type) = @_;
35 my $userid = 'cobain';
37 # we don't need to bother about permissions for this test
39 superlibrarian
=> 1, acquisition
=> 0,
40 borrow
=> 0, borrowers
=> 0,
41 catalogue
=> 1, circulate
=> 0,
42 coursereserves
=> 0, editauthorities
=> 0,
43 editcatalogue
=> 0, management
=> 0,
44 parameters
=> 0, permissions
=> 0,
45 plugins
=> 0, reports
=> 0,
46 reserveforothers
=> 0, serials
=> 0,
47 staffaccess
=> 0, tools
=> 0,
51 my $session_cookie = $query->cookie(
57 return ( $userid, $session_cookie, $sessionID, $flags );
60 # Mock checkauth, build the scenario
61 my $auth = new Test
::MockModule
( 'C4::Auth' );
62 $auth->mock( 'checkauth', \
&MockedCheckauth
);
64 # Make sure 'EnableOpacSearchHistory' is set
65 t
::lib
::Mocks
::mock_preference
('EnableOpacSearchHistory',1);
66 # Enable es-ES for the OPAC and staff interfaces
67 t
::lib
::Mocks
::mock_preference
('opaclanguages','en,es-ES');
68 t
::lib
::Mocks
::mock_preference
('language','en,es-ES');
70 # we need a session cookie
71 $ENV{"SERVER_PORT"} = 80;
72 $ENV{"HTTP_COOKIE"} = 'CGISESSID=nirvana';
75 $query->param('language','es-ES');
77 my ( $template, $loggedinuser, $cookies ) = get_template_and_user
(
79 template_name
=> "about.tt",
83 flagsrequired
=> { catalogue
=> 1 },
88 ok
( ( all
{ ref($_) eq 'CGI::Cookie' } @
$cookies ),
89 'BZ9735: the cookies array is flat' );
91 # new query, with non-existent language (we only have en and es-ES)
92 $query->param('language','tomas');
94 ( $template, $loggedinuser, $cookies ) = get_template_and_user
(
96 template_name
=> "about.tt",
100 flagsrequired
=> { catalogue
=> 1 },
105 ok
( ( none
{ $_->name eq 'KohaOpacLanguage' and $_->value eq 'tomas' } @
$cookies ),
106 'BZ9735: invalid language, it is not set');
108 ok
( ( any
{ $_->name eq 'KohaOpacLanguage' and $_->value eq 'en' } @
$cookies ),
109 'BZ9735: invalid language, then default to en');
111 for my $template_name (
113 ../../../../../../../../../../../../../../../etc/passwd
114 test/../../../../../../../../../../../../../../etc/passwd
116 test/does_not_finished_by_tt_t
120 ( $template, $loggedinuser, $cookies ) = get_template_and_user
(
122 template_name
=> $template_name,
125 authnotrequired
=> 1,
126 flagsrequired
=> { catalogue
=> 1 },
130 like
( $@
, qr
(^bad template path
), 'The file $template_name should not be accessible' );
132 ( $template, $loggedinuser, $cookies ) = get_template_and_user
(
134 template_name
=> 'errors/errorpage.tt',
137 authnotrequired
=> 1,
138 flagsrequired
=> { catalogue
=> 1 },
141 my $file_exists = ( -f
$template->{filename
} ) ?
1 : 0;
142 is
( $file_exists, 1, 'The file errors/errorpage.tt should be accessible (contains integers)' );
145 # Check that there is always an OPACBaseURL set.
146 my $input = CGI
->new();
147 my ( $template1, $borrowernumber, $cookie );
148 ( $template1, $borrowernumber, $cookie ) = get_template_and_user
(
150 template_name
=> "opac-detail.tt",
153 authnotrequired
=> 1,
157 ok
( ( any
{ 'OPACBaseURL' eq $_ } keys %{$template1->{VARS
}} ),
158 'OPACBaseURL is in OPAC template' );
161 ( $template2, $borrowernumber, $cookie ) = get_template_and_user
(
163 template_name
=> "catalogue/detail.tt",
166 authnotrequired
=> 1,
170 ok
( ( any
{ 'OPACBaseURL' eq $_ } keys %{$template2->{VARS
}} ),
171 'OPACBaseURL is in Staff template' );
173 my $hash1 = hash_password
('password');
174 my $hash2 = hash_password
('password');
176 ok
(C4
::Auth
::checkpw_hash
('password', $hash1), 'password validates with first hash');
177 ok
(C4
::Auth
::checkpw_hash
('password', $hash2), 'password validates with second hash');