source: trunk/t/18_http_headers.t @ 868

Last change on this file since 868 was 868, checked in by nick, 15 years ago

Support the config flag http_charset, which sets a http charset header on content type. (Closes #141)

File size: 2.6 KB
Line 
1use strict;
2use Cwd;
3use CGI::Cookie;
4use Wiki::Toolkit::Formatter::UseMod;
5use OpenGuides::Config;
6use OpenGuides::Template;
7use Test::MockObject;
8use Test::More tests => 5;
9
10my $config = OpenGuides::Config->new(
11       vars => {
12                 template_path         => cwd . '/t/templates',
13                 site_name             => 'Wiki::Toolkit Test Site',
14                 script_url            => 'http://wiki.example.com/',
15                 script_name           => 'mywiki.cgi',
16                 default_country       => 'United Kingdom',
17                 default_city          => 'London',
18                 contact_email         => 'wiki@example.com',
19                 stylesheet_url        => 'http://wiki.example.com/styles.css',
20                 home_name             => 'Home Page',
21                 formatting_rules_node => 'Rules',
22                 formatting_rules_link => '',
23               }
24);
25
26# White box testing - we know that OpenGuides::Template only actually uses
27# the node_name_to_node_param method of the formatter component of the wiki
28# object passed in, and I CBA to make a proper wiki object here.
29my $fake_wiki = Test::MockObject->new;
30$fake_wiki->mock("formatter",
31                 sub { return Wiki::Toolkit::Formatter::UseMod->new( munge_urls => 1 ); } );
32
33eval {
34    OpenGuides::Template->output( wiki     => $fake_wiki,
35                                  config   => $config,
36                                  template => "15_test.tt" );
37};
38is( $@, "", "is happy doing output" );
39
40my $output = OpenGuides::Template->output(
41    wiki     => $fake_wiki,
42    config   => $config,
43    template => "15_test.tt"
44);
45like( $output, qr/^Content-Type: text\/html/,
46      "Content-Type header included and defaults to text/html" );
47
48# Now supply a http charset
49$config->{http_charset} = "UTF-8";
50
51$output = OpenGuides::Template->output(
52    wiki     => $fake_wiki,
53    config   => $config,
54    template => "15_test.tt"
55);
56like( $output, qr/^Content-Type: text\/html; charset=UTF-8/,
57      "Content-Type header included charset" );
58
59# Suppy charset and content type
60$output = OpenGuides::Template->output(
61    wiki     => $fake_wiki,
62    config   => $config,
63    content_type => "text/xml",
64    template => "15_test.tt"
65);
66like( $output, qr/^Content-Type: text\/xml; charset=UTF-8/,
67      "Content-Type header included charset" );
68
69# Content type but no charset
70$config->{http_charset} = "";
71$output = OpenGuides::Template->output(
72    wiki     => $fake_wiki,
73    config   => $config,
74    content_type => "text/xml",
75    template => "15_test.tt"
76);
77like( $output, qr/^Content-Type: text\/xml/,
78      "Content-Type header didn't include charset" );
Note: See TracBrowser for help on using the repository browser.