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