- Fixed CAT_BENCH_ITERS :)
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / forward.t
1 #!perl
2
3 use strict;
4 use warnings;
5
6 use FindBin;
7 use lib "$FindBin::Bin/../../../lib";
8
9 our $iters;
10
11 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; }
12
13 use Test::More tests => 30*$iters;
14 use Catalyst::Test 'TestApp';
15
16 if ( $ENV{CAT_BENCHMARK} ) {
17     require Benchmark;
18     Benchmark::timethis( $iters, \&run_tests );
19 }
20 else {
21     for ( 1 .. $iters ) {
22         run_tests();
23     }
24 }
25
26 sub run_tests {
27     {
28         my @expected = qw[
29           TestApp::Controller::Action::Forward->begin
30           TestApp::Controller::Action::Forward->one
31           TestApp::Controller::Action::Forward->two
32           TestApp::Controller::Action::Forward->three
33           TestApp::Controller::Action::Forward->four
34           TestApp::Controller::Action::Forward->five
35           TestApp::View::Dump::Request->process
36         ];
37
38         my $expected = join( ", ", @expected );
39
40         # Test forward to global private action
41         ok( my $response = request('http://localhost/action/forward/global'),
42             'Request' );
43         ok( $response->is_success, 'Response Successful 2xx' );
44         is( $response->content_type, 'text/plain', 'Response Content-Type' );
45         is( $response->header('X-Catalyst-Action'),
46             'action/forward/global', 'Main Class Action' );
47
48         # Test forward to chain of actions.
49         ok( $response = request('http://localhost/action/forward/one'),
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/forward/one', 'Test Action' );
55         is(
56             $response->header('X-Test-Class'),
57             'TestApp::Controller::Action::Forward',
58             'Test Class'
59         );
60         is( $response->header('X-Catalyst-Executed'),
61             $expected, 'Executed actions' );
62         like(
63             $response->content,
64             qr/^bless\( .* 'Catalyst::Request' \)$/s,
65             'Content is a serialized Catalyst::Request'
66         );
67     }
68
69     {
70         my @expected = qw[
71           TestApp::Controller::Action::Forward->begin
72           TestApp::Controller::Action::Forward->jojo
73           TestApp::Controller::Action::Forward->one
74           TestApp::Controller::Action::Forward->two
75           TestApp::Controller::Action::Forward->three
76           TestApp::Controller::Action::Forward->four
77           TestApp::Controller::Action::Forward->five
78           TestApp::View::Dump::Request->process
79           TestApp::Controller::Action::Forward->three
80           TestApp::Controller::Action::Forward->four
81           TestApp::Controller::Action::Forward->five
82           TestApp::View::Dump::Request->process
83         ];
84
85         my $expected = join( ", ", @expected );
86
87         ok( my $response = request('http://localhost/action/forward/jojo'),
88             'Request' );
89         ok( $response->is_success, 'Response Successful 2xx' );
90         is( $response->content_type, 'text/plain', 'Response Content-Type' );
91         is( $response->header('X-Catalyst-Action'),
92             'action/forward/jojo', 'Test Action' );
93         is(
94             $response->header('X-Test-Class'),
95             'TestApp::Controller::Action::Forward',
96             'Test Class'
97         );
98         is( $response->header('X-Catalyst-Executed'),
99             $expected, 'Executed actions' );
100         like(
101             $response->content,
102             qr/^bless\( .* 'Catalyst::Request' \)$/s,
103             'Content is a serialized Catalyst::Request'
104         );
105     }
106
107     {
108         ok(
109             my $response =
110               request('http://localhost/action/forward/with_args/old'),
111             'Request with args'
112         );
113         ok( $response->is_success, 'Response Successful 2xx' );
114         is( $response->content, 'old' );
115     }
116
117     {
118         ok(
119             my $response = request(
120                 'http://localhost/action/forward/with_method_and_args/old'),
121             'Request with args and method'
122         );
123         ok( $response->is_success, 'Response Successful 2xx' );
124         is( $response->content, 'old' );
125     }
126
127     # test forward with embedded args
128     {
129         ok(
130             my $response =
131               request('http://localhost/action/forward/args_embed_relative'),
132             'Request'
133         );
134         ok( $response->is_success, 'Response Successful 2xx' );
135         is( $response->content, 'ok' );
136     }
137
138     {
139         ok(
140             my $response =
141               request('http://localhost/action/forward/args_embed_absolute'),
142             'Request'
143         );
144         ok( $response->is_success, 'Response Successful 2xx' );
145         is( $response->content, 'ok' );
146     }
147 }