remove warning for undef captures
[catagits/Catalyst-Runtime.git] / t / live_component_controller_action_regexp.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
12
13 use Test::More tests => 28*$iters;
14 use Catalyst::Test 'TestApp';
15
16 if ( $ENV{CAT_BENCHMARK} ) {
17     require Benchmark;
18     Benchmark::timethis( $iters, \&run_tests );
19 }
20 else {
21     for ( 1 .. $iters ) {
22         run_tests();
23     }
24 }
25
26 sub run_tests {
27     {
28         ok( my $response = request('http://localhost/action/regexp/10/hello'),
29             'Request' );
30         ok( $response->is_success, 'Response Successful 2xx' );
31         is( $response->content_type, 'text/plain', 'Response Content-Type' );
32         is( $response->header('X-Catalyst-Action'),
33             '^action/regexp/(\d+)/(\w+)$', 'Test Action' );
34         is(
35             $response->header('X-Test-Class'),
36             'TestApp::Controller::Action::Regexp',
37             'Test Class'
38         );
39         like(
40             $response->content,
41             qr/^bless\( .* 'Catalyst::Request' \)$/s,
42             'Content is a serialized Catalyst::Request'
43         );
44     }
45
46     {
47         ok( my $response = request('http://localhost/action/regexp/hello/10'),
48             'Request' );
49         ok( $response->is_success, 'Response Successful 2xx' );
50         is( $response->content_type, 'text/plain', 'Response Content-Type' );
51         is( $response->header('X-Catalyst-Action'),
52             '^action/regexp/(\w+)/(\d+)$', 'Test Action' );
53         is(
54             $response->header('X-Test-Class'),
55             'TestApp::Controller::Action::Regexp',
56             'Test Class'
57         );
58         like(
59             $response->content,
60             qr/^bless\( .* 'Catalyst::Request' \)$/s,
61             'Content is a serialized Catalyst::Request'
62         );
63     }
64
65     {
66         ok( my $response = request('http://localhost/action/regexp/mandatory'),
67             'Request' );
68         ok( $response->is_success, 'Response Successful 2xx' );
69         is( $response->content_type, 'text/plain', 'Response Content-Type' );
70         is( $response->header('X-Catalyst-Action'),
71             '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
72         is(
73             $response->header('X-Test-Class'),
74             'TestApp::Controller::Action::Regexp',
75             'Test Class'
76         );
77         my $content = $response->content;
78         my $req = eval $content; 
79
80         is( scalar @{ $req->captures }, 2, 'number of captures' );
81         is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
82         ok( !defined $req->captures->[ 1 ], 'optional capture' );
83     }
84
85     {
86         ok( my $response = request('http://localhost/action/regexp/mandatory/optional'),
87             'Request' );
88         ok( $response->is_success, 'Response Successful 2xx' );
89         is( $response->content_type, 'text/plain', 'Response Content-Type' );
90         is( $response->header('X-Catalyst-Action'),
91             '^action/regexp/(mandatory)(/optional)?$', 'Test Action' );
92         is(
93             $response->header('X-Test-Class'),
94             'TestApp::Controller::Action::Regexp',
95             'Test Class'
96         );
97         my $content = $response->content;
98         my $req = eval $content; 
99
100         is( scalar @{ $req->captures }, 2, 'number of captures' );
101         is( $req->captures->[ 0 ], 'mandatory', 'mandatory capture' );
102         is( $req->captures->[ 1 ], '/optional', 'optional capture' );
103     }
104 }