3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # Koha is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20 use Test::More tests => 7;
30 my $query = CGI->new();
32 my $output = 'foobarbaz';
37 open STDOUT, '>', \$stdout;
38 output_html_with_http_headers $query, $cookie, $output, undef, { force_no_caching => 1 };
39 like($stdout, qr/Cache-control: no-cache, no-store, max-age=0/, 'force_no_caching sets Cache-control as desired');
40 like($stdout, qr/Expires: /, 'force_no_caching sets an Expires header');
43 open STDOUT, '>', \$stdout;
44 output_html_with_http_headers $query, $cookie, $output, undef, undef;
45 like($stdout, qr/Cache-control: no-cache[^,]/, 'not using force_no_caching sets Cache-control as desired');
46 unlike($stdout, qr/Expires: /, 'force_no_caching does not set an Expires header');
49 subtest 'parametrized_url' => sub {
52 my $url = 'https://somesite.com/search?q={TITLE}&author={AUTHOR}{SUFFIX}';
53 my $subs = { TITLE => '_title_', AUTHOR => undef, ISBN => '123456789' };
55 warning_is { $res = C4::Output::parametrized_url( $url, $subs ) }
56 q{}, 'No warning expected on undefined author';
57 is( $res, 'https://somesite.com/search?q=_title_&author=',
58 'Title replaced, author empty and SUFFIX removed' );
61 subtest 'output_with_http_headers() tests' => sub {
68 my $query = CGI->new();
70 my $output = 'foobarbaz';
72 open STDOUT, '>', \$stdout;
73 t::lib::Mocks::mock_preference('AccessControlAllowOrigin','');
74 output_html_with_http_headers $query, $cookie, $output, undef;
75 unlike($stdout, qr/Access-control-allow-origin/, 'No header set if no value on syspref');
78 open STDOUT, '>', \$stdout;
79 t::lib::Mocks::mock_preference('AccessControlAllowOrigin',undef);
80 output_html_with_http_headers $query, $cookie, $output, undef;
81 unlike($stdout, qr/Access-control-allow-origin/, 'No header set if no value on syspref');
84 open STDOUT, '>', \$stdout;
85 t::lib::Mocks::mock_preference('AccessControlAllowOrigin','*');
86 output_html_with_http_headers $query, $cookie, $output, undef;
87 like($stdout, qr/Access-control-allow-origin: \*/, 'Header set to *');
90 open STDOUT, '>', \$stdout;
91 t::lib::Mocks::mock_preference('AccessControlAllowOrigin','https://koha-community.org');
92 output_html_with_http_headers $query, $cookie, $output, undef;
93 like($stdout, qr/Access-control-allow-origin: https:\/\/koha-community\.org/, 'Header set to https://koha-community.org');