From: Matt S Trout Date: Thu, 22 Jun 2006 14:51:44 +0000 (+0000) Subject: Added ChildOf tests for args passed to actions X-Git-Tag: 5.7099_04~493 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=b25353e54699bb335bd54eece6f7cab5714346a0 Added ChildOf tests for args passed to actions r10063@cain (orig r4394): phaylon | 2006-06-17 16:26:41 +0000 --- diff --git a/t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm b/t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm new file mode 100644 index 0000000..831f778 --- /dev/null +++ b/t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm @@ -0,0 +1,34 @@ +package TestApp::Controller::Action::ChildOf::PassedArgs; +use warnings; +use strict; + +use base qw( Catalyst::Controller ); + +# +# This controller builds a simple chain of three actions that +# will output the arguments they got passed to @_ after the +# context object. We do this to test if that passing works +# as it should. +# + +sub first : PathPart('childof/passedargs/a') ChildOf('/') Captures(1) { + my ( $self, $c, $arg ) = @_; + $c->stash->{ passed_args } = [ $arg ]; +} + +sub second : PathPart('b') ChildOf('first') Captures(1) { + my ( $self, $c, $arg ) = @_; + push @{ $c->stash->{ passed_args } }, $arg; +} + +sub third : PathPart('c') ChildOf('second') Args(1) { + my ( $self, $c, $arg ) = @_; + push @{ $c->stash->{ passed_args } }, $arg; +} + +sub end : Private { + my ( $self, $c ) = @_; + $c->response->body( join '; ', @{ $c->stash->{ passed_args } } ); +} + +1; diff --git a/t/live_component_controller_action_childof.t b/t/live_component_controller_action_childof.t index 384f849..4c32a15 100644 --- a/t/live_component_controller_action_childof.t +++ b/t/live_component_controller_action_childof.t @@ -10,7 +10,7 @@ our $iters; BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; } -use Test::More tests => 54*$iters; +use Test::More tests => 57*$iters; use Catalyst::Test 'TestApp'; if ( $ENV{CAT_BENCHMARK} ) { @@ -383,4 +383,26 @@ sub run_tests { $expected, 'Executed actions' ); is( $response->content, '1; 2', 'Content OK' ); } + + # + # This is for testing if the arguments got passed to the actions + # correctly. + # + { + my @expected = qw[ + TestApp::Controller::Action::ChildOf->begin + TestApp::Controller::Action::ChildOf::PassedArgs->first + TestApp::Controller::Action::ChildOf::PassedArgs->second + TestApp::Controller::Action::ChildOf::PassedArgs->third + TestApp::Controller::Action::ChildOf::PassedArgs->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/childof/passedargs/a/1/b/2/c/3'), + 'Correct arguments passed to actions' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, '1; 2; 3', 'Content OK' ); + } }