i18 label for StoryTopic help.
View methods for StoryTopic, with tests for template variables and amount of data returned.
This commit is contained in:
parent
5ae32f8cb4
commit
49b01b76ec
3 changed files with 183 additions and 8 deletions
|
|
@ -19,6 +19,8 @@ use WebGUI::Utility;
|
||||||
use WebGUI::Asset::Story;
|
use WebGUI::Asset::Story;
|
||||||
use base 'WebGUI::Asset::Wobject';
|
use base 'WebGUI::Asset::Wobject';
|
||||||
|
|
||||||
|
use constant DATE_FORMAT => '%c_%D_%y';
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 definition ( )
|
=head2 definition ( )
|
||||||
|
|
@ -94,7 +96,7 @@ sub prepareView {
|
||||||
|
|
||||||
=head2 view ( )
|
=head2 view ( )
|
||||||
|
|
||||||
method called by the www_view method. Returns a processed template
|
Method called by the www_view method. Returns a processed template
|
||||||
to be displayed within the page style.
|
to be displayed within the page style.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
@ -104,14 +106,57 @@ sub view {
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
|
|
||||||
#This automatically creates template variables for all of your wobject's properties.
|
#This automatically creates template variables for all of your wobject's properties.
|
||||||
my $var = $self->get;
|
my $var = $self->viewTemplateVariables;
|
||||||
|
|
||||||
#This is an example of debugging code to help you diagnose problems.
|
|
||||||
#WebGUI::ErrorHandler::warn($self->get("templateId"));
|
|
||||||
|
|
||||||
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
return $self->processTemplate($var, undef, $self->{_viewTemplate});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub www_view {
|
||||||
|
my $self = shift;
|
||||||
|
$self->{_standAlone} = 1;
|
||||||
|
return $self->SUPER::www_view;
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 viewTemplateVars ( )
|
||||||
|
|
||||||
|
Make template variables for the view template.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub viewTemplateVariables {
|
||||||
|
my ($self) = @_;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $numberOfStories = $self->{_standAlone}
|
||||||
|
? $self->get('storiesPer')
|
||||||
|
: $self->get('storiesShort');
|
||||||
|
my $var = $self->get();
|
||||||
|
my $wordList = WebGUI::Keyword::string2list($self->get('keywords'));
|
||||||
|
my $key = WebGUI::Keyword->new($session);
|
||||||
|
my $p = $key->getMatchingAssets({
|
||||||
|
keywords => $wordList,
|
||||||
|
isa => 'WebGUI::Asset::Story',
|
||||||
|
usePaginator => 1,
|
||||||
|
rowsPerPage => $numberOfStories,
|
||||||
|
});
|
||||||
|
my $storyIds = $p->getPageData();
|
||||||
|
$var->{story_loop} = [];
|
||||||
|
##Only build objects for the assets that we need
|
||||||
|
STORY: foreach my $storyId (@{ $storyIds }) {
|
||||||
|
my $story = WebGUI::Asset->new($session, $storyId->{assetId}, $storyId->{className}, $storyId->{revisionDate});
|
||||||
|
next STORY unless $story;
|
||||||
|
my $creationDate = $story->get('creationDate');
|
||||||
|
push @{$var->{story_loop}}, {
|
||||||
|
url => $session->url->append($self->getUrl, 'func=viewStory;assetId='.$storyId->{assetId}),
|
||||||
|
title => $story->getTitle,
|
||||||
|
creationDate => $creationDate,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $var;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
1;
|
1;
|
||||||
#vim:ft=perl
|
#vim:ft=perl
|
||||||
|
|
|
||||||
|
|
@ -281,6 +281,12 @@ our $I18N = {
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'story asset template variables title' => {
|
||||||
|
message => q|Story Asset Template Variables.|,
|
||||||
|
context => q|Title of a help page for asset level template variables.|,
|
||||||
|
lastUpdated => 0,
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 0;
|
my $tests = 4;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -40,15 +40,139 @@ plan tests => 1 + $tests;
|
||||||
my $class = 'WebGUI::Asset::Wobject::StoryTopic';
|
my $class = 'WebGUI::Asset::Wobject::StoryTopic';
|
||||||
my $loaded = use_ok($class);
|
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: {
|
||||||
|
|
||||||
skip "Unable to load module $class", $tests unless $loaded;
|
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
|
# Cleanup
|
||||||
END {
|
END {
|
||||||
|
$archive->purge if $archive;
|
||||||
|
$topic->purge if $topic;
|
||||||
|
if ($versionTag) {
|
||||||
|
$versionTag->rollback;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue