A few more tests to kick coverage up to 100 on WebGUI::Session::Setting
Convert it to use placeholders as well. More WebGUI::Session::Url tests, and some bug fixes: getRefererUrl returned parameters and accepted weird methods that looked like http but weren't.
This commit is contained in:
parent
00e37ae971
commit
eea7b941c9
4 changed files with 60 additions and 9 deletions
|
|
@ -67,7 +67,7 @@ sub add {
|
|||
my $name = shift;
|
||||
my $value = shift;
|
||||
$self->{_settings}{$name} = $value;
|
||||
$self->session->db->write("insert into settings (name,value) values (".$self->session->db->quote($name).",".$self->session->db->quote($value).")");
|
||||
$self->session->db->write("insert into settings (name,value) values (?,?)",[$name, $value]);
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -136,7 +136,7 @@ sub remove {
|
|||
my $self = shift;
|
||||
my $name = shift;
|
||||
delete $self->{_settings}{$name};
|
||||
$self->session->db->write("delete from settings where name=".$self->session->db->quote($name));
|
||||
$self->session->db->write("delete from settings where name=?",[$name]);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -175,7 +175,7 @@ sub set {
|
|||
my $name = shift;
|
||||
my $value = shift;
|
||||
$self->{_settings}{$name} = $value;
|
||||
$self->session->db->write("update settings set value=".$self->session->db->quote($value)." where name=".$self->session->db->quote($name));
|
||||
$self->session->db->write("update settings set value=? where name=?",[$value, $name]);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -189,8 +189,8 @@ sub getRefererUrl {
|
|||
return undef unless ($referer);
|
||||
my $url = $referer;
|
||||
my $gateway = $self->session->config->get("gateway");
|
||||
$url =~ s/htt\w+\:\/\/[A-Za-z0-9\.\-]+$gateway\/*(\S*)/$1/;;
|
||||
if ($url eq $referer) {
|
||||
$url =~ s{https?://[A-Za-z0-9\.-]+$gateway/*([^?]*)\??.*$}{$1};
|
||||
if ($url eq $referer) { ##s/// failed
|
||||
return undef;
|
||||
} else {
|
||||
return $url;
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use lib "$FindBin::Bin/../lib";
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Test::More tests => 4; # increment this value for each test you create
|
||||
use Test::More tests => 6; # increment this value for each test you create
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -26,6 +26,9 @@ is($session->setting->get("test"), "XXX", "get()");
|
|||
$session->setting->set("test","YYY");
|
||||
my ($value) = $session->db->quickArray("select value from settings where name='test'");
|
||||
is($value, 'YYY', "set()");
|
||||
is($session->setting->get("test"), 'YYY', 'set() also updates object cache');
|
||||
$session->setting->remove("test");
|
||||
my ($value) = $session->db->quickArray("select value from settings where name='test'");
|
||||
is($value, undef, "delete()");
|
||||
|
||||
isa_ok($session->setting->session, 'WebGUI::Session', 'session method returns a session object');
|
||||
|
|
|
|||
|
|
@ -15,8 +15,43 @@ use lib "$FindBin::Bin/../lib";
|
|||
use WebGUI::Test;
|
||||
use WebGUI::Session;
|
||||
|
||||
use Test::More tests => 19; # increment this value for each test you create
|
||||
my @getRefererUrlTests = (
|
||||
{
|
||||
input => undef,
|
||||
output => undef,
|
||||
comment => 'getRerererUrl returns undef unless there is a referrer',
|
||||
},
|
||||
{
|
||||
input => 'http://www.domain.com/myUrl.html',
|
||||
output => 'myUrl.html',
|
||||
comment => 'getRefererUrl returns the url minus the gateway',
|
||||
},
|
||||
{
|
||||
input => 'http://www.domain.com/myUrl.html?op=switchAdminOn',
|
||||
output => 'myUrl.html',
|
||||
comment => 'getRefererUrl returns the url minus the gateway',
|
||||
},
|
||||
{
|
||||
input => 'https://www.site.com/myUrl.html',
|
||||
output => 'myUrl.html',
|
||||
comment => 'getRefererUrl handles SSL urls',
|
||||
},
|
||||
{
|
||||
input => 'itunes://www.site.com/myUrl.html',
|
||||
output => undef,
|
||||
comment => 'getRefererUrl only handles HTTP protocols',
|
||||
},
|
||||
{
|
||||
input => 'http://site/myUrl.html',
|
||||
output => 'myUrl.html',
|
||||
comment => 'getRefererUrl will also parse weird URLs',
|
||||
},
|
||||
);
|
||||
|
||||
use Test::More;
|
||||
use Test::MockObject::Extends;
|
||||
use Test::MockObject;
|
||||
plan tests => 21 + scalar(@getRefererUrlTests);
|
||||
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
|
|
@ -28,14 +63,12 @@ $session->setting->set('preventProxyCache', 0) if ($preventProxyCache);
|
|||
my $url = 'http://localhost.localdomain/foo';
|
||||
my $url2;
|
||||
|
||||
|
||||
$url2 = $session->url->append($url,'a=b');
|
||||
is( $url2, $url.'?a=b', 'append first pair');
|
||||
|
||||
$url2 = $session->url->append($url2,'c=d');
|
||||
is( $url2, $url.'?a=b;c=d', 'append second pair');
|
||||
|
||||
|
||||
$session->config->{_config}->{'gateway'} = '/';
|
||||
|
||||
is ( $session->config->get('gateway'), '/', 'Set gateway for downstream tests');
|
||||
|
|
@ -105,3 +138,18 @@ 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
|
||||
|
||||
our %mockEnv = (HTTP_REFERER => undef);
|
||||
|
||||
$session->{_env}->{_env} = \%mockEnv;
|
||||
|
||||
$mockEnv{'HTTP_REFERER'} = 'test';
|
||||
|
||||
is($session->env->get('HTTP_REFERER'), 'test', 'testing MockObject');
|
||||
|
||||
foreach my $test (@getRefererUrlTests) {
|
||||
$mockEnv{HTTP_REFERER} = $test->{input};
|
||||
is($session->url->getRefererUrl, $test->{output}, $test->{comment});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue