Update changelog
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_auto.t
CommitLineData
50cc3183 1#!perl
2
3use strict;
4use warnings;
5
6use FindBin;
42da66a9 7use lib "$FindBin::Bin/../lib";
50cc3183 8
9our $iters;
10
6b25e555 11BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
50cc3183 12
2688734f 13use Test::More tests => 27*$iters;
50cc3183 14use Catalyst::Test 'TestApp';
15
16if ( $ENV{CAT_BENCHMARK} ) {
17 require Benchmark;
18 Benchmark::timethis( $iters, \&run_tests );
19
20 # new dispatcher:
21 # 11 wallclock secs (10.14 usr + 0.20 sys = 10.34 CPU) @ 15.18/s (n=157)
22 # old dispatcher (r1486):
23 # 11 wallclock secs (10.34 usr + 0.20 sys = 10.54 CPU) @ 13.76/s (n=145)
24}
25else {
26 for ( 1 .. $iters ) {
27 run_tests();
28 }
29}
30
31sub run_tests {
32 # test auto + local method
33 {
34 my @expected = qw[
35 TestApp::Controller::Action::Auto->begin
36 TestApp::Controller::Action::Auto->auto
37 TestApp::Controller::Action::Auto->one
a0a66cb8 38 TestApp::Controller::Root->end
50cc3183 39 ];
40
41 my $expected = join( ", ", @expected );
42
43 ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' );
44 is( $response->header('X-Catalyst-Executed'),
45 $expected, 'Executed actions' );
46 is( $response->content, 'one', 'Content OK' );
47 }
48
49 # test auto + default
50 {
51 my @expected = qw[
52 TestApp::Controller::Action::Auto->begin
53 TestApp::Controller::Action::Auto->auto
54 TestApp::Controller::Action::Auto->default
a0a66cb8 55 TestApp::Controller::Root->end
50cc3183 56 ];
57
58 my $expected = join( ", ", @expected );
59
60 ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' );
61 is( $response->header('X-Catalyst-Executed'),
62 $expected, 'Executed actions' );
63 is( $response->content, 'default', 'Content OK' );
64 }
65
66 # test auto + auto + local
67 {
68 my @expected = qw[
69 TestApp::Controller::Action::Auto::Deep->begin
70 TestApp::Controller::Action::Auto->auto
71 TestApp::Controller::Action::Auto::Deep->auto
72 TestApp::Controller::Action::Auto::Deep->one
a0a66cb8 73 TestApp::Controller::Root->end
50cc3183 74 ];
75
76 my $expected = join( ", ", @expected );
77
78 ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' );
79 is( $response->header('X-Catalyst-Executed'),
80 $expected, 'Executed actions' );
81 is( $response->content, 'deep one', 'Content OK' );
82 }
83
84 # test auto + auto + default
85 {
86 my @expected = qw[
87 TestApp::Controller::Action::Auto::Deep->begin
88 TestApp::Controller::Action::Auto->auto
89 TestApp::Controller::Action::Auto::Deep->auto
90 TestApp::Controller::Action::Auto::Deep->default
a0a66cb8 91 TestApp::Controller::Root->end
50cc3183 92 ];
93
94 my $expected = join( ", ", @expected );
95
96 ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' );
97 is( $response->header('X-Catalyst-Executed'),
98 $expected, 'Executed actions' );
99 is( $response->content, 'deep default', 'Content OK' );
100 }
101
102 # test auto + failing auto + local + end
103 {
104 my @expected = qw[
105 TestApp::Controller::Action::Auto::Abort->begin
106 TestApp::Controller::Action::Auto->auto
107 TestApp::Controller::Action::Auto::Abort->auto
108 TestApp::Controller::Action::Auto::Abort->end
109 ];
110
111 my $expected = join( ", ", @expected );
112
113 ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' );
114 is( $response->header('X-Catalyst-Executed'),
115 $expected, 'Executed actions' );
116 is( $response->content, 'abort end', 'Content OK' );
117 }
118
37d1bca8 119 # test auto + default (bug on invocation of default twice)
50cc3183 120 {
121 my @expected = qw[
37d1bca8 122 TestApp::Controller::Action::Auto::Default->begin
50cc3183 123 TestApp::Controller::Action::Auto->auto
37d1bca8 124 TestApp::Controller::Action::Auto::Default->auto
125 TestApp::Controller::Action::Auto::Default->default
126 TestApp::Controller::Action::Auto::Default->end
50cc3183 127 ];
128
129 my $expected = join( ", ", @expected );
130
37d1bca8 131 ok( my $response = request('http://localhost/action/auto/default/moose'), 'auto + default' );
50cc3183 132 is( $response->header('X-Catalyst-Executed'),
133 $expected, 'Executed actions' );
37d1bca8 134 is( $response->content, 'default (auto: 1)', 'Content OK' );
50cc3183 135 }
2688734f 136
137 # test detach in auto
138 {
139 my @expected = qw[
140 TestApp::Controller::Action::Auto::Detach->begin
141 TestApp::Controller::Action::Auto->auto
142 TestApp::Controller::Action::Auto::Detach->auto
143 TestApp::Controller::Root->end
144 ];
145
146 my $expected = join( ", ", @expected );
147
148 ok( my $response = request('http://localhost/action/auto/detach'), 'auto with detach' );
149 is( $response->header('X-Catalyst-Executed'),
150 $expected, 'Executed actions' );
151 is( $response->content, 'detach auto', 'Content OK' );
152 }
153
154 # test detach in auto forward
155 {
156 my @expected = qw[
157 TestApp::Controller::Action::Auto::Detach->begin
158 TestApp::Controller::Action::Auto->auto
159 TestApp::Controller::Action::Auto::Detach->auto
160 TestApp::Controller::Action::Auto::Detach->with_forward_detach
161 TestApp::Controller::Root->end
162 ];
163
164 my $expected = join( ", ", @expected );
165
166 ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1'), 'auto with_forward_detach' );
167 is( $response->header('X-Catalyst-Executed'),
168 $expected, 'Executed actions' );
169 is( $response->content, 'detach with_forward_detach', 'Content OK' );
170 }
171
172 # test detach in auto forward detach action
173 {
174 my @expected = qw[
175 TestApp::Controller::Action::Auto::Detach->begin
176 TestApp::Controller::Action::Auto->auto
177 TestApp::Controller::Action::Auto::Detach->auto
178 TestApp::Controller::Action::Auto::Detach->with_forward_detach
179 TestApp::Controller::Action::Auto::Detach->detach_action
180 TestApp::Controller::Root->end
181 ];
182
183 my $expected = join( ", ", @expected );
184
185 ok( my $response = request('http://localhost/action/auto/detach?with_forward_detach=1&detach_to_action=1'), 'auto with_forward_detach to detach_action' );
186 is( $response->header('X-Catalyst-Executed'),
187 $expected, 'Executed actions' );
188 is( $response->content, 'detach_action', 'Content OK' );
189 }
50cc3183 190}