more unicode fixes
[catagits/Catalyst-Runtime.git] / t / utf_incoming.t
1 use utf8;
2 use warnings;
3 use strict;
4 use Test::More;
5 use HTTP::Request::Common;
6
7 # Test cases for incoming utf8 
8
9 {
10   package MyApp::Controller::Root;
11   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
12
13   use base 'Catalyst::Controller';
14
15   sub heart :Path('♥') {
16     my ($self, $c) = @_;
17     $c->response->content_type('text/html');
18     $c->response->body("<p>This is path-heart action ♥</p>");
19     # We let the content length middleware find the length...
20   }
21
22   sub hat :Path('^') {
23     my ($self, $c) = @_;
24     $c->response->content_type('text/html');
25     $c->response->body("<p>This is path-hat action ^</p>");
26   }
27
28   sub base :Chained('/') CaptureArgs(0) { }
29     sub link :Chained('base') PathPart('♥') Args(0) {
30       my ($self, $c) = @_;
31       $c->response->content_type('text/html');
32       $c->response->body("<p>This is base-link action ♥</p>");
33     }
34
35   package MyApp;
36   use Catalyst;
37
38   MyApp->config(encoding=>'UTF-8');
39
40   Test::More::ok(MyApp->setup, 'setup app');
41 }
42
43 ok my $psgi = MyApp->psgi_app, 'build psgi app';
44
45 use Catalyst::Test 'MyApp';
46 use Encode 2.21 'decode_utf8', 'encode_utf8';
47
48 {
49   my $res = request "/root/♥";
50
51   is $res->code, 200, 'OK';
52   is decode_utf8($res->content), '<p>This is path-heart action ♥</p>', 'correct body';
53   is $res->content_length, 36, 'correct length';
54 }
55
56 {
57   my $res = request "/root/^";
58
59   is $res->code, 200, 'OK';
60   is decode_utf8($res->content), '<p>This is path-hat action ^</p>', 'correct body';
61   is $res->content_length, 32, 'correct length';
62 }
63
64 {
65   my $res = request "/base/♥";
66
67   is $res->code, 200, 'OK';
68   is decode_utf8($res->content), '<p>This is base-link action ♥</p>', 'correct body';
69   is $res->content_length, 35, 'correct length';
70 }
71
72 {
73   my ($res, $c) = ctx_request POST "/base/♥?♥=♥&♥=♥♥", [a=>1, b=>'', '♥'=>'♥', '♥'=>'♥♥'];
74
75   is $res->code, 200, 'OK';
76   is decode_utf8($res->content), '<p>This is base-link action ♥</p>', 'correct body';
77   is $res->content_length, 35, 'correct length';
78   is $c->req->parameters->{'♥'}[0], '♥';
79   is $c->req->query_parameters->{'♥'}[0], '♥';
80   is $c->req->body_parameters->{'♥'}[0], '♥';
81   is $c->req->parameters->{'♥'}[0], '♥';
82 }
83
84 ## tests for args and captureargs (chained and otherise)
85 ## warn $c->req->uri; (seemsto be pre encodinged and all
86 ## test what uri_for looks like in responses 
87
88
89 done_testing;