added: getLineageIterator method to simplify working on large sets of assets
This commit is contained in:
parent
3d5224c93c
commit
29a419e1eb
3 changed files with 86 additions and 1 deletions
|
|
@ -17,7 +17,7 @@ use WebGUI::Session;
|
|||
use WebGUI::User;
|
||||
|
||||
use WebGUI::Asset;
|
||||
use Test::More tests => 87; # increment this value for each test you create
|
||||
use Test::More tests => 92; # increment this value for each test you create
|
||||
use Test::Deep;
|
||||
|
||||
# Test the methods in WebGUI::AssetLineage
|
||||
|
|
@ -442,6 +442,58 @@ cmp_bag(
|
|||
'getLineage: descendants of topFolder',
|
||||
);
|
||||
|
||||
####################################################
|
||||
#
|
||||
# getLineageIterator
|
||||
#
|
||||
####################################################
|
||||
|
||||
sub getListFromIterator {
|
||||
my $iterator = shift;
|
||||
my @items;
|
||||
while (my $item = $iterator->()) {
|
||||
push @items, $item->getId;
|
||||
}
|
||||
return \@items;
|
||||
}
|
||||
|
||||
@snipIds = map { $_->getId } @snippets;
|
||||
my $ids = getListFromIterator($folder->getLineageIterator(['descendants']));
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: get descendants of folder'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($folder->getLineageIterator(['self','descendants']));
|
||||
unshift @snipIds, $folder->getId;
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: get descendants of folder and self'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($folder->getLineageIterator(['self','children']));
|
||||
cmp_bag(
|
||||
\@snipIds,
|
||||
$ids,
|
||||
'getLineageIterator: descendants == children if there are no grandchildren'
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($topFolder->getLineageIterator(['self','children']));
|
||||
cmp_bag(
|
||||
[$topFolder->getId, $folder->getId, $folder2->getId, ],
|
||||
$ids,
|
||||
'getLineageIterator: children (no descendants) of topFolder',
|
||||
);
|
||||
|
||||
$ids = getListFromIterator($topFolder->getLineageIterator(['self','descendants']));
|
||||
cmp_bag(
|
||||
[$topFolder->getId, @snipIds, $folder2->getId, $snippet2->getId],
|
||||
$ids,
|
||||
'getLineageIterator: descendants of topFolder',
|
||||
);
|
||||
|
||||
####################################################
|
||||
#
|
||||
# addChild
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue