Extend Session::Http::getStatus so that is will also return the
description when called in list context. Build tests to verify that behavior, and the default settings for code and description.
This commit is contained in:
parent
ab835f3c64
commit
ca7110249f
2 changed files with 61 additions and 2 deletions
|
|
@ -36,6 +36,7 @@ This package allows the manipulation of HTTP protocol information.
|
|||
$cookies = $http->getCookies();
|
||||
$mimetype = $http->getMimeType();
|
||||
$code = $http->getStatus();
|
||||
($code, $description) = $http->getStatus();
|
||||
$boolean = $http->isRedirect();
|
||||
|
||||
$http->setCookie($name,$value);
|
||||
|
|
@ -105,14 +106,19 @@ sub getMimeType {
|
|||
|
||||
=head2 getStatus ( ) {
|
||||
|
||||
Returns the current HTTP status code, if one has been set.
|
||||
Returns the current HTTP status code and description. When called in scalar
|
||||
context, returns only the status code. When called in list context, returns
|
||||
the status and description. If no code has been set, the code returned will be 200.
|
||||
If no description has been set, the internal description will be set to "OK" and
|
||||
"OK" will be returned.
|
||||
|
||||
=cut
|
||||
|
||||
sub getStatus {
|
||||
my $self = shift;
|
||||
$self->{_http}{statusDescription} = $self->{_http}{statusDescription} || "OK";
|
||||
return $self->{_http}{status} || "200";
|
||||
my $status = $self->{_http}{status} || "200";
|
||||
return wantarray ? ( $status, $self->{_http}{statusDescription} ) : $status;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
53
t/Session/Http.t
Normal file
53
t/Session/Http.t
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#-------------------------------------------------------------------
|
||||
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
||||
#-------------------------------------------------------------------
|
||||
# Please read the legal notices (docs/legal.txt) and the license
|
||||
# (docs/license.txt) that came with this distribution before using
|
||||
# this software.
|
||||
#-------------------------------------------------------------------
|
||||
# http://www.plainblack.com info@plainblack.com
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
|
||||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Test::More; # increment this value for each test you create
|
||||
|
||||
my $num_tests = 8;
|
||||
|
||||
plan tests => $num_tests;
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
# put your tests here
|
||||
|
||||
my $http = $session->http;
|
||||
|
||||
isa_ok($http, 'WebGUI::Session::Http', 'session has correct object type');
|
||||
|
||||
$http->setStatus('123');
|
||||
|
||||
is($http->getStatus, '123', 'getStatus: returns correct code in scalar context');
|
||||
|
||||
my ($status, $description) = $http->getStatus;
|
||||
is($status, '123', 'getStatus: returns correct code');
|
||||
is($description, 'OK', 'getStatus: default description returned');
|
||||
|
||||
$http->setStatus('');
|
||||
|
||||
($status, $description) = $http->getStatus;
|
||||
is($status, '200', 'getStatus: returns default code');
|
||||
is($description, 'OK', 'getStatus: default description returned');
|
||||
|
||||
$http->setStatus('', 'packets are great');
|
||||
|
||||
($status, $description) = $http->getStatus;
|
||||
is($status, '200', 'getStatus: returns default code');
|
||||
is($description, 'packets are great', 'getStatus: default description returned');
|
||||
|
||||
END {
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue