X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Futf_incoming.t;h=864c99dfcbafaaafb0fd547713bf1bc84028c37d;hb=4d94a93ad9c5791db5861b3dc2250aa6ef4770f2;hp=638cef5a1555ea2ab1830d0226494c86794e3187;hpb=70005e986f12f433f81595e35c902358487b7869;p=catagits%2FCatalyst-Runtime.git diff --git a/t/utf_incoming.t b/t/utf_incoming.t index 638cef5..864c99d 100644 --- a/t/utf_incoming.t +++ b/t/utf_incoming.t @@ -3,7 +3,8 @@ use warnings; use strict; use Test::More; use HTTP::Request::Common; -use Encode 2.21 'decode_utf8', 'encode_utf8'; +use HTTP::Message::PSGI (); +use Encode 2.21 'decode_utf8', 'encode_utf8', 'encode'; use File::Spec; use JSON::MaybeXS; @@ -180,6 +181,18 @@ use JSON::MaybeXS; $c->response->write("

This is stream_write action ♥

"); } + sub from_external_psgi :Local { + my ($self, $c) = @_; + my $env = HTTP::Message::PSGI::req_to_psgi( HTTP::Request::Common::GET '/root/♥'); + $c->res->from_psgi_response( ref($c)->to_app->($env)); + } + + sub echo_arg :Local { + my ($self, $c) = @_; + $c->response->content_type('text/plain'); + $c->response->body($c->req->body_parameters->{arg}); + } + package MyApp; use Catalyst; @@ -411,6 +424,45 @@ SKIP: { like decode_utf8($res->content), qr[

This is stream_write action ♥

code, 200, 'OK'; + is decode_utf8($res->content), '

This is path-heart action ♥

', 'correct body'; + is $res->content_length, 36, 'correct length'; + is $res->content_charset, 'UTF-8'; +} + +SKIP: { + skip 4; + my $utf8 = 'test ♥'; + my $shiftjs = 'test テスト'; + + ok my $req = POST '/root/echo_arg', + Content_Type => 'form-data', + Content => [ + arg0 => 'helloworld', + arg1 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=UTF-8', + 'Content' => Encode::encode('UTF-8', $utf8)], + arg2 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=SHIFT_JIS', + 'Content' => Encode::encode('SHIFT_JIS', $shiftjs)], + arg2 => [ + undef, '', + 'Content-Type' =>'text/plain; charset=SHIFT_JIS', + 'Content' => Encode::encode('SHIFT_JIS', $shiftjs)], + ]; + + my ($res, $c) = ctx_request $req; + + is $c->req->body_parameters->{'arg0'}, 'helloworld'; + is Encode::decode('UTF-8', $c->req->body_parameters->{'arg1'}), $utf8; + is Encode::decode('SHIFT_JIS', $c->req->body_parameters->{'arg2'}[0]), $shiftjs; + +} ## should we use binmode on filehandles to force the encoding...? ## Not sure what else to do with multipart here, if docs are enough...