| 1 | use strict; |
|---|
| 2 | use Cwd; |
|---|
| 3 | use CGI::Cookie; |
|---|
| 4 | use Wiki::Toolkit::Formatter::UseMod; |
|---|
| 5 | use OpenGuides::Config; |
|---|
| 6 | use OpenGuides::Template; |
|---|
| 7 | use Test::MockObject; |
|---|
| 8 | use Test::More tests => 5; |
|---|
| 9 | |
|---|
| 10 | my $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. |
|---|
| 29 | my $fake_wiki = Test::MockObject->new; |
|---|
| 30 | $fake_wiki->mock("formatter", |
|---|
| 31 | sub { return Wiki::Toolkit::Formatter::UseMod->new( munge_urls => 1 ); } ); |
|---|
| 32 | |
|---|
| 33 | eval { |
|---|
| 34 | OpenGuides::Template->output( wiki => $fake_wiki, |
|---|
| 35 | config => $config, |
|---|
| 36 | template => "15_test.tt" ); |
|---|
| 37 | }; |
|---|
| 38 | is( $@, "", "is happy doing output" ); |
|---|
| 39 | |
|---|
| 40 | my $output = OpenGuides::Template->output( |
|---|
| 41 | wiki => $fake_wiki, |
|---|
| 42 | config => $config, |
|---|
| 43 | template => "15_test.tt" |
|---|
| 44 | ); |
|---|
| 45 | like( $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 | ); |
|---|
| 56 | like( $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 | ); |
|---|
| 66 | like( $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 | ); |
|---|
| 77 | like( $output, qr/^Content-Type: text\/xml/, |
|---|
| 78 | "Content-Type header didn't include charset" ); |
|---|