Commit | Line | Data |
50cc3183 |
1 | #!perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use FindBin; |
42da66a9 |
7 | use lib "$FindBin::Bin/../lib"; |
50cc3183 |
8 | |
9 | our $iters; |
10 | |
6b25e555 |
11 | BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; } |
50cc3183 |
12 | |
873b98ee |
13 | use Test::More tests => 38*$iters; |
50cc3183 |
14 | use Catalyst::Test 'TestApp'; |
15 | |
048f45ee |
16 | use Catalyst::Request; |
17 | |
50cc3183 |
18 | if ( $ENV{CAT_BENCHMARK} ) { |
19 | require Benchmark; |
20 | Benchmark::timethis( $iters, \&run_tests ); |
21 | } |
22 | else { |
23 | for ( 1 .. $iters ) { |
24 | run_tests(); |
25 | } |
26 | } |
27 | |
28 | sub 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 | } |
2f381252 |
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 | } |
873b98ee |
121 | |
122 | { |
123 | my $url = 'http://localhost/action/regexp/redirect/life/universe/42/everything'; |
124 | ok( my $response = request($url), |
125 | 'Request' ); |
126 | ok( $response->is_redirect, 'Response is redirect' ); |
127 | is( $response->header('X-Catalyst-Action'), |
128 | '^action/regexp/redirect/(\w+)/universe/(\d+)/everything$', 'Test Action' ); |
129 | is( |
130 | $response->header('X-Test-Class'), |
131 | 'TestApp::Controller::Action::Regexp', |
132 | 'Test Class' |
133 | ); |
134 | is( |
c09cc357 |
135 | $response->header('location'), |
136 | $response->request->uri, |
873b98ee |
137 | 'Redirect URI is the same as the request URI' |
138 | ); |
139 | } |
50cc3183 |
140 | } |
873b98ee |
141 | |