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

(-)a/t/Output.t (-5 / +21 lines)
Lines 19-25 use Modern::Perl; Link Here
19
19
20
use Test::More tests => 8;
20
use Test::More tests => 8;
21
use Test::Warn;
21
use Test::Warn;
22
use Test::Trap;
22
use Test::MockModule;
23
23
24
use File::Temp qw/tempfile/;
24
use File::Temp qw/tempfile/;
25
use CGI qw ( -utf8 );
25
use CGI qw ( -utf8 );
Lines 103-108 subtest 'output_and_exit_if_error() tests' => sub { Link Here
103
103
104
    plan tests => 2;
104
    plan tests => 2;
105
105
106
    my $exit;
107
    my $output = Test::MockModule->new('C4::Output');
108
    $output->mock(
109
        'output_and_exit',
110
        sub {
111
            my ( $query, $cookie, $template, $error ) = @_;
112
            $template->param( blocking_error => $error );
113
            output_html_with_http_headers( $query, $cookie, $template->output );
114
            $exit = 1;
115
        }
116
    );
117
106
    t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] );
118
    t::lib::Mocks::mock_config( 'pluginsdir', [ C4::Context::temporary_directory ] );
107
    my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory );
119
    my ( $fh, $fn ) = tempfile( SUFFIX => '.tt', UNLINK => 1, DIR => C4::Context::temporary_directory );
108
    print $fh qq|[% blocking_error %]|;
120
    print $fh qq|[% blocking_error %]|;
Lines 119-125 subtest 'output_and_exit_if_error() tests' => sub { Link Here
119
        }
131
        }
120
    );
132
    );
121
133
122
    my @r = trap { output_and_exit_if_error($query, $cookie, $template, { check => 'csrf_token' }) };
134
    local *STDOUT;
123
    is ( $trap->exit, 0, 'Expecting &output_and_exit_if_error to exit with 0' );
135
    my $stdout;
124
    like ( $trap->stdout, qr/wrong_csrf_token/, 'Expecting wrong_csrf_token' );
136
137
    open STDOUT, '>', \$stdout;
138
    output_and_exit_if_error($query, $cookie, $template, { check => 'csrf_token' });
139
    is( $exit, 1, "Exit");
140
    like ( $stdout, qr/wrong_csrf_token/, 'Expecting wrong_csrf_token' );
141
    close STDOUT;
125
};
142
};
126
- 

Return to bug 30524