diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 96b93730e..8fed74d7c 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -1895,10 +1895,12 @@ sub urlExists { my $url = lc(shift); my $options = shift || {}; my $limit = ""; - if (defined $options->{assetId}) { - $limit = "and assetId<>?" + my $placeholders = [ $url ]; + if (exists $options->{assetId}) { + $limit = "and assetId=?"; + push @{ $placeholders }, $options->{assetId}; } - my ($test) = $session->db->quickArray("select count(url) from assetData where url=? $limit", [$url, $options->{assetId}]); + my ($test) = $session->db->quickArray("select count(url) from assetData where url=? $limit", $placeholders); return $test; } diff --git a/t/Asset/Asset.t b/t/Asset/Asset.t index 51513aa35..aace68e80 100644 --- a/t/Asset/Asset.t +++ b/t/Asset/Asset.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Wobject::Navigation; -use Test::More tests => 20; # increment this value for each test you create +use Test::More tests => 25; # increment this value for each test you create my $session = WebGUI::Test->session; @@ -95,3 +95,20 @@ my $importNode = WebGUI::Asset->getImportNode($session); isa_ok($importNode, 'WebGUI::Asset::Wobject::Folder'); is($importNode->getId, 'PBasset000000000000002', 'Import Node Asset ID check'); is($importNode->getParent->getId, $rootAsset->getId, 'Import Nodes parent is Root Asset'); + +################################################################ +# +# urlExists +# +################################################################ + +##We need as asset with a URL for this one. + +my $importUrl = $importNode->get('url'); +my $importId = $importNode->getId; + +ok( WebGUI::Asset->urlExists($session, $importUrl), 'url for import node exists'); +ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz'), 'made up url does not exist'); +ok( WebGUI::Asset->urlExists($session, $importUrl, {assetId => $importId}), 'url for import node exists at specific id'); +ok( !WebGUI::Asset->urlExists($session, '/foo/bar/baz', {assetId => $importId}), 'imaginary url does not exist at specific id'); +ok( !WebGUI::Asset->urlExists($session, $importUrl, {assetId => 'notAnWebGUIId'}), 'imaginary url does not exist at wrong id');