newByUrl should throw an exception. Test it.

This commit is contained in:
Colin Kuskie 2010-01-29 17:35:19 -08:00
parent 387866cfcb
commit 006570a05a
2 changed files with 26 additions and 8 deletions

View file

@ -1814,13 +1814,10 @@ sub newByUrl {
$url =~ tr/'"//d;
if ($url ne "") {
my ($id) = $session->db->quickArray("select assetId from assetData where url = ? limit 1", [ $url ]);
if ($id ne "" || $class ne "") {
return WebGUI::Asset->newById($session, $id, $revisionDate);
}
else {
$session->errorHandler->warn("The URL $url was requested, but does not exist in your asset tree.");
return undef;
}
if (!$id) {
WebGUI::Error::ObjectNotFound->throw(error => "The URL was requested, but does not exist in your asset tree.", id => $url);
}
return WebGUI::Asset->newById($session, $id, $revisionDate);
}
return WebGUI::Asset->getDefault($session);
}

View file

@ -35,7 +35,7 @@ my $session = WebGUI::Test->session;
my @getTitleTests = getTitleTests($session);
plan tests => 105
plan tests => 110
+ 2*scalar(@getTitleTests) #same tests used for getTitle and getMenuTitle
;
@ -139,6 +139,27 @@ note "newById";
);
}
note "newByUrl";
{
my $deadAsset = eval { WebGUI::Asset->newByUrl($session, '/workFromHomeScam'); };
my $e = Exception::Class->caught;
isa_ok($e, 'WebGUI::Error::ObjectNotFound');
cmp_deeply(
$e,
methods(
error => "The URL was requested, but does not exist in your asset tree.",
id => 'workfromhomescam',
),
'... checking error message',
);
my $root = eval { WebGUI::Asset->newByUrl($session, '/root'); };
isa_ok($root, 'WebGUI::Asset');
$root = eval { WebGUI::Asset->newByUrl($session, '/ROOT'); };
isa_ok($root, 'WebGUI::Asset');
$root = eval { WebGUI::Asset->newByUrl($session, '/root/'); };
isa_ok($root, 'WebGUI::Asset');
}
# -- no session
# Root Asset
my $rootAsset = WebGUI::Asset->getRoot($session);