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

(-)a/t/db_dependent/Output.t (-3 / +129 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 3;
20
use Test::More tests => 4;
21
use Test::MockModule;
21
use Test::MockModule;
22
use Test::NoWarnings;
22
use Test::NoWarnings;
23
use Test::Warn;
23
use Test::Warn;
Lines 30-42 use t::lib::TestBuilder; Link Here
30
BEGIN {
30
BEGIN {
31
    use_ok(
31
    use_ok(
32
        'C4::Output',
32
        'C4::Output',
33
        qw( redirect_if_opac_suppressed )
33
        qw( redirect_if_opac_hidden redirect_if_opac_suppressed )
34
    );
34
    );
35
}
35
}
36
36
37
my $builder = t::lib::TestBuilder->new();
37
my $builder = t::lib::TestBuilder->new();
38
my $schema  = Koha::Database->new()->schema();
38
my $schema  = Koha::Database->new()->schema();
39
39
40
subtest 'redirect_if_opac_hidden() tests' => sub {
41
42
    plan tests => 2;
43
44
    $schema->storage->txn_begin;
45
46
    local *STDOUT;
47
    my $stdout;
48
49
    # variable controlling opac hidden status
50
    my $opac_hidden;
51
52
    my $auth_mock = Test::MockModule->new('C4::Auth');
53
    $auth_mock->mock( 'safe_exit', sub { warn "safe_exit_called" } );
54
55
    my $biblio_mock = Test::MockModule->new('Koha::Biblio');
56
    $biblio_mock->mock( 'hidden_in_opac', sub { return $opac_hidden; } );
57
58
    my $biblio = $builder->build_sample_biblio();
59
60
    my $query = CGI->new();
61
62
    subtest 'not hidden tests' => sub {
63
64
        plan tests => 1;
65
66
        open STDOUT, '>', \$stdout;
67
        $opac_hidden = 0;
68
69
        redirect_if_opac_hidden( $query, $biblio );
70
71
        is( $stdout, undef, 'No redirection if the biblio is not hidden' );
72
73
        close STDOUT;
74
    };
75
76
    subtest 'hidden tests' => sub {
77
78
        plan tests => 9;
79
80
        $opac_hidden = 1;
81
82
        {
83
            open STDOUT, '>', \$stdout;
84
            t::lib::Mocks::mock_preference( 'OpacHiddenRecordRedirect', 1 );
85
86
            warning_is {
87
                redirect_if_opac_hidden( $query, $biblio );
88
            }
89
            q{safe_exit_called},
90
                'Safe exit called on redirection';
91
92
            like( $stdout, qr{Status: 302 Found} );
93
            like( $stdout, qr{Location: /cgi-bin/koha/opac-blocked.pl\?hidden=1} );
94
95
            undef $stdout;
96
97
            close STDOUT;
98
        }
99
100
        {
101
            open STDOUT, '>', \$stdout;
102
            t::lib::Mocks::mock_preference( 'OpacHiddenRecordRedirect', 0 );
103
104
            warning_is {
105
                redirect_if_opac_hidden( $query, $biblio );
106
            }
107
            q{safe_exit_called},
108
                'Safe exit called on redirection';
109
110
            like( $stdout, qr{Status: 302 Found} );
111
            like( $stdout, qr{Location: /cgi-bin/koha/errors/404.pl} );
112
113
            undef $stdout;
114
115
            close STDOUT;
116
        }
117
118
        {
119
            open STDOUT, '>', \$stdout;
120
            t::lib::Mocks::mock_preference( 'OpacHiddenRecordRedirect', 1 );
121
122
            my $patron = $builder->build_object(
123
                {
124
                    class => 'Koha::Patrons',
125
                }
126
            );
127
128
            my $patron2 = $builder->build_object(
129
                {
130
                    class => 'Koha::Patrons',
131
                }
132
            );
133
134
            t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', $patron->categorycode );
135
136
            redirect_if_opac_hidden( $query, $biblio, $patron );
137
138
            is( $stdout, undef, 'No redirection if the patron category is excluded from hidden items' );
139
140
            undef $stdout;
141
142
            t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', $patron2->categorycode );
143
144
            warning_is {
145
                redirect_if_opac_hidden( $query, $biblio, $patron );
146
            }
147
            q{safe_exit_called},
148
                'Safe exit called on redirection';
149
150
            t::lib::Mocks::mock_preference( 'OpacHiddenItemsExceptions', '' );
151
152
            warning_is {
153
                redirect_if_opac_hidden( $query, $biblio, $patron );
154
            }
155
            q{safe_exit_called},
156
                'Safe exit called on redirection';
157
158
            undef $stdout;
159
160
            close STDOUT;
161
        }
162
    };
163
164
    $schema->storage->txn_rollback;
165
};
166
40
subtest 'redirect_if_opac_suppressed() tests' => sub {
167
subtest 'redirect_if_opac_suppressed() tests' => sub {
41
168
42
    plan tests => 2;
169
    plan tests => 2;
43
- 

Return to bug 27734