From 5a379fe91e7c4f981123be1f7f65ee07d64b845b Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 25 Feb 2007 06:18:15 +0000 Subject: [PATCH] Add tests for urlExists and fix bugs in the method. It now handles placeholders correctly and does exactly what the POD says, assetId requires that the url be with that assetId, rather than not in that assetId. --- lib/WebGUI/Asset.pm | 8 +++++--- t/Asset/Asset.t | 19 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) 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');