diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index aa44daa87..7e1d965fb 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -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); } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index e66a0ded3..817cd44dd 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -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);