Added ChildOf tests for args passed to actions
Matt S Trout [Thu, 22 Jun 2006 14:51:44 +0000 (14:51 +0000)]
r10063@cain (orig r4394):  phaylon | 2006-06-17 16:26:41 +0000

t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm [new file with mode: 0644]
t/live_component_controller_action_childof.t

diff --git a/t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm b/t/lib/TestApp/Controller/Action/ChildOf/PassedArgs.pm
new file mode 100644 (file)
index 0000000..831f778
--- /dev/null
@@ -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;
index 384f849..4c32a15 100644 (file)
@@ -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' );
+    }
 }