Top story photo template variables, with i18n, help and tests.
This commit is contained in:
parent
4768a8687e
commit
c28c7771c3
4 changed files with 116 additions and 17 deletions
|
|
@ -166,6 +166,22 @@ sub viewTemplateVariables {
|
|||
$var->{topStoryUrl} = $session->url->append($self->getUrl, 'func=viewStory;assetId='.$topStoryData->{assetId}),
|
||||
$var->{topStoryCreationDate} = $topStory->get('creationDate');
|
||||
##TODO: Photo variables
|
||||
my $photoData = $topStory->getPhotoData;
|
||||
PHOTO: foreach my $photo (@{ $photoData }) {
|
||||
next PHOTO unless $photo->{storageId};
|
||||
my $storage = WebGUI::Storage->get($session, $photo->{storageId});
|
||||
my $file = $storage->getFiles->[0];
|
||||
warn $storage->getId;
|
||||
next PHOTO unless $file;
|
||||
my $imageUrl = $storage->getUrl($file);
|
||||
$var->{topStoryImageUrl} = $imageUrl;
|
||||
$var->{topStoryImageCaption} = $photo->{caption};
|
||||
$var->{topStoryImageByline} = $photo->{byLine};
|
||||
$var->{topStoryImageAlt} = $photo->{alt};
|
||||
$var->{topStoryImageTitle} = $photo->{title};
|
||||
$var->{topStoryImageLink} = $photo->{url};
|
||||
last PHOTO;
|
||||
}
|
||||
}
|
||||
$var->{standAlone} = $self->{_standAlone};
|
||||
$var->{rssUrl} = $self->getUrl('func=viewRss');
|
||||
|
|
|
|||
|
|
@ -27,12 +27,18 @@ our $HELP = {
|
|||
{ name => 'creationDate' },
|
||||
],
|
||||
},
|
||||
{ name => 'topStoryTitle' },
|
||||
{ name => 'topStorySubtitle' },
|
||||
{ name => 'topStoryUrl' },
|
||||
{ name => 'topStoryTitle' },
|
||||
{ name => 'topStorySubtitle' },
|
||||
{ name => 'topStoryUrl' },
|
||||
{ name => 'topStoryCreationDate' },
|
||||
{ name => 'rssUrl' },
|
||||
{ name => 'atomUrl' },
|
||||
{ name => 'topStoryImageUrl' },
|
||||
{ name => 'topStoryImageCaption' },
|
||||
{ name => 'topStoryImageByline' },
|
||||
{ name => 'topStoryImageAlt' },
|
||||
{ name => 'topStoryImageTitle' },
|
||||
{ name => 'topStoryImageLink' },
|
||||
{ name => 'rssUrl' },
|
||||
{ name => 'atomUrl' },
|
||||
],
|
||||
related => []
|
||||
},
|
||||
|
|
|
|||
|
|
@ -105,6 +105,42 @@ our $I18N = {
|
|||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageCaption' => {
|
||||
message => q|The Caption of the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageByline' => {
|
||||
message => q|The Byline of the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageAlt' => {
|
||||
message => q|The alternate image text for the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageTitle' => {
|
||||
message => q|The image title for the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageLink' => {
|
||||
message => q|The link for the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'topStoryImageUrl' => {
|
||||
message => q|The URL to the first photo for the top story, if it exists.|,
|
||||
context => q|Template variable.|,
|
||||
lastUpdated => 0,
|
||||
},
|
||||
|
||||
'standAlone' => {
|
||||
message => q|This variable will be true if the Story Topic is being viewed directly, by its URL. Otherwise, if it is viewed as part of a Page Layout or other Container, it will be false.|,
|
||||
context => q|Template variable.|,
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 11;
|
||||
my $tests = 14;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -58,7 +58,6 @@ $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 = {};
|
||||
|
|
@ -158,19 +157,61 @@ 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->{topStoryTitle}, 'bogs', '... topStoryTitle');
|
||||
is(
|
||||
$templateVars->{topStorySubtitle},
|
||||
'drinking his food through a straw',
|
||||
'viewTemplateVars in standalone mode, subtitle'
|
||||
'... topStorySubtitle'
|
||||
);
|
||||
is(
|
||||
$templateVars->{topStoryUrl},
|
||||
$session->url->append($topic->getUrl, 'func=viewStory;assetId='.$storyHandler->{'bogs'}->getId),
|
||||
'viewTemplateVars in standalone mode, url'
|
||||
'... topStoryUrl'
|
||||
);
|
||||
is($templateVars->{topStoryCreationDate}, $now, 'viewTemplateVars in standalone mode, title');
|
||||
ok($templateVars->{standAlone}, 'viewTemplateVars: in standalone mode');
|
||||
is($templateVars->{topStoryCreationDate}, $now, '... topStoryCreationDate');
|
||||
ok($templateVars->{standAlone}, '... standAlone mode=1');
|
||||
|
||||
my $storage = WebGUI::Storage->create($session);
|
||||
WebGUI::Test->storagesToDelete($storage);
|
||||
$storyHandler->{bogs}->setPhotoData([{
|
||||
caption => "Octopus seen at the scene of Mrs. Dufresne's murder.",
|
||||
byLine => 'Elmo Blatch',
|
||||
alt => 'The suspect',
|
||||
}]);
|
||||
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
ok(
|
||||
! exists $templateVars->{topStoryImageUrl}
|
||||
&& ! exists $templateVars->{topStoryImageByLine}
|
||||
&& ! exists $templateVars->{topStoryImageAlt}
|
||||
&& ! exists $templateVars->{topStoryImageCaption},
|
||||
'... no photo template variables, since there is no storage location'
|
||||
);
|
||||
my $bogsData = $storyHandler->{bogs}->getPhotoData();
|
||||
$bogsData->[0]->{storageId} = $storage->getId;
|
||||
$storyHandler->{bogs}->setPhotoData($bogsData);
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
ok(
|
||||
! exists $templateVars->{topStoryImageUrl}
|
||||
&& ! exists $templateVars->{topStoryImageByLine}
|
||||
&& ! exists $templateVars->{topStoryImageAlt}
|
||||
&& ! exists $templateVars->{topStoryImageCaption},
|
||||
'... no photo template variables, since there is no file in the storage location'
|
||||
);
|
||||
|
||||
$storage->addFileFromFilesystem(WebGUI::Test->getTestCollateralPath('gooey.jpg'));
|
||||
$templateVars = $topic->viewTemplateVariables();
|
||||
cmp_deeply(
|
||||
[ @{ $templateVars }{qw/topStoryImageUrl topStoryImageByline topStoryImageAlt topStoryImageCaption/} ],
|
||||
[
|
||||
$storage->getUrl('gooey.jpg'),
|
||||
'Elmo Blatch',
|
||||
'The suspect',
|
||||
"Octopus seen at the scene of Mrs. Dufresne's murder.",
|
||||
],
|
||||
'... photo template variables set'
|
||||
);
|
||||
|
||||
|
||||
$topic->update({
|
||||
storiesShort => 20,
|
||||
|
|
@ -191,9 +232,9 @@ cmp_deeply(
|
|||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
# $archive->purge if $archive;
|
||||
# $topic->purge if $topic;
|
||||
# if ($versionTag) {
|
||||
# $versionTag->rollback;
|
||||
# }
|
||||
$archive->purge if $archive;
|
||||
$topic->purge if $topic;
|
||||
if ($versionTag) {
|
||||
$versionTag->rollback;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue