Fixed test
[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 use Test::More tests => 30;
10 use Catalyst::Test 'TestApp';
11
12 {
13     my @expected = qw[
14       TestApp::Controller::Action::Forward->begin
15       TestApp::Controller::Action::Forward->one
16       TestApp::Controller::Action::Forward->two
17       TestApp::Controller::Action::Forward->three
18       TestApp::Controller::Action::Forward->four
19       TestApp::Controller::Action::Forward->five
20       TestApp::View::Dump::Request->process
21     ];
22
23     my $expected = join( ", ", @expected );
24
25     # Test forward to global private action
26     ok( my $response = request('http://localhost/action/forward/global'),
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/forward/global', 'Main Class Action' );
32
33     # Test forward to chain of actions.
34     ok( $response = request('http://localhost/action/forward/one'), 'Request' );
35     ok( $response->is_success, 'Response Successful 2xx' );
36     is( $response->content_type, 'text/plain', 'Response Content-Type' );
37     is( $response->header('X-Catalyst-Action'),
38         'action/forward/one', 'Test Action' );
39     is(
40         $response->header('X-Test-Class'),
41         'TestApp::Controller::Action::Forward',
42         'Test Class'
43     );
44     is( $response->header('X-Catalyst-Executed'),
45         $expected, 'Executed actions' );
46     like(
47         $response->content,
48         qr/^bless\( .* 'Catalyst::Request' \)$/s,
49         'Content is a serialized Catalyst::Request'
50     );
51 }
52
53 {
54     my @expected = qw[
55       TestApp::Controller::Action::Forward->begin
56       TestApp::Controller::Action::Forward->jojo
57       TestApp::Controller::Action::Forward->one
58       TestApp::Controller::Action::Forward->two
59       TestApp::Controller::Action::Forward->three
60       TestApp::Controller::Action::Forward->four
61       TestApp::Controller::Action::Forward->five
62       TestApp::View::Dump::Request->process
63       TestApp::Controller::Action::Forward->three
64       TestApp::Controller::Action::Forward->four
65       TestApp::Controller::Action::Forward->five
66       TestApp::View::Dump::Request->process
67     ];
68
69     my $expected = join( ", ", @expected );
70
71     ok( my $response = request('http://localhost/action/forward/jojo'),
72         'Request' );
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/forward/jojo', 'Test Action' );
77     is(
78         $response->header('X-Test-Class'),
79         'TestApp::Controller::Action::Forward',
80         'Test Class'
81     );
82     is( $response->header('X-Catalyst-Executed'),
83         $expected, 'Executed actions' );
84     like(
85         $response->content,
86         qr/^bless\( .* 'Catalyst::Request' \)$/s,
87         'Content is a serialized Catalyst::Request'
88     );
89 }
90
91 {
92     ok(
93         my $response = request('http://localhost/action/forward/with_args/old'),
94         'Request with args'
95     );
96     ok( $response->is_success, 'Response Successful 2xx' );
97     is( $response->content, 'old' );
98 }
99
100 {
101     ok(
102         my $response =
103           request('http://localhost/action/forward/with_method_and_args/old'),
104         'Request with args and method'
105     );
106     ok( $response->is_success, 'Response Successful 2xx' );
107     is( $response->content, 'old' );
108 }
109
110 # test forward with embedded args
111 {
112     ok(
113         my $response =
114           request('http://localhost/action/forward/args_embed_relative'),
115         'Request'
116     );
117     ok( $response->is_success, 'Response Successful 2xx' );
118     is( $response->content, 'ok' );
119 }
120
121 {
122     ok(
123         my $response =
124           request('http://localhost/action/forward/args_embed_absolute'),
125         'Request'
126     );
127     ok( $response->is_success, 'Response Successful 2xx' );
128     is( $response->content, 'ok' );
129 }