1#!perl
2
3BEGIN {
4  unless ($ENV{AUTHOR_TESTING}) {
5    require Test::More;
6    Test::More::plan(skip_all => 'these tests are for testing by the author');
7  }
8}
9
10
11use strict;
12use warnings;
13
14use FindBin;
15use lib "$FindBin::Bin/lib";
16
17our $iters;
18
19BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
20
21use Test::More tests => 28 * $iters;
22use Catalyst::Test 'TestApp';
23
24if ( $ENV{CAT_BENCHMARK} ) {
25    require Benchmark;
26    Benchmark::timethis( $iters, \&run_tests );
27}
28else {
29    for ( 1 .. $iters ) {
30        run_tests();
31    }
32}
33
34sub run_tests {
35    {
36        ok( my $response = request('http://localhost/action_action_one'),
37            'Request' );
38        ok( $response->is_success, 'Response Successful 2xx' );
39        is( $response->content_type, 'text/plain', 'Response Content-Type' );
40        is( $response->header('X-Catalyst-Action'),
41            'action_action_one', 'Test Action' );
42        is(
43            $response->header('X-Test-Class'),
44            'TestApp::Controller::Action::Action',
45            'Test Class'
46        );
47        is( $response->header('X-Action'), 'works' );
48        like(
49            $response->content,
50            qr/^bless\( .* 'Catalyst::Request' \)$/s,
51            'Content is a serialized Catalyst::Request'
52        );
53    }
54
55    {
56        ok( my $response = request('http://localhost/action_action_two'),
57            'Request' );
58        ok( $response->is_success, 'Response Successful 2xx' );
59        is( $response->content_type, 'text/plain', 'Response Content-Type' );
60        is( $response->header('X-Catalyst-Action'),
61            'action_action_two', 'Test Action' );
62        is(
63            $response->header('X-Test-Class'),
64            'TestApp::Controller::Action::Action',
65            'Test Class'
66        );
67        is( $response->header('X-Action-After'), 'awesome' );
68        like(
69            $response->content,
70            qr/^bless\( .* 'Catalyst::Request' \)$/s,
71            'Content is a serialized Catalyst::Request'
72        );
73    }
74
75    {
76        ok(
77            my $response =
78              request('http://localhost/action_action_three/one/two'),
79            'Request'
80        );
81        ok( $response->is_success, 'Response Successful 2xx' );
82        is( $response->content_type, 'text/plain', 'Response Content-Type' );
83        is( $response->header('X-Catalyst-Action'),
84            'action_action_three', 'Test Action' );
85        is(
86            $response->header('X-Test-Class'),
87            'TestApp::Controller::Action::Action',
88            'Test Class'
89        );
90        is( $response->header('X-TestAppActionTestBefore'), 'one' );
91        like(
92            $response->content,
93            qr/^bless\( .* 'Catalyst::Request' \)$/s,
94            'Content is a serialized Catalyst::Request'
95        );
96    }
97
98    {
99        ok( my $response = request('http://localhost/action_action_four'),
100            'Request' );
101        ok( $response->is_success, 'Response Successful 2xx' );
102        is( $response->content_type, 'text/plain', 'Response Content-Type' );
103        is( $response->header('X-Catalyst-Action'),
104            'action_action_four', 'Test Action' );
105        is(
106            $response->header('X-Test-Class'),
107            'TestApp::Controller::Action::Action',
108            'Test Class'
109        );
110        is( $response->header('X-TestAppActionTestMyAction'), 'MyAction works' );
111        like(
112            $response->content,
113            qr/^bless\( .* 'Catalyst::Request' \)$/s,
114            'Content is a serialized Catalyst::Request'
115        );
116    }
117
118}
119