From: Andy Grundman Date: Fri, 21 Oct 2005 16:01:15 +0000 (+0000) Subject: Added some tests for auto X-Git-Tag: 5.7099_04~1157 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e1bf532b9461ab134abe5664a4438420f4eb33f5 Added some tests for auto --- diff --git a/MANIFEST b/MANIFEST index 4c75f11..2fc5399 100644 --- a/MANIFEST +++ b/MANIFEST @@ -38,6 +38,7 @@ t/01use.t t/02pod.t t/03podcoverage.t t/conf/extra.conf.in +t/live/component/controller/action/auto.t t/live/component/controller/action/begin.t t/live/component/controller/action/default.t t/live/component/controller/action/detach.t @@ -70,6 +71,9 @@ t/live/lib/Catalyst/Plugin/Test/Headers.pm t/live/lib/Catalyst/Plugin/Test/Plugin.pm t/live/lib/TestApp.pm t/live/lib/TestApp/Controller/Action.pm +t/live/lib/TestApp/Controller/Action/Auto.pm +t/live/lib/TestApp/Controller/Action/Auto/Abort.pm +t/live/lib/TestApp/Controller/Action/Auto/Deep.pm t/live/lib/TestApp/Controller/Action/Begin.pm t/live/lib/TestApp/Controller/Action/Default.pm t/live/lib/TestApp/Controller/Action/Detach.pm diff --git a/t/live/component/controller/action/auto.t b/t/live/component/controller/action/auto.t new file mode 100644 index 0000000..ce7a4de --- /dev/null +++ b/t/live/component/controller/action/auto.t @@ -0,0 +1,110 @@ +#!perl + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../../../lib"; + +use Test::More tests => 18; +use Catalyst::Test 'TestApp'; + +# test auto + local method +{ + my @expected = qw[ + TestApp::Controller::Action::Auto->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto->one + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/one'), 'auto + local' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'one', 'Content OK' ); +} + +# test auto + default +{ + my @expected = qw[ + TestApp::Controller::Action::Auto->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto->default + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/anything'), 'auto + default' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'default', 'Content OK' ); +} + +# test auto + auto + local +{ + my @expected = qw[ + TestApp::Controller::Action::Auto::Deep->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto::Deep->auto + TestApp::Controller::Action::Auto::Deep->one + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/deep/one'), 'auto + auto + local' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'deep one', 'Content OK' ); +} + +# test auto + auto + default +{ + my @expected = qw[ + TestApp::Controller::Action::Auto::Deep->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto::Deep->auto + TestApp::Controller::Action::Auto::Deep->default + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/deep/anything'), 'auto + auto + default' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'deep default', 'Content OK' ); +} + +# test auto + failing auto + local + end +{ + my @expected = qw[ + TestApp::Controller::Action::Auto::Abort->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto::Abort->auto + TestApp::Controller::Action::Auto::Abort->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/abort/one'), 'auto + failing auto + local' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'abort end', 'Content OK' ); +} + +# test auto + failing auto + default + end +{ + my @expected = qw[ + TestApp::Controller::Action::Auto::Abort->begin + TestApp::Controller::Action::Auto->auto + TestApp::Controller::Action::Auto::Abort->auto + TestApp::Controller::Action::Auto::Abort->end + ]; + + my $expected = join( ", ", @expected ); + + ok( my $response = request('http://localhost/action/auto/abort/anything'), 'auto + failing auto + default' ); + is( $response->header('X-Catalyst-Executed'), + $expected, 'Executed actions' ); + is( $response->content, 'abort end', 'Content OK' ); +} diff --git a/t/live/lib/TestApp/Controller/Action/Auto.pm b/t/live/lib/TestApp/Controller/Action/Auto.pm new file mode 100644 index 0000000..b90b4e6 --- /dev/null +++ b/t/live/lib/TestApp/Controller/Action/Auto.pm @@ -0,0 +1,21 @@ +package TestApp::Controller::Action::Auto; + +use strict; +use base 'TestApp::Controller::Action'; + +sub auto : Private { + my ( $self, $c ) = @_; + return 1; +} + +sub default : Private { + my ( $self, $c ) = @_; + $c->res->body( 'default' ); +} + +sub one : Local { + my ( $self, $c ) = @_; + $c->res->body( 'one' ); +} + +1; diff --git a/t/live/lib/TestApp/Controller/Action/Auto/Abort.pm b/t/live/lib/TestApp/Controller/Action/Auto/Abort.pm new file mode 100644 index 0000000..9a65aac --- /dev/null +++ b/t/live/lib/TestApp/Controller/Action/Auto/Abort.pm @@ -0,0 +1,26 @@ +package TestApp::Controller::Action::Auto::Abort; + +use strict; +use base 'TestApp::Controller::Action'; + +sub auto : Private { + my ( $self, $c ) = @_; + return 0; +} + +sub default : Private { + my ( $self, $c ) = @_; + $c->res->body( 'abort default' ); +} + +sub end : Private { + my ( $self, $c ) = @_; + $c->res->body( 'abort end' ) unless $c->res->body; +} + +sub one : Local { + my ( $self, $c ) = @_; + $c->res->body( 'abort one' ); +} + +1; diff --git a/t/live/lib/TestApp/Controller/Action/Auto/Deep.pm b/t/live/lib/TestApp/Controller/Action/Auto/Deep.pm new file mode 100644 index 0000000..0c96f28 --- /dev/null +++ b/t/live/lib/TestApp/Controller/Action/Auto/Deep.pm @@ -0,0 +1,21 @@ +package TestApp::Controller::Action::Auto::Deep; + +use strict; +use base 'TestApp::Controller::Action'; + +sub auto : Private { + my ( $self, $c ) = @_; + return 1; +} + +sub default : Private { + my ( $self, $c ) = @_; + $c->res->body( 'deep default' ); +} + +sub one : Local { + my ( $self, $c ) = @_; + $c->res->body( 'deep one' ); +} + +1;