More tests for WebGUI::Session::Url::getSiteUrl, which now has 100% test coverage.

Refactored getSiteUrl so it is very obvious as to how it works, replacing
code that was hard to cover.
This commit is contained in:
Colin Kuskie 2006-09-29 02:30:54 +00:00
parent c71a1ac5ee
commit 8174f9d2b4
2 changed files with 33 additions and 6 deletions

View file

@ -231,10 +231,10 @@ sub getSiteURL {
unless ($self->{_siteUrl}) {
my $site = "";
my $sitenames = $self->session->config->get("sitename");
if ($self->session->setting->get("hostToUse") eq "sitename" || !isIn($self->session->env->get("HTTP_HOST"),@{$sitenames})) {
$site = $sitenames->[0];
if ($self->session->setting->get("hostToUse") eq "HTTP_HOST" and isIn($self->session->env->get("HTTP_HOST"),@{$sitenames})) {
$site = $self->session->env->get("HTTP_HOST");
} else {
$site = $self->session->env->get("HTTP_HOST") || $sitenames->[0];
$site = $sitenames->[0];
}
my $proto = "http://";
if ($self->session->env->get("HTTPS") eq "on") {

View file

@ -51,7 +51,7 @@ my @getRefererUrlTests = (
use Test::More;
use Test::MockObject::Extends;
use Test::MockObject;
plan tests => 27 + scalar(@getRefererUrlTests);
plan tests => 31 + scalar(@getRefererUrlTests);
my $session = WebGUI::Test->session;
@ -155,7 +155,10 @@ is ( $session->url->getSiteURL, 'http://'.$sitename, 'restore config setting');
$session->config->set('sitename', \@config_sitename);
$session->setting->set('hostToUse', $setting_hostToUse);
if ($config_port) {
$session->config->set($config_port);
$session->config->set('webServerPort', $config_port);
}
else {
$session->config->delete('webServerPort');
}
$url = 'level1 /level2/level3 ';
@ -165,6 +168,8 @@ is ( $session->url->makeCompliant($url), $url2, 'language specific URL complianc
my $originalRequest = $session->request; ##Save the original request
is ($session->url->getRequestedUrl, undef, 'getRequestedUrl returns undef unless it has a request object');
my $newRequest = Test::MockObject->new;
my $requestedUrl = 'empty';
$newRequest->set_bound('uri', \$requestedUrl);
@ -194,7 +199,12 @@ is ($session->url->page, '/path1/file1', 'page with no args returns getRequested
$url2 = 'http://'.$session->config->get('sitename')->[0].'/path1/file1';
is ($session->url->page('',1), $url2, 'page, withFullUrl includes method and sitename');
##getReferrerUrl tests
#######################################
#
# getReferrerUrl
#
#######################################
$mockEnv{'HTTP_REFERER'} = 'test';
@ -205,10 +215,27 @@ foreach my $test (@getRefererUrlTests) {
is($session->url->getRefererUrl, $test->{output}, $test->{comment});
}
#######################################
#
# makeAbsolute
#
#######################################
TODO: {
local $TODO = "makeAbsolute TODO's";
ok(0, 'go back and refigure out how the page method works to test makeAbsoluate with default params');
}
is($session->url->makeAbsolute('page1', '/layer1/layer2/'), '/layer1/layer2/page1', 'use a different root');
is($session->url->makeAbsolute('page1', '/layer1/page2'), '/layer1/page1', 'use a second root that is one level shallower');
END {
$session->config->set('sitename', \@config_sitename);
$session->setting->set('hostToUse', $setting_hostToUse);
if ($config_port) {
$session->config->set($config_port);
}
else {
$session->config->delete('webServerPort');
}
}