r12983@zaphod: kd | 2008-04-28 18:10:27 +1000
[catagits/Catalyst-Runtime.git] / t / live_component_controller_action_regexp.t
index 49f7460..be005bc 100644 (file)
@@ -8,11 +8,13 @@ use lib "$FindBin::Bin/lib";
 
 our $iters;
 
-BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
+BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
 
-use Test::More tests => 12*$iters;
+use Test::More tests => 33*$iters;
 use Catalyst::Test 'TestApp';
 
+use Catalyst::Request;
+
 if ( $ENV{CAT_BENCHMARK} ) {
     require Benchmark;
     Benchmark::timethis( $iters, \&run_tests );
@@ -61,4 +63,59 @@ sub run_tests {
             'Content is a serialized Catalyst::Request'
         );
     }
+
+    {
+        ok( my $response = request('http://localhost/action/regexp/mandatory'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Regexp',
+            'Test Class'
+        );
+        my $content = $response->content;
+        my $req = eval $content; 
+
+        is( scalar @{ $req->captures }, 2, 'number of captures' );
+        is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
+        ok( !defined $req->captures->[ 1 ], 'optional capture' );
+    }
+
+    {
+        ok( my $response = request('http://localhost/action/regexp/mandatory/optional'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Action::Regexp',
+            'Test Class'
+        );
+        my $content = $response->content;
+        my $req = eval $content; 
+
+        is( scalar @{ $req->captures }, 2, 'number of captures' );
+        is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
+        is( $req->captures->[ 1 ], '/optional', 'optional capture' );
+    }
+
+    # test localregex in the root controller
+    {
+        ok( my $response = request('http://localhost/localregex'),
+            'Request' );
+        ok( $response->is_success, 'Response Successful 2xx' );
+        is( $response->content_type, 'text/plain', 'Response Content-Type' );
+        is( $response->header('X-Catalyst-Action'),
+            '^localregex$', 'Test Action' );
+        is(
+            $response->header('X-Test-Class'),
+            'TestApp::Controller::Root',
+            'Test Class'
+        );
+    }
 }