From: Charlie Garrison Date: Sun, 28 Sep 2014 02:43:40 +0000 (+1000) Subject: Tests for `uri_for` called as class method. X-Git-Tag: 5.90102~4^2^2~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=950282bc140f3044f59fc3a70f6f63857f963d7b;p=catagits%2FCatalyst-Runtime.git Tests for `uri_for` called as class method. And for `uri_for_action` too. --- diff --git a/t/aggregate/unit_core_uri_for.t b/t/aggregate/unit_core_uri_for.t index 3318192..d7fdbea 100644 --- a/t/aggregate/unit_core_uri_for.t +++ b/t/aggregate/unit_core_uri_for.t @@ -59,6 +59,50 @@ is( 'Plus is not encoded' ); +is( + Catalyst::uri_for( 'TestApp', '/bar/baz' )->as_string, + '/bar/baz', + 'URI for absolute path, called with only class name' +); + +## relative action (or path) doesn't make sense when calling as class method +# is( +# Catalyst::uri_for( 'TestApp', 'bar/baz' )->as_string, +# '/yada/bar/baz', +# 'URI for relative path, called with only class name' +# ); + +is( + Catalyst::uri_for( 'TestApp', '/', 'arg1', 'arg2' )->as_string, + '/arg1/arg2', + 'URI for root action with args, called with only class name' +); + +## relative action (or path) doesn't make sense when calling as class method +# is( Catalyst::uri_for( 'TestApp', '../quux' )->as_string, +# '/quux', 'URI for relative dot path, called with only class name' ); + +is( + Catalyst::uri_for( 'TestApp', '/quux', { param1 => 'value1' } )->as_string, + '/quux?param1=value1', + 'URI for quux action with query params, called with only class name' +); + +is (Catalyst::uri_for( 'TestApp', '/bar/wibble?' )->as_string, + '/bar/wibble%3F', 'Question Mark gets encoded, called with only class name' +); + +## relative action (or path) doesn't make sense when calling as class method +# is( Catalyst::uri_for( 'TestApp', qw/bar wibble?/, 'with space' )->as_string, +# '/yada/bar/wibble%3F/with%20space', 'Space gets encoded, called with only class name' +# ); + +is( + Catalyst::uri_for( 'TestApp', '/bar', 'with+plus', { 'also' => 'with+plus' })->as_string, + '/bar/with+plus?also=with%2Bplus', + 'Plus is not encoded, called with only class name' +); + TODO: { local $TODO = 'broken by 5.7008'; is( diff --git a/t/aggregate/unit_core_uri_for_action.t b/t/aggregate/unit_core_uri_for_action.t index 4036f88..7341365 100644 --- a/t/aggregate/unit_core_uri_for_action.t +++ b/t/aggregate/unit_core_uri_for_action.t @@ -77,6 +77,36 @@ my $context = TestApp->new( { namespace => 'yada', } ); + + + +# this works, using $ctx +is($context->uri_for( 'TestApp', $context->controller('Action::Chained')->action_for('endpoint')), + "http://127.0.0.1/foo/yada/chained/foo/end", + "uri_for a controller and action"); + +# this fails, uri_for returns undef, why isn't this one working?? +is( $context->uri_for_action( '/action/chained/endpoint' ), + 'http://127.0.0.1/chained/foo/end', + "uri_for a controller and action as string"); + +# this fails, uri_for returns undef +is(Catalyst::uri_for_action( 'TestApp', $context->controller('Action::Chained')->action_for('endpoint')), + "/chained/foo/end", + "uri_for a controller and action, called with only class name"); + +# this fails, uri_for returns undef +is(Catalyst::uri_for_action( 'TestApp', '/action/chained/endpoint' ), + "/chained/foo/end", + "uri_for a controller and action as string, called with only class name"); + +# this fails, uri_for returns undef +is(Catalyst::uri_for_action( 'TestApp', $chained_action), + "/chained/foo/end", + "uri_for action via dispatcher, called with only class name"); + + + is($context->uri_for($context->controller('Action')), "http://127.0.0.1/foo/yada/action/", "uri_for a controller");