| 1 | use strict; |
|---|
| 2 | use Cwd; |
|---|
| 3 | use OpenGuides; |
|---|
| 4 | use OpenGuides::Template; |
|---|
| 5 | use OpenGuides::Test; |
|---|
| 6 | use Test::More tests => 5; |
|---|
| 7 | |
|---|
| 8 | my $config = OpenGuides::Test->make_basic_config; |
|---|
| 9 | $config->template_path( cwd . "/t/templates" ); |
|---|
| 10 | |
|---|
| 11 | my $guide = OpenGuides->new( config => $config ); |
|---|
| 12 | my $wiki = $guide->wiki; |
|---|
| 13 | |
|---|
| 14 | eval { |
|---|
| 15 | OpenGuides::Template->output( wiki => $wiki, |
|---|
| 16 | config => $config, |
|---|
| 17 | template => "15_test.tt" ); |
|---|
| 18 | }; |
|---|
| 19 | is( $@, "", "is happy doing output" ); |
|---|
| 20 | |
|---|
| 21 | my $output = OpenGuides::Template->output( |
|---|
| 22 | wiki => $wiki, |
|---|
| 23 | config => $config, |
|---|
| 24 | template => "15_test.tt" |
|---|
| 25 | ); |
|---|
| 26 | like( $output, qr/^Content-Type: text\/html/, |
|---|
| 27 | "Content-Type header included and defaults to text/html" ); |
|---|
| 28 | |
|---|
| 29 | # Now supply a http charset |
|---|
| 30 | $config->http_charset( "UTF-8" ); |
|---|
| 31 | |
|---|
| 32 | $output = OpenGuides::Template->output( |
|---|
| 33 | wiki => $wiki, |
|---|
| 34 | config => $config, |
|---|
| 35 | template => "15_test.tt" |
|---|
| 36 | ); |
|---|
| 37 | like( $output, qr/^Content-Type: text\/html; charset=UTF-8/, |
|---|
| 38 | "Content-Type header included charset" ); |
|---|
| 39 | |
|---|
| 40 | # Suppy charset and content type |
|---|
| 41 | $output = OpenGuides::Template->output( |
|---|
| 42 | wiki => $wiki, |
|---|
| 43 | config => $config, |
|---|
| 44 | content_type => "text/xml", |
|---|
| 45 | template => "15_test.tt" |
|---|
| 46 | ); |
|---|
| 47 | like( $output, qr/^Content-Type: text\/xml; charset=UTF-8/, |
|---|
| 48 | "Content-Type header included charset" ); |
|---|
| 49 | |
|---|
| 50 | # Content type but no charset |
|---|
| 51 | $config->http_charset( "" ); |
|---|
| 52 | $output = OpenGuides::Template->output( |
|---|
| 53 | wiki => $wiki, |
|---|
| 54 | config => $config, |
|---|
| 55 | content_type => "text/xml", |
|---|
| 56 | template => "15_test.tt" |
|---|
| 57 | ); |
|---|
| 58 | like( $output, qr/^Content-Type: text\/xml/, |
|---|
| 59 | "Content-Type header didn't include charset" ); |
|---|