:Chained and :Chained('.') tests
Matt S Trout [Thu, 22 Jun 2006 14:52:30 +0000 (14:52 +0000)]
r10072@cain (orig r4402):  phaylon | 2006-06-17 21:57:17 +0000

t/lib/TestApp/Controller/Action/Chained.pm
t/lib/TestApp/Controller/Action/Chained/ParentChain.pm [new file with mode: 0644]
t/live_component_controller_action_chained.t

index 6bb0acf..01fb363 100644 (file)
@@ -9,9 +9,7 @@ sub begin :Private { }
 
 #
 #   TODO
-#   :Chained('') defaulting to controller namespace
-#   :Chained('..') defaulting to action in controller above
-#   :Chained == Chained('/')
+#   :Chained('') means what?
 #
 
 #
@@ -97,6 +95,17 @@ sub opt_pathpart :Chained('opt_pp_start') :Args(1) { }
 sub opt_all_start :Chained('/') :PathPart('chained/optall') :Captures(1) { }
 sub oa :Chained('opt_all_start') { }
 
+#
+#   :Chained is the same as :Chained('/')
+#
+sub rootdef :Chained :PathPart('chained/rootdef') :Args(1) { }
+
+#
+#   the ParentChain controller chains to this action by
+#   specifying :Chained('.')
+#
+sub parentchain :Chained('/') :PathPart('chained/parentchain') :Captures(1) { }
+
 sub end :Private {
   my ($self, $c) = @_;
   my $out = join('; ', map { join(', ', @$_) }
diff --git a/t/lib/TestApp/Controller/Action/Chained/ParentChain.pm b/t/lib/TestApp/Controller/Action/Chained/ParentChain.pm
new file mode 100644 (file)
index 0000000..ec72a38
--- /dev/null
@@ -0,0 +1,13 @@
+package TestApp::Controller::Action::Chained::ParentChain;
+use warnings;
+use strict;
+
+use base qw/ Catalyst::Controller /;
+
+#
+#   Chains to the action /action/chained/parentchain in the
+#   Action::Chained controller.
+#
+sub child :Chained('.') :Args(1) { }
+
+1;
index 46d95a9..7eccb4f 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
 
-use Test::More tests => 66*$iters;
+use Test::More tests => 72*$iters;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -465,4 +465,43 @@ sub run_tests {
             $expected, 'Executed actions' );
         is( $response->content, '1; 2, 3', 'Content OK' );
     }
+
+    #
+    #   Test if :Chained is the same as :Chained('/')
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->rootdef
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/rootdef/23'),
+            ":Chained is the same as :Chained('/')" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; 23', 'Content OK' );
+    }
+
+    #
+    #   Test if :Chained is the same as :Chained('/')
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->parentchain
+          TestApp::Controller::Action::Chained::ParentChain->child
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/parentchain/1/child/2'),
+            ":Chained('.') chains to parent controller action" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '1; 2', 'Content OK' );
+    }
 }