ChildOf Tests: chaining and dispatching on arg count
Matt S Trout [Thu, 22 Jun 2006 14:49:54 +0000 (14:49 +0000)]
r9813@cain (orig r4294):  phaylon | 2006-06-05 21:40:53 +0000

t/lib/TestApp/Controller/Action/ChildOf.pm
t/live_component_controller_action_childof.t

index 2bb2818..377c3d8 100644 (file)
@@ -7,14 +7,26 @@ use base qw/Catalyst::Controller/;
 
 sub begin :Private { }
 
-sub foo :PathPart('childof/foo') :Captures(1) :ChildOf('/') { }
+sub foo  :PathPart('childof/foo')  :Captures(1) :ChildOf('/') { }
+sub foo2 :PathPart('childof/foo2') :Captures(2) :ChildOf('/') { }
 
 sub bar :PathPart('childof/bar') :ChildOf('/') { }
 
-sub endpoint :PathPart('end') :ChildOf('/action/childof/foo') :Args(1) { }
+sub endpoint  :PathPart('end')  :ChildOf('/action/childof/foo')  :Args(1) { }
+sub endpoint2 :PathPart('end2') :ChildOf('/action/childof/foo2') :Args(2) { }
 
 sub finale :ChildOf('bar') :Args { }
 
+sub one   :PathPart('childof/one') :ChildOf('/')                   :Captures(1) { }
+sub two   :PathPart('two')         :ChildOf('/action/childof/one') :Captures(2) { }
+
+sub three_end :PathPart('three')       :ChildOf('two') :Args(3) { }
+sub one_end   :PathPart('childof/one') :ChildOf('/')   :Args(1) { }
+sub two_end   :PathPart('two')         :ChildOf('one') :Args(2) { }
+
+sub multi1 :PathPart('childof/multi') :ChildOf('/') :Args(1) { }
+sub multi2 :PathPart('childof/multi') :ChildOf('/') :Args(2) { }
+
 sub end :Private {
   my ($self, $c) = @_;
   my $out = join('; ', map { join(', ', @$_) }
index d1a0278..4e1de89 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
 
-use Test::More tests => 9*$iters;
+use Test::More tests => 27*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -22,7 +22,7 @@ else {
         run_tests();
     }
 }
-    
+
 sub run_tests {
     {
         my @expected = qw[
@@ -31,9 +31,9 @@ sub run_tests {
           TestApp::Controller::Action::ChildOf->endpoint
           TestApp::Controller::Action::ChildOf->end
         ];
-    
+
         my $expected = join( ", ", @expected );
-    
+
         ok( my $response = request('http://localhost/childof/foo/1/end/2'), 'childof + local endpoint' );
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
@@ -46,9 +46,9 @@ sub run_tests {
           TestApp::Controller::Action::ChildOf::Foo->spoon
           TestApp::Controller::Action::ChildOf->end
         ];
-    
+
         my $expected = join( ", ", @expected );
-    
+
         ok( my $response = request('http://localhost/childof/foo/1/spoon'), 'childof + subcontroller endpoint' );
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
@@ -61,12 +61,106 @@ sub run_tests {
           TestApp::Controller::Action::ChildOf->finale
           TestApp::Controller::Action::ChildOf->end
         ];
-    
+
         my $expected = join( ", ", @expected );
-    
+
         ok( my $response = request('http://localhost/childof/bar/1/spoon'), 'childof + relative endpoint' );
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
         is( $response->content, '; 1, spoon', 'Content OK' );
     }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->foo2
+          TestApp::Controller::Action::ChildOf->endpoint2
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/foo2/10/20/end2/15/25'), 
+            'childof + local (2 args each)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '10, 20; 15, 25', 'Content OK' );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->one_end
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/one/23'),
+            'three-chain (only first)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; 23', 'Content OK' );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->one
+          TestApp::Controller::Action::ChildOf->two_end
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/one/23/two/23/46'),
+            'three-chain (up to second)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '23; 23, 46', 'Content OK' );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->one
+          TestApp::Controller::Action::ChildOf->two
+          TestApp::Controller::Action::ChildOf->three_end
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/one/23/two/23/46/three/1/2/3'),
+            'three-chain (all three)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '23, 23, 46; 1, 2, 3', 'Content OK' );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->multi1
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/multi/23'),
+            'multi-action (one arg)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; 23', 'Content OK' );
+    }
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->multi2
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/multi/23/46'),
+            'multi-action (two args)' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; 23, 46', 'Content OK' );
+    }
 }