Fix for AssetLineage's getChildCount. It did not consider the

asset's status, only the state.  Change the SQL query to always
look at status, and consider state based on the options passed
to the method.
Add two quick tests to test that.  More to follow.
This commit is contained in:
Colin Kuskie 2007-11-20 04:46:45 +00:00
parent ced6e64aff
commit 0799d70428
2 changed files with 12 additions and 7 deletions

View file

@ -170,7 +170,7 @@ sub formatRank {
=head2 getChildCount ( opts )
Returns the number of children this asset has. This excludes assets in the trash or clipbaord.
Returns the number of children this asset has. This excludes assets in the trash or clipboard.
=head3 opts
@ -186,8 +186,8 @@ only those that are published or achived are counted.
sub getChildCount {
my $self = shift;
my $opts = shift || {};
my $stateWhere = $opts->{includeTrash} ? '' : "state in ('published','archived') and";
my ($count) = $self->session->db->quickArray("select count(*) from asset where $stateWhere parentId=?", [$self->getId]);
my $stateWhere = $opts->{includeTrash} ? '' : "asset.state='published' and";
my ($count) = $self->session->db->quickArray("select count(asset.state) from asset, assetData where asset.assetId=assetData.assetId and $stateWhere parentId=? and assetData.status in ('approved', 'archived')", [$self->getId]);
return $count;
}

View file

@ -17,7 +17,7 @@ use WebGUI::Session;
use WebGUI::User;
use WebGUI::Asset;
use Test::More tests => 76; # increment this value for each test you create
use Test::More tests => 78; # increment this value for each test you create
use Test::Deep;
# Test the methods in WebGUI::AssetLineage
@ -111,8 +111,13 @@ is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild: cached loo
#
####################################################
is(scalar @snippets, $folder->getChildCount, 'getChildCount on folder with several children');
is(1, $folder2->getChildCount, 'getChildCount on folder with 1 child');
is(scalar @snippets, $folder->getChildCount, 'getChildCount on folder with several children');
is(1, $folder2->getChildCount, 'getChildCount on folder with 1 child');
is(2, $topFolder->getChildCount, 'getChildCount on top folder (2 kids)');
$folder->update({status => 'pending'});
is(1, $topFolder->getChildCount, 'getChildCount with one child pending');
$folder->update({status => 'approved'});
####################################################
#
@ -120,7 +125,7 @@ is(1, $folder2->getChildCount, 'getChildCount on folder with 1 ch
#
####################################################
is(10, $topFolder->getDescendantCount, 'getDescendantCount on top folder');
is(10, $topFolder->getDescendantCount, 'getDescendantCount on top folder');
is(scalar @snippets, $folder->getDescendantCount, 'getDescendantCount on folder with several children');
is(1, $folder2->getDescendantCount, 'getDescendantCount on folder with 1 child');