optional PathPart and PathPart+Args tests for ChildOf
Matt S Trout [Thu, 22 Jun 2006 14:52:04 +0000 (14:52 +0000)]
r10067@cain (orig r4398):  phaylon | 2006-06-17 21:13:45 +0000

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

index ba6e5d2..24fe369 100644 (file)
@@ -8,6 +8,13 @@ use base qw/Catalyst::Controller/;
 sub begin :Private { }
 
 #
+#   TODO
+#   :ChildOf('') defaulting to controller namespace
+#   :ChildOf('..') defaulting to action in controller above
+#   :ChildOf == ChildOf('/')
+#
+
+#
 #   Simple parent/child action test
 #
 sub foo  :PathPart('childof/foo')  :Captures(1) :ChildOf('/') { }
@@ -78,6 +85,18 @@ sub priority_b2_end :PathPart('end') :ChildOf('priority_b2') :Args(1) { }
 #
 sub opt_args :PathPart('childof/opt_args') :ChildOf('/') { }
 
+#
+#   Optional PathPart test -> /childof/optpp/*/opt_pathpart/*
+#
+sub opt_pp_start :ChildOf('/') :PathPart('childof/optpp') :Captures(1) { }
+sub opt_pathpart :ChildOf('opt_pp_start') :Args(1) { }
+
+#
+#   Optional Args *and* PathPart -> /childof/optall/*/oa/...
+#
+sub opt_all_start :ChildOf('/') :PathPart('childof/optall') :Captures(1) { }
+sub oa :ChildOf('opt_all_start') { }
+
 sub end :Private {
   my ($self, $c) = @_;
   my $out = join('; ', map { join(', ', @$_) }
index 8ae78d2..712d033 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
 
-use Test::More tests => 60*$iters;
+use Test::More tests => 66*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -425,4 +425,44 @@ sub run_tests {
             $expected, 'Executed actions' );
         is( $response->content, '; 1, 2, 3', 'Content OK' );
     }
+
+    #
+    #   Tests for optional PathPart attribute.
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->opt_pp_start
+          TestApp::Controller::Action::ChildOf->opt_pathpart
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/optpp/1/opt_pathpart/2'),
+            'Optional :PathName attribute working' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '1; 2', 'Content OK' );
+    }
+
+    #
+    #   Tests for optional PathPart *and* Args attributes.
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::ChildOf->begin
+          TestApp::Controller::Action::ChildOf->opt_all_start
+          TestApp::Controller::Action::ChildOf->oa
+          TestApp::Controller::Action::ChildOf->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/childof/optall/1/oa/2/3'),
+            'Optional :PathName *and* :Args attributes working' );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '1; 2, 3', 'Content OK' );
+    }
 }