A whole batch of Http test, and a pseudo Request test module to help.

Added accessors to Session/Http.pm, and wrote tests to back them all up.
This commit is contained in:
Colin Kuskie 2006-10-30 18:09:25 +00:00
parent 0b1e077f69
commit 75f159f71b
4 changed files with 483 additions and 9 deletions

View file

@ -67,6 +67,19 @@ sub DESTROY {
#-------------------------------------------------------------------
=head2 getCacheControl ( )
Returns the cache control setting from this object.
=cut
sub getCacheControl {
my $self = shift;
return $self->{_http}{cacheControl};
}
#-------------------------------------------------------------------
=head2 getCookies ( )
@ -90,6 +103,19 @@ sub getCookies {
}
#-------------------------------------------------------------------
=head2 getLastModified ( )
Returns the stored epoch date when the page as last modified.
=cut
sub getLastModified {
my $self = shift;
return $self->{_http}{lastModified};
}
#-------------------------------------------------------------------
=head2 getMimeType ( )
@ -103,6 +129,33 @@ sub getMimeType {
return $self->{_http}{mimetype} || "text/html; charset=UTF-8";
}
#-------------------------------------------------------------------
=head2 getNoHeader ( )
Returns whether or not a HTTP header will be printed.
=cut
sub getNoHeader {
my $self = shift;
return $self->{_http}{noHeader};
}
#-------------------------------------------------------------------
=head2 getRedirectLocation ( )
Return the location that was set via setRedirect
=cut
sub getRedirectLocation {
my $self = shift;
return $self->{_http}{location};
}
#-------------------------------------------------------------------
=head2 getStatus ( ) {
@ -200,15 +253,15 @@ sub sendHeader {
return undef unless $request;
my $userId = $self->session->var->get("userId");
$self->{_http}{noHeader} = 1;
$self->setNoHeader(1);
my %params;
if ($self->isRedirect()) {
$request->headers_out->set(Location => $self->{_http}{location});
$request->headers_out->set(Location => $self->getRedirectLocation);
$request->status(301);
} else {
$request->content_type($self->{_http}{mimetype} || "text/html; charset=UTF-8");
my $date = ($userId eq "1") ? $datetime->epochToHttp($self->{_http}{lastModified}) : $datetime->epochToHttp;
my $cacheControl = $self->{_http}{cacheControl};
$request->content_type($self->getMimeType || "text/html; charset=UTF-8");
my $cacheControl = $self->getCacheControl;
my $date = ($userId eq "1") ? $datetime->epochToHttp($self->getLastModified) : $datetime->epochToHttp;
$request->headers_out->set('Last-Modified' => $date);
if ($cacheControl eq "none" || $self->session->setting->get("preventProxyCache") || ($cacheControl eq "" && $userId ne "1")) {
$request->headers_out->set("Cache-Control" => "private");
@ -222,8 +275,8 @@ sub sendHeader {
my $date = $datetime->epochToHttp(time() + $cacheControl);
$request->headers_out->set('Expires' => $date);
}
if ($self->{_http}{filename}) {
$request->headers_out->set('Content-Disposition' => qq!attachment; filename="$self->{_http}{filename}"!);
if ($self->getFilename) {
$request->headers_out->set('Content-Disposition' => qq!attachment; filename="!.$self->getFilename().'"');
}
$request->status($self->getStatus());
$request->status_line($self->getStatus().' '.$self->getStatusDescription());
@ -347,10 +400,29 @@ sub setFilename {
#-------------------------------------------------------------------
=head2 getFilename ( )
Returns the default filename for the document.
=cut
sub getFilename {
my $self = shift;
return $self->{_http}{filename};
}
#-------------------------------------------------------------------
=head2 setLastModified ( epoch )
=head3 epoch
The epoch date when the page was last modified.
=cut
sub setLastModified {