diff --git a/lib/WebGUI/Asset/Wobject/StoryTopic.pm b/lib/WebGUI/Asset/Wobject/StoryTopic.pm index 7706ef506..f61ba6487 100644 --- a/lib/WebGUI/Asset/Wobject/StoryTopic.pm +++ b/lib/WebGUI/Asset/Wobject/StoryTopic.pm @@ -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. diff --git a/t/Asset/Wobject/StoryTopic.t b/t/Asset/Wobject/StoryTopic.t index f1fd0936a..564e326f4 100644 --- a/t/Asset/Wobject/StoryTopic.t +++ b/t/Asset/Wobject/StoryTopic.t @@ -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"); +