Fix http server test, which also runs all the tests at a sub-path
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_chained.t
index 7977875..b4907f7 100644 (file)
@@ -847,6 +847,30 @@ sub run_tests {
     }
 
     #
+    #   Complex path with multiple non-capturing pathparts
+    # PathPart('') CaptureArgs(0), PathPart('foo') CaptureArgs(0), PathPart('') Args(0)
+    # should win over PathPart('') CaptureArgs(1), PathPart('') Args(0)
+    #
+    {
+        my @expected = qw[
+          TestApp::Controller::Action::Chained->begin
+          TestApp::Controller::Action::Chained->mult_nopp2_base
+          TestApp::Controller::Action::Chained->mult_nopp2_nocap
+          TestApp::Controller::Action::Chained->mult_nopp2_action
+          TestApp::Controller::Action::Chained->mult_nopp2_action_default
+          TestApp::Controller::Action::Chained->end
+        ];
+
+        my $expected = join( ", ", @expected );
+
+        ok( my $response = request('http://localhost/chained/mult_nopp2/action'),
+            "Complex path with multiple non-capturing pathparts" );
+        is( $response->header('X-Catalyst-Executed'),
+            $expected, 'Executed actions' );
+        is( $response->content, '; ', 'Content OK' );
+    }
+
+    #
     #   Higher Args() hiding more specific CaptureArgs chains sections
     #
     {
@@ -1084,10 +1108,30 @@ 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");
+        my %got_q = map { split /=/ } split /\&/, ($got->query||'');
+        my %exp_q = map { split /=/ } split /\&/, ($exp->query||'');
+        is_deeply \%got_q, \%exp_q, "uri $path can round trip through uri_for (query)"
+            or diag("Expected $path, got $content");
+    }
+
+    #
+    #   match_captures
+    #
+    {
+
+        ok( my $response = request('http://localhost/chained/match_captures/foo/bar'), 'match_captures: falling through' );
+        is($response->header('X-TestAppActionTestMatchCaptures'), 'fallthrough', 'match_captures: fell through');
+
+        ok($response = request('http://localhost/chained/match_captures/force/bar'), 'match_captures: *not* falling through' );
+        is($response->header('X-TestAppActionTestMatchCaptures'), 'forcing', 'match_captures: forced');
+        is($response->header('X-TestAppActionTestMatchCapturesHasRan'), 'yes', 'match_captures: actually ran');
     }
 }