10 tests for rank swap, promote and demote

changed promote and demote to use placeholders in AssetLineage.
Added explicit return values to demote
This commit is contained in:
Colin Kuskie 2007-04-14 01:50:11 +00:00
parent c9e2a8b9f3
commit a7cb2133c9
2 changed files with 67 additions and 5 deletions

View file

@ -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 lineage<?",[$self->get("parentId"), $self->get("lineage")]);
if (defined $sisterLineage) {
$self->swapRank($sisterLineage);
$self->{_properties}{lineage} = $sisterLineage;

View file

@ -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;
}