diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 4a4f3e90b..981f38d01 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -618,7 +618,7 @@ sub newByLineage { my $id = $assetLineage->{$lineage}{id}; $class = $assetLineage->{$lineage}{class}; unless ($id && $class) { - ($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=".$session->db->quote($lineage)); + ($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=?",[$lineage]); $assetLineage->{$lineage}{id} = $id; $assetLineage->{$lineage}{class} = $class; $session->stow->set("assetLineage",$assetLineage); diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index 269fae04a..55caabd20 100644 --- a/t/Asset/AssetLineage.t +++ b/t/Asset/AssetLineage.t @@ -17,7 +17,7 @@ use WebGUI::Session; use WebGUI::User; use WebGUI::Asset; -use Test::More tests => 59; # increment this value for each test you create +use Test::More tests => 67; # increment this value for each test you create use Test::Deep; # Test the methods in WebGUI::AssetLineage @@ -94,6 +94,7 @@ cmp_bag(\@snipIds, $lineageIds, 'default order returned by getLineage is lineage #################################################### is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild'); +is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild: cached lookup'); #################################################### # @@ -102,6 +103,7 @@ is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild'); #################################################### is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild'); +is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild: cached lookup'); #################################################### # @@ -145,16 +147,6 @@ is( 'getParentLineage: arbitrary lineage' ); -#################################################### -# -# hasChildren -# -#################################################### - -ok($folder->hasChildren, 'test folder has children'); -ok($root->hasChildren, 'root node has children'); -ok(!$snippets[0]->hasChildren, 'test snippet has no children'); - #################################################### # # cascadeLineage @@ -332,6 +324,51 @@ is($snippets[6]->getRank(), '7', 'setRank: move the Asset back (higher rank)'); $lineageIds = $folder->getLineage(['descendants']); cmp_bag(\@snipIds, $lineageIds, 'setRank: put them back in order'); +#################################################### +# +# hasChildren +# +#################################################### + +##Functional tests +ok($root->hasChildren, 'root node has children'); +ok(!$snippets[0]->hasChildren, 'test snippet has no children'); + +##Coverage tests will require reaching inside the object +##to reset the caching +delete $folder->{_hasChildren}; +ok($folder->hasChildren, 'test folder has children, manually built'); + +delete $folder->{_hasChildren}; +$folder->getLastChild(); +ok($folder->hasChildren, 'hasChildren: cached from getLastChild'); + +delete $folder->{_hasChildren}; +$folder->getFirstChild(); +ok($folder->hasChildren, 'hasChildren: cached from getFirstChild'); + +#################################################### +# +# newByLineage +# +#################################################### +##Clear the stowed assetLineage hash +$session->stow->delete('assetLineage'); +my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); +is ($snippet4->getId, $snippets[4]->getId, 'newByLineage returns correct Asset'); + +$snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); +is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: cached lookup'); + +my $cachedLineage = $session->stow->get('assetLineage'); +delete $cachedLineage->{$snippet4->get('lineage')}->{id}; +my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); +is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing id cache forces lookup'); + +delete $cachedLineage->{$snippet4->get('lineage')}->{class}; +my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage')); +is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing class cache forces lookup'); + END { $versionTag->rollback; foreach my $account ($editor) {