diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index e11bec4f5..a4b83f607 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -139,12 +139,13 @@ Swaps lineage with sister below. Returns 1 if there is a sister to swap. Otherwi sub demote { my $self = shift; my ($sisterLineage) = $self->session->db->quickArray("select min(lineage) from asset - where parentId=".$self->session->db->quote($self->get("parentId"))." - and state='published' and lineage>".$self->session->db->quote($self->get("lineage"))); + where parentId=? and state='published' and lineage>?",[$self->get('parentId'), $self->get('lineage')]); if (defined $sisterLineage) { $self->swapRank($sisterLineage); $self->{_properties}{lineage} = $sisterLineage; + return 1; } + return 0; } @@ -634,8 +635,7 @@ Keeps the same rank of lineage, swaps with sister above. Returns 1 if there is a sub promote { my $self = shift; my ($sisterLineage) = $self->session->db->quickArray("select max(lineage) from asset - where parentId=".$self->session->db->quote($self->get("parentId"))." - and state='published' and lineage<".$self->session->db->quote($self->get("lineage"))); + where parentId=? and state='published' and lineageget("parentId"), $self->get("lineage")]); if (defined $sisterLineage) { $self->swapRank($sisterLineage); $self->{_properties}{lineage} = $sisterLineage; diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index d49ffda99..d7f481426 100644 --- a/t/Asset/AssetLineage.t +++ b/t/Asset/AssetLineage.t @@ -16,7 +16,7 @@ use WebGUI::Test; use WebGUI::Session; use WebGUI::Asset; -use Test::More tests => 33; # increment this value for each test you create +use Test::More tests => 43; # increment this value for each test you create use Test::Deep; # Test the methods in WebGUI::AssetLineage @@ -202,6 +202,68 @@ cmp_bag( 'swapRank: swapped first and second snippets' ); +is( + $snippets[3]->swapRank($snippets[0]->get('lineage'), $snippets[0]->get('lineage'), ), + 1, + 'swapRank: remote, two different snippets to restore original order' +); + +@snipIds[0,1] = @snipIds[1,0]; +$lineageIds = $folder->getLineage(['descendants']); +cmp_bag( + \@snipIds, + $lineageIds, + 'swapRank: swapped first and second snippets' +); + +#################################################### +# +# demote +# +#################################################### + +ok(!$snippets[6]->demote(), 'demote: last snippet in the set will not swap'); +$lineageIds = $folder->getLineage(['descendants']); +cmp_bag( + \@snipIds, + $lineageIds, + 'demote: no change' +); + +ok($snippets[5]->demote(), 'demote: demote 5 to 6'); +@snipIds[5,6] = @snipIds[6,5]; +$lineageIds = $folder->getLineage(['descendants']); +cmp_bag( + \@snipIds, + $lineageIds, + 'demote: 5 was swapped with 6' +); + +#################################################### +# +# promote +# +#################################################### + +ok(!$snippets[0]->promote(), 'promote: first snippet in the set will not swap'); +$lineageIds = $folder->getLineage(['descendants']); +cmp_bag( + \@snipIds, + $lineageIds, + 'promote: no change' +); + +ok($snippets[4]->promote(), 'promote: promote 4 to 3'); +@snipIds[4,3] = @snipIds[3,4]; +$lineageIds = $folder->getLineage(['descendants']); +cmp_bag( + \@snipIds, + $lineageIds, + 'promote: 4 was swapped with 3' +); + + + END { $versionTag->rollback; }