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