diff --git a/lib/WebGUI/AssetLineage.pm b/lib/WebGUI/AssetLineage.pm index 994e9d283..e7a017125 100644 --- a/lib/WebGUI/AssetLineage.pm +++ b/lib/WebGUI/AssetLineage.pm @@ -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; } diff --git a/t/Asset/AssetLineage.t b/t/Asset/AssetLineage.t index 7774d5504..c5e408fdc 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 => 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');