Don't call methods on the first story item when there are no story items.

Fixes #11747.
This commit is contained in:
Scott Walters 2010-07-27 19:16:00 -04:00
parent e033192328
commit ca5ca46557
2 changed files with 18 additions and 2 deletions

View file

@ -220,7 +220,7 @@ sub viewTemplateVariables {
push @{$var->{story_loop}}, $storyVars;
}
if ($self->{_standAlone}) {
if ($self->{_standAlone} and @$storyIds) {
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.

View file

@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 19;
plan tests => 20;
#----------------------------------------------------------------------------
# put your tests here
@ -357,3 +357,19 @@ cmp_deeply(
'viewTemplateVars has right number and contents in the story_loop in sort order Alphabetically mode'
);
################################################################
# Regression -- Empty StoryTopics shouldn't blow up
################################################################
my $emptyarchive = WebGUI::Asset->getDefault($session)->addChild({
className => 'WebGUI::Asset::Wobject::StoryTopic',
title => 'Why Do Good Things Happen To Bad People',
url => '/home/badstories',
keywords => 'aksjhgkja asgjhshs assajshhsg5',
});
addToCleanup($emptyarchive); # blows up under the debugger...?
$versionTag->commit;
$emptyarchive->{_standAlone} = 1;
ok(eval { $emptyarchive->viewTemplateVariables() }, "viewTemplateVariables with _standAlone = 1 doesn't throw an error");