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