Fix Keywords so that by default, only Keywords from published assets are returned.

Reported as bug against the StoryManager, but also affects Wiki, Shelf.
This commit is contained in:
Colin Kuskie 2009-07-20 16:01:30 +00:00
parent 75c8ec1e59
commit c668226651
3 changed files with 96 additions and 16 deletions

View file

@ -17,7 +17,9 @@ use WebGUI::Keyword;
use WebGUI::Asset;
# load your modules here
use Test::More tests => 9; # increment this value for each test you create
use Test::More tests => 14; # increment this value for each test you create
use Test::Deep;
use Data::Dumper;
my $session = WebGUI::Test->session;
@ -31,6 +33,19 @@ isa_ok($keyword, "WebGUI::Keyword");
$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"test key, word, foo bar"});
my ($count) = $session->db->quickArray("select count(*) from assetKeyword where assetId=?", [$home->getId]);
is($count, 3, "setKeywordsForAsset() create");
cmp_bag(
$keyword->getKeywordsForAsset({ asset => $home, asArrayRef => 1}),
['test key', 'word', 'foo bar'],
'... check correct keywords set, returns array ref'
);
my $keywords = $keyword->getKeywordsForAsset({ asset => $home, });
my @keywords = split ',\s*', $keywords;
cmp_bag(
\@keywords,
['test key', 'word', 'foo bar'],
'... check correct keywords set, returns string'
);
$keyword->setKeywordsForAsset({ asset=>$home, keywords=>"webgui, rules"});
my ($count) = $session->db->quickArray("select count(*) from assetKeyword where assetId=?", [$home->getId]);
@ -46,8 +61,39 @@ like($keyword->getKeywordsForAsset({asset=>$home }), qr/owns/, "getLatestVersion
$keyword->deleteKeyword({keyword => "owns"});
unlike($keyword->getKeywordsForAsset({asset=>$home }), qr/owns/, "getLatestVersionNumber()");
my $snippet = $home->addChild({
className => 'WebGUI::Asset::Snippet',
title => 'keyword snippet',
snippet => 'keyword snippet',
keywords => 'webgui',
});
my $tag = WebGUI::VersionTag->getWorking($session);
WebGUI::Test->tagsToRollback($tag);
$tag->commit;
my $assetIds = $keyword->getMatchingAssets({ keyword => 'webgui', });
cmp_deeply(
$assetIds,
[$snippet->getId, $home->getId, ],
'getMatchingAssets, by keyword, assetIds in order by creationDate, descending'
);
$snippet->trash();
cmp_deeply(
$keyword->getMatchingAssets({ keyword => 'webgui', }),
[$home->getId, ],
'... only published assets'
);
cmp_deeply(
$keyword->getMatchingAssets({ keyword => 'webgui', states => [ qw/published trash/, ]}),
[$snippet->getId, $home->getId, ],
'... retrieving assets in more than one state'
);
$keyword->deleteKeywordsForAsset($home);
is(scalar(@{$keyword->getKeywordsForAsset({ asset=>$home, asArrayRef=>1})}), 0, "getKeywordsForAsset()");
undef $keyword;
undef $home;