X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=t%2Flive%2Fcomponent%2Fcontroller%2Faction%2Fforward.t;h=d64b5f9b045c5a0edcadee0ba4c2356dc8c94269;hp=58355af4bd717e659b6b8f709485383c8b1f1f75;hb=01ba879fae4d3ac2babde66ec6d45b822ba412f8;hpb=fbcc39ad23f2bbecf5d84c9ba581e6af86fcd460 diff --git a/t/live/component/controller/action/forward.t b/t/live/component/controller/action/forward.t index 58355af..d64b5f9 100644 --- a/t/live/component/controller/action/forward.t +++ b/t/live/component/controller/action/forward.t @@ -6,73 +6,144 @@ use warnings; use FindBin; use lib "$FindBin::Bin/../../../lib"; -use Test::More tests => 24; -use Catalyst::Test 'TestApp'; +our $iters; +BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 2; } -{ - my @expected = qw[ - TestApp::Controller::Action::Forward->begin - TestApp::Controller::Action::Forward->one - TestApp::Controller::Action::Forward->two - TestApp::Controller::Action::Forward->three - TestApp::Controller::Action::Forward->four - TestApp::Controller::Action::Forward->five - TestApp::View::Dump::Request->process - ]; - - my $expected = join( ", ", @expected ); - - # Test forward to global private action - ok( my $response = request('http://localhost/action/forward/global'), 'Request' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->content_type, 'text/plain', 'Response Content-Type' ); - is( $response->header('X-Catalyst-Action'), 'action/forward/global', 'Main Class Action' ); - # Test forward to chain of actions. - ok( $response = request('http://localhost/action/forward/one'), 'Request' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->content_type, 'text/plain', 'Response Content-Type' ); - is( $response->header('X-Catalyst-Action'), 'action/forward/one', 'Test Action' ); - is( $response->header('X-Test-Class'), 'TestApp::Controller::Action::Forward', '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' ); -} +use Test::More tests => 30*$iters; +use Catalyst::Test 'TestApp'; -{ - my @expected = qw[ - TestApp::Controller::Action::Forward->begin - TestApp::Controller::Action::Forward->jojo - TestApp::Controller::Action::Forward->one - TestApp::Controller::Action::Forward->two - TestApp::Controller::Action::Forward->three - TestApp::Controller::Action::Forward->four - TestApp::Controller::Action::Forward->five - TestApp::View::Dump::Request->process - TestApp::Controller::Action::Forward->three - TestApp::Controller::Action::Forward->four - TestApp::Controller::Action::Forward->five - TestApp::View::Dump::Request->process - ]; - - my $expected = join( ", ", @expected ); - - ok( my $response = request('http://localhost/action/forward/jojo'), 'Request' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->content_type, 'text/plain', 'Response Content-Type' ); - is( $response->header('X-Catalyst-Action'), 'action/forward/jojo', 'Test Action' ); - is( $response->header('X-Test-Class'), 'TestApp::Controller::Action::Forward', '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' ); +if ( $ENV{CAT_BENCHMARK} ) { + require Benchmark; + Benchmark::timethis( $iters, \&run_tests ); } - -{ - ok( my $response = request('http://localhost/action/forward/with_args/old'), 'Request with args' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->content,'old'); +else { + for ( 1 .. $iters ) { + run_tests(); + } } -{ - ok( my $response = request('http://localhost/action/forward/with_method_and_args/old'), 'Request with args and method' ); - ok( $response->is_success, 'Response Successful 2xx' ); - is( $response->content,'old'); +sub run_tests { + { + my @expected = qw[ + TestApp::Controller::Action::Forward->begin + TestApp::Controller::Action::Forward->one + TestApp::Controller::Action::Forward->two + TestApp::Controller::Action::Forward->three + TestApp::Controller::Action::Forward->four + TestApp::Controller::Action::Forward->five + TestApp::View::Dump::Request->process + TestApp->end + ]; + + my $expected = join( ", ", @expected ); + + # Test forward to global private action + ok( my $response = request('http://localhost/action/forward/global'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action/forward/global', 'Main Class Action' ); + + # Test forward to chain of actions. + ok( $response = request('http://localhost/action/forward/one'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action/forward/one', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Forward', + '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' + ); + } + + { + my @expected = qw[ + TestApp::Controller::Action::Forward->begin + TestApp::Controller::Action::Forward->jojo + TestApp::Controller::Action::Forward->one + TestApp::Controller::Action::Forward->two + TestApp::Controller::Action::Forward->three + TestApp::Controller::Action::Forward->four + TestApp::Controller::Action::Forward->five + TestApp::View::Dump::Request->process + TestApp::Controller::Action::Forward->three + TestApp::Controller::Action::Forward->four + TestApp::Controller::Action::Forward->five + TestApp::View::Dump::Request->process + TestApp->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/forward/jojo'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action/forward/jojo', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Forward', + '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( + my $response = + request('http://localhost/action/forward/with_args/old'), + 'Request with args' + ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, 'old' ); + } + + { + ok( + my $response = request( + 'http://localhost/action/forward/with_method_and_args/old'), + 'Request with args and method' + ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, 'old' ); + } + + # test forward with embedded args + { + ok( + my $response = + request('http://localhost/action/forward/args_embed_relative'), + 'Request' + ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, 'ok' ); + } + + { + ok( + my $response = + request('http://localhost/action/forward/args_embed_absolute'), + 'Request' + ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content, 'ok' ); + } }