diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index a4b83f607..be6291167 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -100,7 +100,8 @@ sub addChild { =head2 cascadeLineage ( newLineage [,oldLineage] ) -Updates lineage when asset is moved. Prepends newLineage to the lineage "stack." +Updates lineage when asset is moved. Prepends newLineage to the lineage +"stack." The change only occurs in the db, no in the objects. =head3 newLineage @@ -117,7 +118,7 @@ sub cascadeLineage { my $newLineage = shift; my $oldLineage = shift || $self->get("lineage"); my $prepared = $self->session->db->prepare("update asset set lineage=? where assetId=?"); - my $descendants = $self->session->db->read("select assetId,lineage from asset where lineage like ".$self->session->db->quote($oldLineage.'%')); + my $descendants = $self->session->db->read("select assetId,lineage from asset where lineage like ?",[$oldLineage.'%']); my $cache = WebGUI::Cache->new($self->session); while (my ($assetId, $lineage) = $descendants->array) { my $fixedLineage = $newLineage.substr($lineage,length($oldLineage)); @@ -134,6 +135,8 @@ sub cascadeLineage { Swaps lineage with sister below. Returns 1 if there is a sister to swap. Otherwise returns 0. +This will update the lineage of $self, but not the sister. + =cut sub demote { @@ -630,6 +633,8 @@ sub newByLineage { Keeps the same rank of lineage, swaps with sister above. Returns 1 if there is a sister to swap. Otherwise returns 0. +This will update the lineage of $self, but not the sister. + =cut sub promote { @@ -729,7 +734,8 @@ Returns 1. Swaps current rank with second rank. =head3 first -If specified, swaps second rank with first rank. +If specified, swaps second rank with first rank. The change only occurs in the db, +no in the objects. =cut diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index 4b3db7373..9d0a786a5 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 => 45; # increment this value for each test you create +use Test::More tests => 49; # increment this value for each test you create use Test::Deep; # Test the methods in WebGUI::AssetLineage @@ -60,6 +60,7 @@ foreach my $snipNum (0..6) { groupIdEdit => 3, title => "Snippet $snipNum", menuTitle => $snipNum, + url => 'snippet'.$snipNum, }); } @@ -100,7 +101,8 @@ is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild'); # #################################################### -is(scalar @snippets, $folder->getChildCount, 'getChildCount'); +is(scalar @snippets, $folder->getChildCount, 'getChildCount on folder with several children'); +is(1, $folder2->getChildCount, 'getChildCount on folder with 1 child'); #################################################### # @@ -209,12 +211,15 @@ cmp_bag( 'swapRank: swapped first and second snippets' ); +@snippets[0..1] = map { WebGUI::Asset->newByUrl($session, "snippet$_") } 0..1; + is( - $snippets[3]->swapRank($snippets[0]->get('lineage'), $snippets[0]->get('lineage'), ), + $snippets[1]->swapRank($snippets[0]->get('lineage'), $snippets[1]->get('lineage'), ), 1, 'swapRank: remote, two different snippets to restore original order' ); +@snippets[0..1] = map { WebGUI::Asset->newByUrl($session, "snippet$_") } 0..1; @snipIds[0,1] = @snipIds[1,0]; $lineageIds = $folder->getLineage(['descendants']); cmp_bag( @@ -223,6 +228,18 @@ cmp_bag( 'swapRank: swapped first and second snippets' ); + +ok($folder->swapRank($folder2->get('lineage')), 'swap folder and folder2'); + +is(scalar @snippets, $folder->getChildCount, 'changing lineage does not change relationship in folder'); +is(1 , $folder2->getChildCount, 'changing lineage does not change relationship in folder2'); + +##Reinstance the asset object due to db manipulation +$folder = WebGUI::Asset->newByUrl($session, $folder->get('url')); +$folder2 = WebGUI::Asset->newByUrl($session, $folder2->get('url')); +@snippets = map { WebGUI::Asset->newByUrl($session, "snippet$_") } 0..6; +$snippet2 = WebGUI::Asset->newByUrl($session, $snippet2->get('url')); + #################################################### # # demote @@ -252,6 +269,7 @@ cmp_bag( # #################################################### + ok(!$snippets[0]->promote(), 'promote: first snippet in the set will not swap'); $lineageIds = $folder->getLineage(['descendants']); cmp_bag(