Add template field to StoryTopic. The same template will be shared between both modes.

Add top story variables, and tests.
This commit is contained in:
Colin Kuskie 2009-03-19 16:43:21 +00:00
parent 4b859e5ada
commit ea31d52ac0
5 changed files with 71 additions and 18 deletions

View file

@ -32,9 +32,6 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
installStoryManagerTables($session);
upgradeConfigFiles($session);
addGroupToAddToMatrix( $session );
addScreenshotTemplatesToMatrix( $session );
surveyDoAfterTimeLimit($session);
@ -42,6 +39,10 @@ surveyRemoveResponseTemplate($session);
surveyEndWorkflow($session);
installAssetHistory($session);
# Story Manager
installStoryManagerTables($session);
upgradeConfigFiles($session);
# Passive Analytics
pa_installLoggingTables($session);
pa_installPassiveAnalyticsRule($session);
@ -364,6 +365,7 @@ CREATE TABLE StoryTopic (
revisionDate BIGINT NOT NULL,
storiesPer INTEGER,
storiesShort INTEGER,
templateId CHAR(22) BINARY,
storyTemplateId CHAR(22) BINARY,
PRIMARY KEY ( assetId, revisionDate )
)

View file

@ -53,6 +53,15 @@ sub definition {
hoverHelp => $i18n->get('stories short help'),
defaultValue => 5,
},
templateId => {
tab => 'display',
fieldType => 'template',
label => $i18n->get('template'),
hoverHelp => $i18n->get('template help'),
filter => 'fixId',
namespace => 'Story',
defaultValue => 'liNZSK4xWGyALU6nu_criw',
},
storyTemplateId => {
tab => 'display',
fieldType => 'template',
@ -146,14 +155,24 @@ sub viewTemplateVariables {
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,
creationDate => $story->get('creationDate'),
}
}
if ($self->{_standAlone}) {
my $topStoryData = $storyIds->[0];
shift @{ $var->{story_loop} };
##Note, this could have saved from the loop above, but this looks more clean and encapsulated to me.
my $topStory = WebGUI::Asset->new($session, $topStoryData->{assetId}, $topStoryData->{className}, $topStoryData->{revisionDate});
$var->{topStoryTitle} = $topStory->getTitle;
$var->{topStoryUrl} = $session->url->append($self->getUrl, 'func=viewStory;assetId='.$topStoryData->{assetId}),
$var->{topStoryCreationDate} = $topStory->get('creationDate');
##TODO: Photo variables
}
return $var;
}

View file

@ -19,13 +19,16 @@ our $HELP = {
],
fields => [],
variables => [
{ 'name' => 'story_loop',
'variables' => [
{ 'name' => 'url' },
{ 'name' => 'title' },
{ 'name' => 'creationDate' },
{ name => 'story_loop',
variables => [
{ name => 'url' },
{ name => 'title' },
{ name => 'creationDate' },
],
},
{ name => 'topStoryTitle' },
{ name => 'topStoryUrl' },
{ name => 'topStoryCreationDate' },
],
related => []
},

View file

@ -81,6 +81,24 @@ our $I18N = {
lastUpdated => 0,
},
'topStoryUrl' => {
message => q|The URL to view the top story.|,
context => q|Template variable.|,
lastUpdated => 0,
},
'topStoryTitle' => {
message => q|The title of the top story.|,
context => q|Template variable.|,
lastUpdated => 0,
},
'topStoryCreationDate' => {
message => q|The epoch date when the top story was created, or submitted, to its Story Archive.|,
context => q|Template variable.|,
lastUpdated => 0,
},
'view template' => {
message => q|View Story Topic Template|,
context => q|Template variable.|,

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 4;
my $tests = 8;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -113,16 +113,18 @@ cmp_deeply(
'viewTemplateVars has right number and contents in the story_loop'
);
ok(
! exists $templateVars->{topStoryTitle}
&& ! exists $templateVars->{topStoryUrl}
&& ! exists $templateVars->{topStoryCreationDate},
'topStory variables not present unless in standalone mode'
);
$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),
@ -152,11 +154,20 @@ cmp_deeply(
'viewTemplateVars has right number and contents in the story_loop in standalone mode'
);
is($templateVars->{topStoryTitle}, 'bogs', 'viewTemplateVars in standalone mode, title');
is(
$templateVars->{topStoryUrl},
$session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'bogs'}->getId),
'viewTemplateVars in standalone mode, url'
);
is($templateVars->{topStoryCreationDate}, $now, 'viewTemplateVars in standalone mode, title');
$topic->update({
storiesPer => 16,
storiesShort => 3,
storiesShort => 20,
});
$topic->{_standAlone} = 0;
$templateVars = $topic->viewTemplateVariables;
my @topicInmates = map { $_->{title} } @{ $templateVars->{story_loop} };
cmp_deeply(