use inlined module hiding in tests
[catagits/Catalyst-Runtime.git] / t / aggregate / live_component_controller_action_default.t
CommitLineData
50cc3183 1use strict;
2use warnings;
3
4use FindBin;
42da66a9 5use lib "$FindBin::Bin/../lib";
50cc3183 6
7our $iters;
8
6b25e555 9BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
50cc3183 10
4065bc1e 11use Test::More tests => 16 * $iters;
50cc3183 12use Catalyst::Test 'TestApp';
13
14if ( $ENV{CAT_BENCHMARK} ) {
15 require Benchmark;
16 Benchmark::timethis( $iters, \&run_tests );
17}
18else {
19 for ( 1 .. $iters ) {
20 run_tests();
21 }
22}
23
24sub 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
a0a66cb8 30 TestApp::Controller::Root->end
50cc3183 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' );
d1cbffb4 54 is( $response->code, 500, 'Invalid URI returned 500' );
50cc3183 55 }
d1cbffb4 56
50cc3183 57 # test that args are passed properly to default
58 {
59 my $creq;
d1cbffb4 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'
1e3b6963 67 ) or fail("EXCEPTION $@ DESERIALIZING " . $response->content);
50cc3183 68 is_deeply( $creq->{arguments}, $expected, 'Arguments ok' );
69 }
4065bc1e 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
a0a66cb8 77 TestApp::Controller::Root->end
4065bc1e 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 }
50cc3183 94}