diff --git a/lib/WebGUI/Asset/Wobject/StoryArchive.pm b/lib/WebGUI/Asset/Wobject/StoryArchive.pm index ebd99a607..c538ab83e 100644 --- a/lib/WebGUI/Asset/Wobject/StoryArchive.pm +++ b/lib/WebGUI/Asset/Wobject/StoryArchive.pm @@ -210,6 +210,30 @@ sub getFolder { #------------------------------------------------------------------- +=head2 getRssFeedItems ( ) + +Returns an arrayref of hashrefs, containing information on stories +for generating an RSS and Atom feeds. + +=cut + +sub getRssFeedItems { + my $self = shift; + my $stories = $self->getLineageIterator(['descendants'],{ + excludeClasses => ['WebGUI::Asset::Wobject::Folder'], + orderByClause => 'creationDate desc, lineage', + returnObjects => 1, + limit => $self->get('itemsPerFeed'), + }); + my $storyData = []; + while (my $story = $stories->()) { + push @{ $storyData }, $story->getRssData; + } + return $storyData; +} + +#------------------------------------------------------------------- + =head2 folderDateFormat ( $epoch ) Returns the date in the format for folders. Encapsulated in this method diff --git a/t/Asset/Wobject/StoryArchive.t b/t/Asset/Wobject/StoryArchive.t index 332dc4c74..2523179ba 100644 --- a/t/Asset/Wobject/StoryArchive.t +++ b/t/Asset/Wobject/StoryArchive.t @@ -58,11 +58,11 @@ $canPostMaker->prepare({ fail => [1, $reader ], }); -my $tests = 1; -plan tests => 28 - + $tests - + $canPostMaker->plan - ; +my $tests = 31 + + $canPostMaker->plan + ; +plan tests => 1 + + $tests; #---------------------------------------------------------------------------- # put your tests here @@ -387,6 +387,45 @@ cmp_bag( 'keywordCloud template variable has keywords and correct links', ); +################################################################ +# +# RSS and Atom checks +# +################################################################ + +is($archive->getRssFeedUrl, '/home/mystories?func=viewRss', 'RSS Feed Url'); +is($archive->getAtomFeedUrl, '/home/mystories?func=viewAtom', 'Atom Feed Url'); + +$archive->update({itemsPerFeed => 3}); + +cmp_deeply( + $archive->getRssFeedItems(), + [ + { + title => 'First Story', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + { + title => 'Story 2', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + { + title => 'Story 3', + description => ignore(), + 'link' => ignore(), + date => ignore(), + author => ignore(), + }, + ], + 'rssFeedItems' +); + } #----------------------------------------------------------------------------