Added some tests for auto
[catagits/Catalyst-Runtime.git] / t / live / component / controller / action / auto.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 => 18;
10 use Catalyst::Test 'TestApp';
11
12 # test auto + local method
13 {
14     my @expected = qw[
15       TestApp::Controller::Action::Auto->begin
16       TestApp::Controller::Action::Auto->auto
17       TestApp::Controller::Action::Auto->one
18     ];
19
20     my $expected = join( ", ", @expected );
21
22     ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' );
23     is( $response->header('X-Catalyst-Executed'),
24         $expected, 'Executed actions' );
25     is( $response->content, 'one', 'Content OK' );
26 }
27
28 # test auto + default
29 {
30     my @expected = qw[
31       TestApp::Controller::Action::Auto->begin
32       TestApp::Controller::Action::Auto->auto
33       TestApp::Controller::Action::Auto->default
34     ];
35
36     my $expected = join( ", ", @expected );
37
38     ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' );
39     is( $response->header('X-Catalyst-Executed'),
40         $expected, 'Executed actions' );
41     is( $response->content, 'default', 'Content OK' );
42 }
43
44 # test auto + auto + local
45 {
46     my @expected = qw[
47       TestApp::Controller::Action::Auto::Deep->begin
48       TestApp::Controller::Action::Auto->auto
49       TestApp::Controller::Action::Auto::Deep->auto
50       TestApp::Controller::Action::Auto::Deep->one
51     ];
52
53     my $expected = join( ", ", @expected );
54
55     ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' );
56     is( $response->header('X-Catalyst-Executed'),
57         $expected, 'Executed actions' );
58     is( $response->content, 'deep one', 'Content OK' );
59 }
60
61 # test auto + auto + default
62 {
63     my @expected = qw[
64       TestApp::Controller::Action::Auto::Deep->begin
65       TestApp::Controller::Action::Auto->auto
66       TestApp::Controller::Action::Auto::Deep->auto
67       TestApp::Controller::Action::Auto::Deep->default
68     ];
69
70     my $expected = join( ", ", @expected );
71
72     ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' );
73     is( $response->header('X-Catalyst-Executed'),
74         $expected, 'Executed actions' );
75     is( $response->content, 'deep default', 'Content OK' );
76 }
77
78 # test auto + failing auto + local + end
79 {
80     my @expected = qw[
81       TestApp::Controller::Action::Auto::Abort->begin
82       TestApp::Controller::Action::Auto->auto
83       TestApp::Controller::Action::Auto::Abort->auto
84       TestApp::Controller::Action::Auto::Abort->end
85     ];
86
87     my $expected = join( ", ", @expected );
88
89     ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' );
90     is( $response->header('X-Catalyst-Executed'),
91         $expected, 'Executed actions' );
92     is( $response->content, 'abort end', 'Content OK' );
93 }
94
95 # test auto + failing auto + default + end
96 {
97     my @expected = qw[
98       TestApp::Controller::Action::Auto::Abort->begin
99       TestApp::Controller::Action::Auto->auto
100       TestApp::Controller::Action::Auto::Abort->auto
101       TestApp::Controller::Action::Auto::Abort->end
102     ];
103
104     my $expected = join( ", ", @expected );
105
106     ok( my $response = request('http://localhost/action/auto/abort/anything'), 'auto + failing auto + default' );
107     is( $response->header('X-Catalyst-Executed'),
108         $expected, 'Executed actions' );
109     is( $response->content, 'abort end', 'Content OK' );
110 }