whitespace cleanup
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_default.t
1 use strict;
2 use warnings;
3
4 use FindBin;
5 use lib "$FindBin::Bin/../lib";
6
7 our $iters;
8
9 BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
10
11 use Test::More tests => 16 * $iters;
12 use Catalyst::Test 'TestApp';
13
14 if ( $ENV{CAT_BENCHMARK} ) {
15     require Benchmark;
16     Benchmark::timethis( $iters, \&run_tests );
17 }
18 else {
19     for ( 1 .. $iters ) {
20         run_tests();
21     }
22 }
23
24 sub run_tests {
25     {
26         my @expected = qw[
27           TestApp::Controller::Action::Default->begin
28           TestApp::Controller::Action::Default->default
29           TestApp::View::Dump::Request->process
30           TestApp::Controller::Root->end
31         ];
32
33         my $expected = join( ", ", @expected );
34
35         ok( my $response = request('http://localhost/action/default'),
36             'Request' );
37         ok( $response->is_success, 'Response Successful 2xx' );
38         is( $response->content_type, 'text/plain', 'Response Content-Type' );
39         is( $response->header('X-Catalyst-Action'), 'default', 'Test Action' );
40         is(
41             $response->header('X-Test-Class'),
42             'TestApp::Controller::Action::Default',
43             'Test Class'
44         );
45         is( $response->header('X-Catalyst-Executed'),
46             $expected, 'Executed actions' );
47         like(
48             $response->content,
49             qr/^bless\( .* 'Catalyst::Request' \)$/s,
50             'Content is a serialized Catalyst::Request'
51         );
52
53         ok( $response = request('http://localhost/foo/bar/action'), 'Request' );
54         is( $response->code, 500, 'Invalid URI returned 500' );
55     }
56
57     # test that args are passed properly to default
58     {
59         my $creq;
60         my $expected = [qw/action default arg1 arg2/];
61
62         ok( my $response = request('http://localhost/action/default/arg1/arg2'),
63             'Request' );
64         ok(
65             eval '$creq = ' . $response->content,
66             'Unserialize Catalyst::Request'
67         ) or fail("EXCEPTION $@ DESERIALIZING " . $response->content);
68         is_deeply( $creq->{arguments}, $expected, 'Arguments ok' );
69     }
70
71
72     # Test that /foo and /foo/ both do the same thing
73     {
74         my @expected = qw[
75           TestApp::Controller::Action->begin
76           TestApp::Controller::Action->default
77           TestApp::Controller::Root->end
78         ];
79
80         my $expected = join( ", ", @expected );
81
82         ok( my $response = request('http://localhost/action'), 'Request' );
83         is( $response->header('X-Catalyst-Executed'),
84             $expected,
85             'Executed actions for /action'
86         );
87
88         ok( $response = request('http://localhost/action/'), 'Request' );
89         is( $response->header('X-Catalyst-Executed'),
90             $expected,
91             'Executed actions for /action/'
92         );
93     }
94 }