More comments and POD for Session/Url.pm.

Tests for escape, unescape, extras methods.  Test code is big enough 
that I've added section delimiting comments.  This has helped make
the code a lot more readable.
This commit is contained in:
Colin Kuskie 2006-09-29 03:32:24 +00:00
parent 8174f9d2b4
commit 2d2b780ed6
2 changed files with 51 additions and 6 deletions

View file

@ -130,7 +130,7 @@ Combinds the base extrasURL defined in the config file with a specfied path.
=head3 path
The path to the thing in the extras folder that you're referencing. Note that the preceding / is not necessary.
The path to the thing in the extras folder that you're referencing. Note that the leading / is not necessary. Multiple consecutive slashes will be replaced with a single slash.
=cut
@ -138,7 +138,7 @@ sub extras {
my $self = shift;
my $path = shift;
my $url = $self->session->config->get("extrasURL").'/'.$path;
$url =~ s/\/+/\//g;
$url =~ s!/+!/!g;
return $url;
}
@ -399,11 +399,12 @@ sub unescape {
=head2 urlize ( string )
Returns a url that is safe for WebGUI pages.
Returns a url that is safe for WebGUI pages. Strings are lower-cased, run through
$self->makeCompliant and then have any trailing slashes removed.
=head3 string
The string to urlize.
The string to urlize.
=cut

View file

@ -51,7 +51,7 @@ my @getRefererUrlTests = (
use Test::More;
use Test::MockObject::Extends;
use Test::MockObject;
plan tests => 31 + scalar(@getRefererUrlTests);
plan tests => 37 + scalar(@getRefererUrlTests);
my $session = WebGUI::Test->session;
@ -60,6 +60,12 @@ my $preventProxyCache = $session->setting->get('preventProxyCache');
$session->setting->set('preventProxyCache', 0) if ($preventProxyCache);
#######################################
#
# append
#
#######################################
my $url = 'http://localhost.localdomain/foo';
my $url2;
@ -166,7 +172,14 @@ $url2 = 'level1-/level2/level3';
is ( $session->url->makeCompliant($url), $url2, 'language specific URL compliance');
my $originalRequest = $session->request; ##Save the original request
#######################################
#
# getRequestedUrl
#
#######################################
my $originalRequest = $session->request; ##Save the original request object
is ($session->url->getRequestedUrl, undef, 'getRequestedUrl returns undef unless it has a request object');
@ -192,6 +205,12 @@ $session->url->{_requestedUrl} = undef; ##Manually clear cached value
$requestedUrl = '/path2/file2?param1=one;param2=two';
is ($session->url->getRequestedUrl, 'path2/file2', 'getRequestedUrl, does not return params');
#######################################
#
# page
#
#######################################
$session->url->{_requestedUrl} = undef; ##Manually clear cached value
$requestedUrl = '/path1/file1';
is ($session->url->page, '/path1/file1', 'page with no args returns getRequestedUrl through gateway');
@ -229,6 +248,31 @@ TODO: {
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');
#######################################
#
# extras
#
#######################################
is($session->url->extras, $session->config->get('extrasURL').'/', 'extras method returns URL to extras with a trailing slash');
is($session->url->extras('foo.html'), join('/', $session->config->get('extrasURL'),'foo.html'), 'extras method appends to the extras url');
is($session->url->extras('/foo.html'), join('/', $session->config->get('extrasURL'),'foo.html'), 'extras method removes extra slashes');
is($session->url->extras('/dir1//foo.html'), join('/', $session->config->get('extrasURL'),'dir1/foo.html'), 'extras method removes extra slashes anywhere');
#######################################
#
# escape and unescape
# Our goal in this test is just to show that the calls to the URI module work,
# not to test the URI methods themselves
#
#######################################
my $escapeString = '10% is enough!';
my $escapedString = $session->url->escape($escapeString);
my $unEscapedString = $session->url->unescape($escapeString);
is($escapedString, '10%25%20is%20enough!', 'escape method');
is($unEscapedString, '10% is enough!', 'unescape method');
END {
$session->config->set('sitename', \@config_sitename);
$session->setting->set('hostToUse', $setting_hostToUse);