more utf8 tests and fixes
[catagits/Catalyst-Runtime.git] / t / lib / TestAppEncoding / Controller / Root.pm
1 package TestAppEncoding::Controller::Root;
2 use strict;
3 use warnings;
4 use base 'Catalyst::Controller';
5 use Test::More;
6
7 __PACKAGE__->config->{namespace} = '';
8
9 sub binary : Local {
10     my ($self, $c) = @_;
11     $c->res->content_type('image/gif');
12     $c->res->body(do {
13         open(my $fh, '<', $c->path_to('..', '..', 'catalyst_130pix.gif')) or die $!; 
14         binmode($fh); 
15         local $/ = undef; <$fh>;
16     });
17 }
18
19 sub binary_utf8 : Local {
20     my ($self, $c) = @_;
21     $c->forward('binary');
22     my $str = $c->res->body;
23     utf8::upgrade($str);
24     ok utf8::is_utf8($str), 'Body is variable width encoded string';
25     $c->res->body($str);
26 }
27
28 # called by t/aggregate/catalyst_test_utf8.t
29 sub utf8_non_ascii_content : Local {
30     use utf8;
31     my ($self, $c) = @_;
32     
33     my $str = 'ʇsʎlɐʇɐɔ';  # 'catalyst' flipped at http://www.revfad.com/flip.html
34     ok utf8::is_utf8($str), '$str is in UTF8 internally';
35
36     $c->res->content_type('text/plain');
37     $c->res->body($str);
38 }
39
40
41 sub end : Private {
42     my ($self,$c) = @_;
43 }
44
45 1;