Tests for getParent and getParentLineage

Fixed getParentLineage.  The regular expression only matched strings
that were 8 characters long.
This commit is contained in:
Colin Kuskie 2007-04-13 21:45:32 +00:00
parent a548341aea
commit e894ed29ae
2 changed files with 27 additions and 2 deletions

View file

@ -540,7 +540,9 @@ Optional lineage of another Asset.
sub getParentLineage {
my $self = shift;
my $lineage = shift || $self->get("lineage");
my ($parentLineage) = $lineage =~ m/^(.).{6}$/;
my $lineageLength = length($lineage) - 6;
return $lineage unless $lineageLength;
my $parentLineage = substr($lineage, 0, $lineageLength);
return $parentLineage;
}

View file

@ -16,7 +16,7 @@ use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Asset;
use Test::More tests => 17; # increment this value for each test you create
use Test::More tests => 22; # increment this value for each test you create
use Test::Deep;
# Test the methods in WebGUI::AssetLineage
@ -97,6 +97,29 @@ is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild');
is(scalar @snippets, $folder->getChildCount, 'getChildCount');
####################################################
#
# getParent
#
####################################################
is($snippets[0]->getParent->getId, $folder->getId, 'getParent');
is($root->getParent->getId, $root->getId, "getParent: root's parent is itself");
####################################################
#
# getParentLineage
#
####################################################
is($snippets[0]->getParentLineage, $folder->get('lineage'), 'getParentLineage: self');
is($root->getParentLineage, '000001', 'getParentLineage: root');
is(
$root->getParentLineage('000001000002'),
'000001',
'getParentLineage: arbitrary lineage'
);
####################################################
#
# hasChildren