Tests, fix args as well as captureargs and be less violent - only encode /
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_chained.t
index 74db1f2..099c833 100644 (file)
@@ -10,7 +10,7 @@ our $iters;
 
 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 143*$iters;
+use Test::More;
 use Catalyst::Test 'TestApp';
 
 if ( $ENV{CAT_BENCHMARK} ) {
@@ -815,7 +815,7 @@ sub run_tests {
         my @expected = qw[
           TestApp::Controller::Action::Chained::Root->rootsub
           TestApp::Controller::Action::Chained::Root->endpointsub
-          TestApp->end
+          TestApp::Controller::Root->end
         ];
 
         my $expected = join( ", ", @expected );
@@ -1004,4 +1004,41 @@ sub run_tests {
                 $expected, 'Executed actions' );
         }
     }
+
+    {
+        ok( my $content =
+            get('http://localhost/chained/capture%2Farg%3B/return_arg/foo%2Fbar%3B'),
+            'request with URI-encoded arg' );
+        like( $content, qr{foo/bar;\z}, 'args decoded' );
+        like( $content, qr{capture/arg;}, 'captureargs decoded' );
+    }
+    {
+        ok( my $content =
+            get('http://localhost/chained/return_arg_decoded/foo%2Fbar%3B'),
+            'request with URI-encoded arg' );
+        like( $content, qr{foo/bar;\z}, 'args decoded' );
+    }
+    
+    # Test round tripping, specifically the / character %2F in uri_for:
+    # not being able to feed it back action + captureargs and args into uri for and result in the original
+    # request uri is a major piece of suck ;)
+    # FIXME - what about people who have code to hack around this and manually uri encode args and captures
+    #         themselves, erk! 
+    foreach my $thing (
+        ['foo', 'bar'],
+        ['foo%2Fbar', 'baz'],
+        ['foo', 'bar%2Fbaz'],
+        ['foo%2Fbar', 'baz%2Fquux'],
+        ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz' => 'quux%2Ffrood'}],
+        ['foo%2Fbar', 'baz%2Fquux', { foo => 'bar', 'baz%2Ffnoo' => 'quux%2Ffrood'}],
+    ) {
+        my $uri = 'http://localhost/chained/roundtrip_urifor/' . $thing->[0] . '/' . $thing->[1];
+        $uri .= '?' . join('&', map { $_ .'='. $thing->[2]->{$_}} sort keys %{$thing->[2]}) if $thing->[2];
+        ok( my $content =
+            get($uri),
+            'request ' . $uri . ' ok');
+        is( $content, $uri, 'uri can round trip through uri_for' );
+    }
 }
+
+done_testing;