View | Details | Raw Unified | Return to bug 9735
Collapse All | Expand All

(-)a/t/db_dependent/Auth.t (-4 / +97 lines)
Lines 3-15 Link Here
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
8
7
9
use Test::More tests => 1;
8
use CGI;
9
use Test::MockModule;
10
use List::MoreUtils qw/all any none/;
11
use Test::More tests => 4;
12
use C4::Members;
10
13
11
BEGIN {
14
BEGIN {
12
        use_ok('C4::Auth');
15
        use_ok('C4::Auth');
13
}
16
}
14
17
18
my $dbh = C4::Context->dbh;
15
19
16
- 
20
# Start transaction
21
$dbh->{AutoCommit} = 0;
22
$dbh->{RaiseError} = 1;
23
24
25
# get_template_and_user tests
26
27
{   # Tests for the language URL parameter
28
29
    sub MockedCheckauth {
30
        my ($query,$authnotrequired,$flagsrequired,$type) = @_;
31
        # return vars
32
        my $userid = 'cobain';
33
        my $sessionID = 234;
34
        # we don't need to bother about permissions for this test
35
        my $flags = {
36
            superlibrarian    => 1, acquisition       => 0,
37
            borrow            => 0, borrowers         => 0,
38
            catalogue         => 1, circulate         => 0,
39
            coursereserves    => 0, editauthorities   => 0,
40
            editcatalogue     => 0, management        => 0,
41
            parameters        => 0, permissions       => 0,
42
            plugins           => 0, reports           => 0,
43
            reserveforothers  => 0, serials           => 0,
44
            staffaccess       => 0, tools             => 0,
45
            updatecharges     => 0
46
        };
47
48
        my $session_cookie = $query->cookie(
49
            -name => 'CGISESSID',
50
            -value    => 'nirvana',
51
            -HttpOnly => 1
52
        );
53
54
        return ( $userid, $session_cookie, $sessionID, $flags );
55
    }
56
57
    # Mock checkauth, build the scenario
58
    my $auth = new Test::MockModule( 'C4::Auth' );
59
    $auth->mock( 'checkauth', \&MockedCheckauth );
60
61
    # Make sure 'EnableOpacSearchHistory' is set
62
    C4::Context->set_preference('EnableOpacSearchHistory',1);
63
    # Enable es-ES for the OPAC and staff interfaces
64
    C4::Context->set_preference('opaclanguages','en,es-ES');
65
    C4::Context->set_preference('language','en,es-ES');
66
67
    # we need a session cookie and have some anonymous search history
68
    $ENV{"SERVER_PORT"} = 80;
69
    $ENV{"HTTP_COOKIE"} = 'CGISESSID=nirvana; KohaOpacRecentSearches=%255B%257B%2522time%2522%253A1378313124%252C%2522query_cgi%2522%253A%2522idx%253D%2526q%253Dhistory%2526branch_group_limit%253D%2522%252C%2522total%2522%253A3%252C%2522query_desc%2522%253A%2522kw%252Cwrdl%253A%2520history%252C%2520%2522%257D%252C%257B%2522time%2522%253A1378313137%252C%2522query_cgi%2522%253A%2522idx%253D%2526q%253D%2525D8%2525B9%2525D8%2525B1%2525D8%2525A8%2525D9%25258A%25252F%2525D8%2525B9%2525D8%2525B1%2525D8%2525A8%2525D9%252589%2526branch_group_limit%253D%2522%252C%2522total%2522%253A2%252C%2522query_desc%2522%253A%2522kw%252Cwrdl%253A%2520%25D8%25B9%25D8%25B1%25D8%25A8%25D9%258A%252F%25D8%25B9%25D8%25B1%25D8%25A8%25D9%2589%252C%2520%2522%257D%255D';
70
71
    my $query = new CGI;
72
    $query->param('language','es-ES');
73
74
    my ( $template, $loggedinuser, $cookies ) = get_template_and_user(
75
        {
76
            template_name   => "about.tmpl",
77
            query           => $query,
78
            type            => "opac",
79
            authnotrequired => 1,
80
            flagsrequired   => { catalogue => 1 },
81
            debug           => 1
82
        }
83
    );
84
85
    ok ( ( all { ref($_) eq 'CGI::Cookie' } @$cookies ),
86
            'BZ9735: the cookies array is flat' );
87
88
    # new query, with non-existent language (we only have en and es-ES)
89
    $query->param('language','tomas');
90
91
    ( $template, $loggedinuser, $cookies ) = get_template_and_user(
92
        {
93
            template_name   => "about.tmpl",
94
            query           => $query,
95
            type            => "opac",
96
            authnotrequired => 1,
97
            flagsrequired   => { catalogue => 1 },
98
            debug           => 1
99
        }
100
    );
101
102
    ok( ( none { $_->name eq 'KohaOpacLanguage' and $_->value eq 'tomas' } @$cookies ),
103
        'BZ9735: invalid language, it is not set');
104
105
    ok( ( any { $_->name eq 'KohaOpacLanguage' and $_->value eq 'en' } @$cookies ),
106
        'BZ9735: invalid language, then default to en');
107
}
108
109
$dbh->rollback;

Return to bug 9735