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