X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Futf_incoming.t;h=ea621ce4fb9eed22e5193f97c9be3f494b106ea7;hp=4a697ccab71ad094cd5c46e5dde6f5398c991981;hb=5c397774465fdb8f734dd7948503c571b2677c79;hpb=4a62800defdaa16ec1a5bef88f3e639c983b6f1d diff --git a/t/utf_incoming.t b/t/utf_incoming.t index 4a697cc..ea621ce 100644 --- a/t/utf_incoming.t +++ b/t/utf_incoming.t @@ -25,12 +25,54 @@ use HTTP::Request::Common; $c->response->body("
This is path-hat action ^
"); } + sub uri_for :Path('uri_for') { + my ($self, $c) = @_; + $c->response->content_type('text/html'); + $c->response->body("${\$c->uri_for($c->controller('Root')->action_for('argend'), ['â¥'], 'â¥', {'â¥'=>'â¥â¥'})}"); + } + + sub heart_with_arg :Path('aâ¥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + $c->response->body("This is path-heart-arg action $arg
"); + Test::More::is $c->req->args->[0], 'â¥'; + } + sub base :Chained('/') CaptureArgs(0) { } sub link :Chained('base') PathPart('â¥') Args(0) { my ($self, $c) = @_; $c->response->content_type('text/html'); $c->response->body("This is base-link action â¥
"); } + sub arg :Chained('base') PathPart('â¥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + $c->response->body("This is base-link action ⥠$arg
"); + } + sub capture :Chained('base') PathPart('â¥') CaptureArgs(1) { + my ($self, $c, $arg) = @_; + $c->stash(capture=>$arg); + } + sub argend :Chained('capture') PathPart('â¥') Args(1) { + my ($self, $c, $arg) = @_; + $c->response->content_type('text/html'); + + Test::More::is $c->req->args->[0], 'â¥'; + Test::More::is $c->req->captures->[0], 'â¥'; + + $c->response->body("This is base-link action ⥠${\$c->req->args->[0]}
"); + + # Test to make sure redirect can now take an object (sorry don't have a better place for it + # but wanted test coverage. + my $location = $c->res->redirect( $c->uri_for($c->controller('Root')->action_for('uri_for')) ); + Test::More::ok !ref $location; + } + + sub stream_write :Local { + my ($self, $c) = @_; + $c->response->content_type('text/html'); + $c->response->write("This is stream_write action â¥
"); + } package MyApp; use Catalyst; @@ -54,6 +96,14 @@ use Encode 2.21 'decode_utf8', 'encode_utf8'; } { + my $res = request "/root/aâ¥/â¥"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), 'This is path-heart-arg action â¥
', 'correct body'; + is $res->content_length, 40, 'correct length'; +} + +{ my $res = request "/root/^"; is $res->code, 200, 'OK'; @@ -79,16 +129,67 @@ use Encode 2.21 'decode_utf8', 'encode_utf8'; is $c->req->query_parameters->{'â¥'}[0], 'â¥'; is $c->req->body_parameters->{'â¥'}[0], 'â¥'; is $c->req->parameters->{'â¥'}[0], 'â¥'; - is $c->req->parameters->{a}, 1; is $c->req->body_parameters->{a}, 1; +} +{ + my ($res, $c) = ctx_request GET "/base/â¥?â¥â¥â¥"; + is $res->code, 200, 'OK'; + is decode_utf8($res->content), 'This is base-link action â¥
', 'correct body'; + is $res->content_length, 35, 'correct length'; + is $c->req->query_keywords, 'â¥â¥â¥'; +} + +{ + my $res = request "/base/â¥/â¥"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), 'This is base-link action ⥠â¥
', 'correct body'; + is $res->content_length, 39, 'correct length'; +} + +{ + my $res = request "/base/â¥/â¥/â¥/â¥"; + + is decode_utf8($res->content), 'This is base-link action ⥠â¥
', 'correct body'; + is $res->content_length, 39, 'correct length'; +} + +{ + my ($res, $c) = ctx_request POST "/base/â¥/â¥/â¥/â¥?â¥=â¥â¥", [a=>1, b=>'2', 'â¥'=>'â¥â¥']; + + ## Make sure that the urls we generate work the same + my $uri_for = $c->uri_for($c->controller('Root')->action_for('argend'), ['â¥'], 'â¥', {'â¥'=>'â¥â¥'}); + my $uri = $c->req->uri; + + is "$uri", "$uri_for"; + + { + my ($res, $c) = ctx_request POST "$uri_for", [a=>1, b=>'2', 'â¥'=>'â¥â¥']; + is $c->req->query_parameters->{'â¥'}, 'â¥â¥'; + is $c->req->body_parameters->{'â¥'}, 'â¥â¥'; + is $c->req->parameters->{'â¥'}[0], 'â¥â¥'; #combined with query and body + } } -## tests for args and captureargs (chained and otherise) -## warn $c->req->uri; (seemsto be pre encodinged and all -## test what uri_for looks like in responses +{ + my ($res, $c) = ctx_request "/root/uri_for"; + my $url = $c->uri_for($c->controller('Root')->action_for('argend'), ['â¥'], 'â¥', {'â¥'=>'â¥â¥'}); + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), "$url", 'correct body'; #should do nothing + is $res->content, "$url", 'correct body'; + is $res->content_length, 90, 'correct length'; +} + +{ + my $res = request "/root/stream_write"; + + is $res->code, 200, 'OK'; + is decode_utf8($res->content), 'This is stream_write action â¥
', 'correct body'; +} done_testing;