Change Catalsyt _parse_attrs so that when sub attr handlers:
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_action.t
CommitLineData
734a1e11 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
42da66a9 7use lib "$FindBin::Bin/../lib";
734a1e11 8
9our $iters;
10
6b25e555 11BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
734a1e11 12
d87210ec 13use Test::More;
734a1e11 14use Catalyst::Test 'TestApp';
15
16if ( $ENV{CAT_BENCHMARK} ) {
17 require Benchmark;
18 Benchmark::timethis( $iters, \&run_tests );
19}
20else {
21 for ( 1 .. $iters ) {
22 run_tests();
23 }
24}
25
26sub run_tests {
27 {
28 ok( my $response = request('http://localhost/action_action_one'),
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_action_one', 'Test Action' );
34 is(
35 $response->header('X-Test-Class'),
36 'TestApp::Controller::Action::Action',
37 'Test Class'
38 );
39 is( $response->header('X-Action'), 'works' );
40 like(
41 $response->content,
42 qr/^bless\( .* 'Catalyst::Request' \)$/s,
43 'Content is a serialized Catalyst::Request'
44 );
45 }
46
47 {
48 ok( my $response = request('http://localhost/action_action_two'),
49 'Request' );
50 ok( $response->is_success, 'Response Successful 2xx' );
51 is( $response->content_type, 'text/plain', 'Response Content-Type' );
52 is( $response->header('X-Catalyst-Action'),
53 'action_action_two', 'Test Action' );
54 is(
55 $response->header('X-Test-Class'),
56 'TestApp::Controller::Action::Action',
57 'Test Class'
58 );
59 is( $response->header('X-Action-After'), 'awesome' );
60 like(
61 $response->content,
62 qr/^bless\( .* 'Catalyst::Request' \)$/s,
63 'Content is a serialized Catalyst::Request'
64 );
65 }
66
67 {
68 ok(
69 my $response =
70 request('http://localhost/action_action_three/one/two'),
71 'Request'
72 );
73 ok( $response->is_success, 'Response Successful 2xx' );
74 is( $response->content_type, 'text/plain', 'Response Content-Type' );
75 is( $response->header('X-Catalyst-Action'),
76 'action_action_three', 'Test Action' );
77 is(
78 $response->header('X-Test-Class'),
79 'TestApp::Controller::Action::Action',
80 'Test Class'
81 );
82 is( $response->header('X-TestAppActionTestBefore'), 'one' );
83 like(
84 $response->content,
85 qr/^bless\( .* 'Catalyst::Request' \)$/s,
86 'Content is a serialized Catalyst::Request'
87 );
88 }
89
9287719b 90 {
91 ok( my $response = request('http://localhost/action_action_four'),
92 'Request' );
93 ok( $response->is_success, 'Response Successful 2xx' );
94 is( $response->content_type, 'text/plain', 'Response Content-Type' );
95 is( $response->header('X-Catalyst-Action'),
96 'action_action_four', 'Test Action' );
97 is(
98 $response->header('X-Test-Class'),
99 'TestApp::Controller::Action::Action',
100 'Test Class'
101 );
102 is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' );
103 like(
104 $response->content,
105 qr/^bless\( .* 'Catalyst::Request' \)$/s,
106 'Content is a serialized Catalyst::Request'
107 );
108 }
196932de 109
5d8129e9 110 {
111 ok( my $response = request('http://localhost/action_action_five'),
112 'Request' );
113 ok( $response->is_success, 'Response Successful 2xx' );
114 is( $response->content_type, 'text/plain', 'Response Content-Type' );
115 is( $response->header('X-Catalyst-Action'),
116 'action_action_five', 'Test Action' );
117 is(
118 $response->header('X-Test-Class'),
119 'TestApp::Controller::Action::Action',
120 'Test Class'
121 );
122 is( $response->header('X-Action'), 'works' );
123 like(
124 $response->content,
125 qr/^bless\( .* 'Catalyst::Request' \)$/s,
126 'Content is a serialized Catalyst::Request'
127 );
128 }
5d8129e9 129
130 {
131 ok( my $response = request('http://localhost/action_action_six'),
132 'Request' );
133 ok( $response->is_success, 'Response Successful 2xx' );
134 is( $response->content_type, 'text/plain', 'Response Content-Type' );
135 is( $response->header('X-Catalyst-Action'),
136 'action_action_six', 'Test Action' );
137 is(
138 $response->header('X-Test-Class'),
139 'TestApp::Controller::Action::Action',
140 'Test Class'
141 );
142 is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' );
143 like(
144 $response->content,
145 qr/^bless\( .* 'Catalyst::Request' \)$/s,
146 'Content is a serialized Catalyst::Request'
147 );
148 }
9287719b 149
d87210ec 150 {
151 ok( my $response = request('http://localhost/action_action_seven'),
152 'Request' );
153 ok( $response->is_success, 'Response Successful 2xx' );
154 is( $response->content_type, 'text/plain', 'Response Content-Type' );
155 is( $response->header('X-Catalyst-Action'),
156 'action_action_seven', 'Test Action' );
157 is(
158 $response->header('X-Test-Class'),
159 'TestApp::Controller::Action::Action',
160 'Test Class'
161 );
162 is( $response->header('X-TestExtraArgsAction'), '42,23', 'Extra args get passed to action contstructor' );
163 like(
164 $response->content,
165 qr/^bless\( .* 'Catalyst::Request' \)$/s,
166 'Content is a serialized Catalyst::Request'
167 );
168 }
7d81af7e 169
170 {
171 ok( my $response = request('http://localhost/action_action_eight'),
172 'Request' );
173 ok( $response->is_success, 'Response Successful 2xx' );
174 is( $response->content_type, 'text/plain', 'Response Content-Type' );
175 is( $response->header('X-Catalyst-Action'),
176 'action_action_eight', 'Test Action' );
177 is(
178 $response->header('X-Test-Class'),
179 'TestApp::Controller::Action::Action',
180 'Test Class'
181 );
182 like(
183 $response->content,
184 qr/^bless\( .* 'Catalyst::Action' \)$/s,
185 'Content is a serialized Catalyst::Action'
186 );
187
b09bbdcb 188 require Catalyst::Action; # when running against a remote server, we
189 # need to load the class in the test process
190 # to be able to introspect the action instance
191 # later.
7d81af7e 192 my $action = eval $response->content;
193 is_deeply $action->attributes->{extra_attribute}, [13];
194 is_deeply $action->attributes->{another_extra_attribute}, ['foo'];
195 }
bf7c9c87 196 {
197 ok( my $response = request('http://localhost/action_action_nine'),
198 'Request' );
199 ok( $response->is_success, 'Response Successful 2xx' );
200 is( $response->content_type, 'text/plain', 'Response Content-Type' );
201 is( $response->header('X-Catalyst-Action'),
202 'action_action_nine', 'Test Action' );
203 is(
204 $response->header('X-Test-Class'),
205 'TestApp::Controller::Action::Action',
206 'Test Class'
207 );
208 is( $response->header('X-TestExtraArgsAction'), '42,13', 'Extra args get passed to action constructor' );
209 like(
210 $response->content,
211 qr/^bless\( .* 'Catalyst::Request' \)$/s,
212 'Content is a serialized Catalyst::Request'
213 );
214 }
734a1e11 215}
d87210ec 216
217done_testing;