geoff 2003/10/09 11:40:31
Added: t/response/TestModperl status.pm t/modperl status.t Log: add tests for handler return status logic Revision Changes Path 1.1 modperl-2.0/t/response/TestModperl/status.pm Index: status.pm =================================================================== package TestModperl::status; use strict; use warnings; use Apache::RequestRec; use Apache::Const -compile => qw(DECLINED); use ModPerl::Util; use Apache::TestUtil qw(t_server_log_error_is_expected); sub handler { my $rc = shift->args; if ($rc eq 'die' || $rc eq Apache::DECLINED) { t_server_log_error_is_expected(); } ModPerl::Util::exit if $rc eq 'exit'; die if $rc eq 'die'; return $rc; } 1; __END__ 1.1 modperl-2.0/t/modperl/status.t Index: status.t =================================================================== use strict; use warnings FATAL => 'all'; use Apache::Test; use Apache::TestRequest; use Apache::TestUtil qw(t_cmp t_server_log_error_is_expected); use Apache2; use Apache::Const -compile => qw(OK DECLINED NOT_FOUND SERVER_ERROR FORBIDDEN HTTP_OK); plan tests => 13; my $base = "/TestModperl__status"; # valid Apache return codes { my $uri = join '?', $base, Apache::OK; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } { my $uri = join '?', $base, Apache::DECLINED; my $code = GET_RC $uri; # no Alias to map us to DocumentRoot ok t_cmp(Apache::NOT_FOUND, $code, $uri); } # standard HTTP status codes { my $uri = join '?', $base, Apache::NOT_FOUND; my $code = GET_RC $uri; ok t_cmp(Apache::NOT_FOUND, $code, $uri); } { my $uri = join '?', $base, Apache::FORBIDDEN; my $code = GET_RC $uri; ok t_cmp(Apache::FORBIDDEN, $code, $uri); } { my $uri = join '?', $base, Apache::SERVER_ERROR; my $code = GET_RC $uri; ok t_cmp(Apache::SERVER_ERROR, $code, $uri); } # the return code guessing game { my $uri = join '?', $base, Apache::HTTP_OK; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } { my $uri = join '?', $base, 601; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } { my $uri = join '?', $base, 1; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } # apache translates non-HTTP codes into 500 # see ap_index_of_response { my $uri = join '?', $base, 313; my $code = GET_RC $uri; ok t_cmp(Apache::SERVER_ERROR, $code, $uri); } # mod_perl-specific implementation tests { # ModPerl::Util::exit - voids return OK my $uri = join '?', $base, 'exit'; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } { # die gets trapped my $uri = join '?', $base, 'die'; my $code = GET_RC $uri; ok t_cmp(Apache::SERVER_ERROR, $code, $uri); } { my $uri = join '?', $base, 'foobar'; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); } { my $uri = join '?', $base, 'foo9bar'; my $code = GET_RC $uri; ok t_cmp(Apache::HTTP_OK, $code, $uri); }