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=096ba69cc1bc159a0843637d7aa88a7bcec5e636;hp=4a697ccab71ad094cd5c46e5dde6f5398c991981;hb=e5a5e80ba295da3a2f1fd8610b2f03299f9c5719;hpb=55f8e5163b1f5c502b92a9976350c611610c80e3 diff --git a/t/utf_incoming.t b/t/utf_incoming.t index 4a697cc..096ba69 100644 --- a/t/utf_incoming.t +++ b/t/utf_incoming.t @@ -25,12 +25,43 @@ 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]}

"); + } package MyApp; use Catalyst; @@ -54,6 +85,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 +118,60 @@ 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, '♥♥♥'; } -## 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 = 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 $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, $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 + } +} + +{ + 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'; +} done_testing;