From c4394537840aa86f25bdc9f3523c7eed013a6e3a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 16 Apr 2009 21:19:17 +0000 Subject: [PATCH] Make rssUrl and atomUrl variables respond to exportMode. --- lib/WebGUI/Asset/Wobject/StoryArchive.pm | 9 +++--- lib/WebGUI/Asset/Wobject/StoryTopic.pm | 7 ++-- t/Asset/Wobject/StoryArchive.t | 41 +++++++++++++++++------- t/Asset/Wobject/StoryTopic.t | 20 +++++++++++- 4 files changed, 57 insertions(+), 20 deletions(-) diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index 4129e17f6..89c0c25c2 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -388,12 +388,13 @@ sub viewTemplateVariables { $var->{addStoryUrl} = $var->{canPostStories} ? $self->getUrl('func=add;class=WebGUI::Asset::Story') : ''; - $var->{rssUrl} = $self->getUrl('func=viewRss'); - $var->{atomUrl} = $self->getUrl('func=viewAtom'); - $var->{keywordCloud} = WebGUI::Keyword->new($session)->generateCloud({ + $var->{rssUrl} = $self->{_exportMode} ? $self->getStaticRssFeedUrl : $self->getRssFeedUrl; + $var->{atomUrl} = $self->{_exportMode} ? $self->getStaticAtomFeedUrl : $self->getAtomFeedUrl; + my $cloudOptions = { startAsset => $self, displayFunc => 'view', - }); + }; + $var->{keywordCloud} = WebGUI::Keyword->new($session)->generateCloud($cloudOptions); if (! $self->{_exportMode}) { my $i18n = WebGUI::International->new($session, 'Asset'); $var->{searchHeader} = WebGUI::Form::formHeader($session, { action => $self->getUrl }) diff --git a/lib/WebGUI/Asset/Wobject/StoryTopic.pm b/lib/WebGUI/Asset/Wobject/StoryTopic.pm index fd62de90e..4d84d0438 100644 --- a/lib/WebGUI/Asset/Wobject/StoryTopic.pm +++ b/lib/WebGUI/Asset/Wobject/StoryTopic.pm @@ -17,7 +17,8 @@ use Tie::IxHash; use WebGUI::International; use WebGUI::Utility; use WebGUI::Asset::Story; -use base 'WebGUI::Asset::Wobject'; +use Class::C3; +use base qw/WebGUI::AssetAspect::RssFeed WebGUI::Asset::Wobject/; use constant DATE_FORMAT => '%c_%D_%y'; @@ -201,8 +202,8 @@ sub viewTemplateVariables { } } $var->{standAlone} = $self->{_standAlone}; - $var->{rssUrl} = $self->getUrl('func=viewRss'); - $var->{atomUrl} = $self->getUrl('func=viewAtom'); + $var->{rssUrl} = $self->{_exportMode} ? $self->getStaticRssFeedUrl : $self->getRssFeedUrl; + $var->{atomUrl} = $self->{_exportMode} ? $self->getStaticAtomFeedUrl : $self->getAtomFeedUrl; return $var; } diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index aa14a53a6..ee1237ad1 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -58,7 +58,7 @@ $canPostMaker->prepare({ fail => [1, $reader ], }); -my $tests = 33 +my $tests = 35 + $canPostMaker->plan ; plan tests => 1 @@ -195,6 +195,15 @@ cmp_deeply( 'viewTemplateVars: search variables present' ); +cmp_deeply( + $templateVars, + superhashof({ + rssUrl => $archive->getRssFeedUrl, + atomUrl => $archive->getAtomFeedUrl, + }), + 'viewTemplateVars: RSS and Atom feed template variables' +); + KEY: foreach my $key (keys %{ $templateVars }) { next KEY if isIn($key, qw/canPostStories addStoryUrl date_loop mode/); delete $templateVars->{$key}; @@ -380,6 +389,25 @@ cmp_bag( 'viewTemplateVariables: search mode returns the correct assets in the same form as view mode' ); +$archive->{_exportMode} = 1; +$templateVars = $archive->viewTemplateVariables(); +ok( ( !exists $templateVars->{searchHeader} + && !exists $templateVars->{searchForm} + && !exists $templateVars->{searchButton} + && !exists $templateVars->{searchForm} + ), + '... export mode, no search variables present' +); + +cmp_deeply( + $templateVars, + superhashof({ + rssUrl => $archive->getStaticRssFeedUrl, + atomUrl => $archive->getStaticAtomFeedUrl, + }), + '... export mode, RSS and Atom feed template variables show the static url' +); +$archive->{_exportMode} = 0; ################################################################ # @@ -399,17 +427,6 @@ cmp_bag( 'keywordCloud template variable has keywords and correct links', ); -$archive->{_exportMode} = 1; -$templateVars = $archive->viewTemplateVariables(); -ok( ( !exists $templateVars->{searchHeader} - && !exists $templateVars->{searchForm} - && !exists $templateVars->{searchButton} - && !exists $templateVars->{searchForm} - ), - '... export mode, no search variables present' -); -$archive->{_exportMode} = 0; - ################################################################ # # RSS and Atom checks diff --git a/t/Asset/Wobject/StoryTopic.t b/t/Asset/Wobject/StoryTopic.t index 4a868a84f..ec4b4887c 100644 --- a/t/Asset/Wobject/StoryTopic.t +++ b/t/Asset/Wobject/StoryTopic.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 15; +my $tests = 17; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -94,6 +94,15 @@ $versionTag->commit; my $templateVars; $templateVars = $topic->viewTemplateVariables(); + +cmp_deeply( + $templateVars, + superhashof({ + rssUrl => $topic->getRssFeedUrl, + atomUrl => $topic->getAtomFeedUrl, + }), + 'viewTemplateVars: RSS and Atom feed template variables' +); cmp_deeply( $templateVars->{story_loop}, [ @@ -254,6 +263,15 @@ cmp_deeply( ], '... export mode, URLs are the regular story URLs' ); +cmp_deeply( + $templateVars, + superhashof({ + rssUrl => $topic->getStaticRssFeedUrl, + atomUrl => $topic->getStaticAtomFeedUrl, + }), + '... export mode, RSS and Atom feed template variables show the static url' +); +$topic->{_exportMode} = 0; }