Cache tests for getFirst- and getLastChild, hasChildren.
newByLineage tests, with cache changed newByLineage to use placeholders Coverage is 59/55/84
This commit is contained in:
parent
450aab40a0
commit
bd577a6712
2 changed files with 49 additions and 12 deletions
|
|
@ -618,7 +618,7 @@ sub newByLineage {
|
||||||
my $id = $assetLineage->{$lineage}{id};
|
my $id = $assetLineage->{$lineage}{id};
|
||||||
$class = $assetLineage->{$lineage}{class};
|
$class = $assetLineage->{$lineage}{class};
|
||||||
unless ($id && $class) {
|
unless ($id && $class) {
|
||||||
($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=".$session->db->quote($lineage));
|
($id,$class) = $session->db->quickArray("select assetId, className from asset where lineage=?",[$lineage]);
|
||||||
$assetLineage->{$lineage}{id} = $id;
|
$assetLineage->{$lineage}{id} = $id;
|
||||||
$assetLineage->{$lineage}{class} = $class;
|
$assetLineage->{$lineage}{class} = $class;
|
||||||
$session->stow->set("assetLineage",$assetLineage);
|
$session->stow->set("assetLineage",$assetLineage);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ use WebGUI::Session;
|
||||||
use WebGUI::User;
|
use WebGUI::User;
|
||||||
|
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
use Test::More tests => 59; # increment this value for each test you create
|
use Test::More tests => 67; # increment this value for each test you create
|
||||||
use Test::Deep;
|
use Test::Deep;
|
||||||
|
|
||||||
# Test the methods in WebGUI::AssetLineage
|
# Test the methods in WebGUI::AssetLineage
|
||||||
|
|
@ -94,6 +94,7 @@ cmp_bag(\@snipIds, $lineageIds, 'default order returned by getLineage is lineage
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild');
|
is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild');
|
||||||
|
is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild: cached lookup');
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
#
|
#
|
||||||
|
|
@ -102,6 +103,7 @@ is($snippets[0]->getId, $folder->getFirstChild->getId, 'getFirstChild');
|
||||||
####################################################
|
####################################################
|
||||||
|
|
||||||
is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild');
|
is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild');
|
||||||
|
is($snippets[-1]->getId, $folder->getLastChild->getId, 'getLastChild: cached lookup');
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
#
|
#
|
||||||
|
|
@ -145,16 +147,6 @@ is(
|
||||||
'getParentLineage: arbitrary lineage'
|
'getParentLineage: arbitrary lineage'
|
||||||
);
|
);
|
||||||
|
|
||||||
####################################################
|
|
||||||
#
|
|
||||||
# hasChildren
|
|
||||||
#
|
|
||||||
####################################################
|
|
||||||
|
|
||||||
ok($folder->hasChildren, 'test folder has children');
|
|
||||||
ok($root->hasChildren, 'root node has children');
|
|
||||||
ok(!$snippets[0]->hasChildren, 'test snippet has no children');
|
|
||||||
|
|
||||||
####################################################
|
####################################################
|
||||||
#
|
#
|
||||||
# cascadeLineage
|
# cascadeLineage
|
||||||
|
|
@ -332,6 +324,51 @@ is($snippets[6]->getRank(), '7', 'setRank: move the Asset back (higher rank)');
|
||||||
$lineageIds = $folder->getLineage(['descendants']);
|
$lineageIds = $folder->getLineage(['descendants']);
|
||||||
cmp_bag(\@snipIds, $lineageIds, 'setRank: put them back in order');
|
cmp_bag(\@snipIds, $lineageIds, 'setRank: put them back in order');
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# hasChildren
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
##Functional tests
|
||||||
|
ok($root->hasChildren, 'root node has children');
|
||||||
|
ok(!$snippets[0]->hasChildren, 'test snippet has no children');
|
||||||
|
|
||||||
|
##Coverage tests will require reaching inside the object
|
||||||
|
##to reset the caching
|
||||||
|
delete $folder->{_hasChildren};
|
||||||
|
ok($folder->hasChildren, 'test folder has children, manually built');
|
||||||
|
|
||||||
|
delete $folder->{_hasChildren};
|
||||||
|
$folder->getLastChild();
|
||||||
|
ok($folder->hasChildren, 'hasChildren: cached from getLastChild');
|
||||||
|
|
||||||
|
delete $folder->{_hasChildren};
|
||||||
|
$folder->getFirstChild();
|
||||||
|
ok($folder->hasChildren, 'hasChildren: cached from getFirstChild');
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# newByLineage
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
##Clear the stowed assetLineage hash
|
||||||
|
$session->stow->delete('assetLineage');
|
||||||
|
my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage'));
|
||||||
|
is ($snippet4->getId, $snippets[4]->getId, 'newByLineage returns correct Asset');
|
||||||
|
|
||||||
|
$snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage'));
|
||||||
|
is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: cached lookup');
|
||||||
|
|
||||||
|
my $cachedLineage = $session->stow->get('assetLineage');
|
||||||
|
delete $cachedLineage->{$snippet4->get('lineage')}->{id};
|
||||||
|
my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage'));
|
||||||
|
is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing id cache forces lookup');
|
||||||
|
|
||||||
|
delete $cachedLineage->{$snippet4->get('lineage')}->{class};
|
||||||
|
my $snippet4 = WebGUI::Asset->newByLineage($session, $snippets[4]->get('lineage'));
|
||||||
|
is ($snippet4->getId, $snippets[4]->getId, 'newByLineage: failing class cache forces lookup');
|
||||||
|
|
||||||
END {
|
END {
|
||||||
$versionTag->rollback;
|
$versionTag->rollback;
|
||||||
foreach my $account ($editor) {
|
foreach my $account ($editor) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue