chmod -x test scripts
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_chained.t
index 6f01812..d388a3b 100644 (file)
@@ -1,5 +1,3 @@
-#!perl
-
 use strict;
 use warnings;
 
@@ -11,6 +9,8 @@ our $iters;
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
 use Test::More;
+use URI;
+use URI::QueryParam;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -53,7 +53,7 @@ sub run_tests {
     {
         my $expected = undef;
 
-        ok( my $response = request('http://localhost/chained/foo/1/end'), 
+        ok( my $response = request('http://localhost/chained/foo/1/end'),
             'chained + local endpoint; missing last argument' );
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
@@ -112,7 +112,7 @@ sub run_tests {
 
         my $expected = join( ", ", @expected );
 
-        ok( my $response = request('http://localhost/chained/foo2/10/20/end2/15/25'), 
+        ok( my $response = request('http://localhost/chained/foo2/10/20/end2/15/25'),
             'chained + local (2 args each)' );
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
@@ -407,7 +407,7 @@ sub run_tests {
     }
 
     #
-    #   This is for testing if the arguments got passed to the actions 
+    #   This is for testing if the arguments got passed to the actions
     #   correctly.
     #
     {
@@ -771,6 +771,44 @@ sub run_tests {
     }
 
     #
+    # Test throwing an error in the middle of a chain.
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->chain_error_a
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/chain_error/1/end/2'),
+            "Break a chain in the middle" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, 'FATAL ERROR: break in the middle of a chain', 'Content OK' );
+    }
+
+    #
+    # Test dieing in the middle of a chain.
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->chain_die_a
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/chain_die/1/end/2'),
+            "Break a chain in the middle" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, 'FATAL ERROR: Caught exception in TestApp::Controller::Action::Chained->chain_die_a "die in the middle of a chain"', 'Content OK' );
+    }
+
+    #
     #   Tests that an uri_for to a chained root index action
     #   returns the right value.
     #
@@ -999,8 +1037,8 @@ sub run_tests {
     # With args given, run "all"
         ok( $response = request('http://localhost/argsorder/X'),
             'Correct arg order ran' );
-        is( $response->header('X-Catalyst-Executed'), 
-        join(", ", 
+        is( $response->header('X-Catalyst-Executed'),
+        join(", ",
          qw[
              TestApp::Controller::Action::Chained->begin
              TestApp::Controller::Action::Chained::ArgsOrder->base
@@ -1009,7 +1047,7 @@ sub run_tests {
           ])
       );
         is( $response->content, 'base; ; all; X', 'Content OK' );
-    
+
     }
 
     #
@@ -1050,11 +1088,11 @@ sub run_tests {
         is( $response->header('X-Catalyst-Executed'),
             $expected, 'Executed actions' );
     }
-    
+
     #
     #   */search
     #   doc/*
-    # 
+    #
     #   request for doc/search should end up in doc/*
     {
         my @expected = qw[
@@ -1108,9 +1146,14 @@ sub run_tests {
         ok( my $content =
             get('http://localhost/' . $path),
             'request ' . $path . ' ok');
+        my $exp = URI->new('http://localhost:3000' . $path);
+        my ($want) = $content =~ m{/chained/(.*)};
+        my $got = URI->new('http://localhost:3000/chained/' . $want);
         # Just check that the path matches, as who the hell knows or cares
         # where the app is based (live tests etc)
-        ok( index($content, $path) > 1, 'uri can round trip through uri_for' )
+        is $got->path, $exp->path, "uri $path can round trip through uri_for (path)"
+            or diag("Expected $path, got $content");
+        is_deeply $got->query_form_hash, $exp->query_form_hash, "uri $path can round trip through uri_for (query)"
             or diag("Expected $path, got $content");
     }