actually use the new keywords
[catagits/Catalyst-Runtime.git] / t / utf_incoming.t
CommitLineData
0ca510f0 1use utf8;
2use warnings;
3use strict;
4use Test::More;
b9d96e27 5use HTTP::Request::Common;
0ca510f0 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
43ok my $psgi = MyApp->psgi_app, 'build psgi app';
44
45use Catalyst::Test 'MyApp';
b9d96e27 46use Encode 2.21 'decode_utf8', 'encode_utf8';
0ca510f0 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{
b9d96e27 73 my ($res, $c) = ctx_request POST "/base/♥?♥=♥&♥=♥♥", [a=>1, b=>'', '♥'=>'♥', '♥'=>'♥♥'];
0ca510f0 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';
b9d96e27 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], '♥';
4a62800d 82
83 is $c->req->parameters->{a}, 1;
84 is $c->req->body_parameters->{a}, 1;
85
86
0ca510f0 87}
88
b9d96e27 89## tests for args and captureargs (chained and otherise)
90## warn $c->req->uri; (seemsto be pre encodinged and all
91## test what uri_for looks like in responses
92
0ca510f0 93
94done_testing;