Bug 21662: Add Contributors.yaml file
[koha.git] / t / Output.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 6;
7 use Test::Warn;
8 use CGI qw ( -utf8 );
9
10 BEGIN {
11     use_ok('C4::Output');
12 }
13
14 my $query = CGI->new();
15 my $cookie;
16 my $output = 'foobarbaz';
17
18 {
19     local *STDOUT;
20     my $stdout;
21     open STDOUT, '>', \$stdout;
22     output_html_with_http_headers $query, $cookie, $output, undef, { force_no_caching => 1 };
23     like($stdout, qr/Cache-control: no-cache, no-store, max-age=0/, 'force_no_caching sets Cache-control as desired');
24     like($stdout, qr/Expires: /, 'force_no_caching sets an Expires header');
25     $stdout = '';
26     close STDOUT;
27     open STDOUT, '>', \$stdout;
28     output_html_with_http_headers $query, $cookie, $output, undef, undef;
29     like($stdout, qr/Cache-control: no-cache[^,]/, 'not using force_no_caching sets Cache-control as desired');
30     unlike($stdout, qr/Expires: /, 'force_no_caching does not set an Expires header');
31 }
32
33 subtest 'parametrized_url' => sub {
34     plan tests => 2;
35
36     my $url = 'https://somesite.com/search?q={TITLE}&author={AUTHOR}{SUFFIX}';
37     my $subs = { TITLE => '_title_', AUTHOR => undef, ISBN => '123456789' };
38     my $res;
39     warning_is { $res = C4::Output::parametrized_url( $url, $subs ) }
40         q{}, 'No warning expected on undefined author';
41     is( $res, 'https://somesite.com/search?q=_title_&author=',
42         'Title replaced, author empty and SUFFIX removed' );
43 };