i18 label for StoryTopic help.

View methods for StoryTopic, with tests for template variables and amount of data returned.
This commit is contained in:
Colin Kuskie 2009-03-19 04:07:59 +00:00
parent 5ae32f8cb4
commit 49b01b76ec
3 changed files with 183 additions and 8 deletions

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 0;
my $tests = 4;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -40,15 +40,139 @@ plan tests => 1 + $tests;
my $class = 'WebGUI::Asset::Wobject::StoryTopic';
my $loaded = use_ok($class);
my $storage;
my $versionTag = WebGUI::VersionTag->getWorking($session);
my $archive = WebGUI::Asset->getDefault($session)->addChild({className => 'WebGUI::Asset::Wobject::StoryArchive', title => 'My Stories', url => '/home/mystories'});
my $now = time();
my $nowFolder = $archive->getFolder($now);
my $yesterday = $now-24*3600;
my $newFolder = $archive->getFolder($yesterday);
my $creationDateSth = $session->db->prepare('update asset set creationDate=? where assetId=?');
my $pastStory = $newFolder->addChild({ className => 'WebGUI::Asset::Story', title => "Yesterday is history", keywords => 'andy norton'});
$creationDateSth->execute([$yesterday, $pastStory->getId]);
my @staff = qw/norton hadley mert trout/;
my @inmates = qw/bogs red brooks andy heywood tommy jake skeet/;
my @characters = (@staff, @inmates, );
my $storiesToMake = 16;
my @stories = ();
my $storyHandler = {};
STORY: foreach my $name (@characters) {
my $namedStory = $nowFolder->addChild({ className => 'WebGUI::Asset::Story', title => $name, keywords => $name, } );
$storyHandler->{$name} = $namedStory;
$creationDateSth->execute([$now, $namedStory->getId]);
}
my $topic;
SKIP: {
skip "Unable to load module $class", $tests unless $loaded;
$topic = WebGUI::Asset->getDefault($session)->addChild({ className => 'WebGUI::Asset::Wobject::StoryTopic', title => 'Popular inmates in Shawshank Prison', keywords => join(' ', @inmates)});
isa_ok($topic, 'WebGUI::Asset::Wobject::StoryTopic', 'made a Story Topic');
$topic->update({
storiesPer => 6,
storiesShort => 3,
});
################################################################
#
# viewTemplateVariables
#
################################################################
my $templateVars;
$templateVars = $topic->viewTemplateVariables();
cmp_deeply(
$templateVars->{story_loop},
[
{
title => 'bogs',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'bogs'}->getId),
creationDate => $now,
},
{
title => 'red',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'red'}->getId),
creationDate => $now,
},
{
title => 'brooks',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'brooks'}->getId),
creationDate => $now,
},
],
'viewTemplateVars has right number and contents in the story_loop'
);
$topic->{_standAlone} = 1;
$templateVars = $topic->viewTemplateVariables();
cmp_deeply(
$templateVars->{story_loop},
[
{
title => 'bogs',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'bogs'}->getId),
creationDate => $now,
},
{
title => 'red',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'red'}->getId),
creationDate => $now,
},
{
title => 'brooks',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'brooks'}->getId),
creationDate => $now,
},
{
title => 'andy',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'andy'}->getId),
creationDate => $now,
},
{
title => 'heywood',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'heywood'}->getId),
creationDate => $now,
},
{
title => 'tommy',
url => $session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'tommy'}->getId),
creationDate => $now,
},
],
'viewTemplateVars has right number and contents in the story_loop in standalone mode'
);
$topic->update({
storiesPer => 16,
storiesShort => 3,
});
$templateVars = $topic->viewTemplateVariables;
my @topicInmates = map { $_->{title} } @{ $templateVars->{story_loop} };
cmp_deeply(
\@topicInmates,
[@inmates, 'Yesterday is history'], #extra for pastStory
'viewTemplateVariables: is only finding things with its keywords'
);
}
#----------------------------------------------------------------------------
# Cleanup
END {
$archive->purge if $archive;
$topic->purge if $topic;
if ($versionTag) {
$versionTag->rollback;
}
}