X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fpsgi_utils.t;h=078dd82cba1a6e30d3d8cf910d65a447b212b450;hb=1b526dcc8437ccd8c55e8e313f3fe247b6741969;hp=9b6092676e6fbab3437d819d23abf34c5f42e4f6;hpb=4477b313f9ef93789650b63e5ce408fe65ca54b2;p=catagits%2FCatalyst-Runtime.git diff --git a/t/psgi_utils.t b/t/psgi_utils.t index 9b60926..078dd82 100644 --- a/t/psgi_utils.t +++ b/t/psgi_utils.t @@ -3,18 +3,19 @@ use strict; # Make it easier to mount PSGI apps under catalyst +my $psgi_app = sub { + my $req = Plack::Request->new(shift); + return [200,[],[$req->path]]; +}; + { package MyApp::Controller::Docs; + $INC{'MyApp/Controller/Docs.pm'} = __FILE__; use base 'Catalyst::Controller'; use Plack::Request; use Catalyst::Utils; - my $psgi_app = sub { - my $req = Plack::Request->new(shift); - return [200,[],[$req->path]]; - }; - sub name :Local { my ($self, $c) = @_; my $env = $c->Catalyst::Utils::env_at_action; @@ -31,16 +32,12 @@ use strict; } package MyApp::Controller::User; + $INC{'MyApp/Controller/User.pm'} = __FILE__; use base 'Catalyst::Controller'; use Plack::Request; use Catalyst::Utils; - my $psgi_app = sub { - my $req = Plack::Request->new(shift); - return [200,[],[$req->path]]; - }; - sub local_example :Local { my ($self, $c) = @_; my $env = $self->get_env($c); @@ -80,6 +77,27 @@ use strict; $c->res->from_psgi_response( $psgi_app->($env)); } + + sub mounted :Local Args(1) { + my ($self, $c, $arg) = @_; + our $app ||= ref($c)->psgi_app; + my $env = $self->get_env($c); + $c->res->from_psgi_response( + $app->($env)); + } + + sub mount_arg :Path(/mounted) Arg(1) { + my ($self, $c, $arg) = @_; + my $uri = $c->uri_for( $self->action_for('local_example_args1'),$arg); + $c->res->body("$uri"); + } + + sub mount_noarg :Path(/mounted_no_arg) { + my ($self, $c) = @_; + my $uri = $c->uri_for( $self->action_for('local_example_args1'),444); + $c->res->body("$uri"); + } + sub get_env { my ($self, $c) = @_; @@ -94,8 +112,6 @@ use strict; } } - $INC{'MyApp/Controller/User.pm'} = __FILE__; - package MyApp; use Catalyst; MyApp->setup; @@ -105,6 +121,20 @@ use strict; use Test::More; use Catalyst::Test 'MyApp'; +{ + my ($res, $c) = ctx_request('/user/mounted/111?path_prefix=1'); + is $c->action, 'user/mounted'; + is $res->content, 'http://localhost/user/user/local_example_args1/111'; + is_deeply $c->req->args, [111]; +} + +{ + my ($res, $c) = ctx_request('/user/mounted/mounted_no_arg?env_path=1'); + is $c->action, 'user/mounted'; + is $res->content, 'http://localhost/user/mounted/user/local_example_args1/444'; + is_deeply $c->req->args, ['mounted_no_arg']; +} + # BEGIN [user/local_example] { my ($res, $c) = ctx_request('/user/local_example');