From c8fe4092a28f76995048fee71dd1ae5c938387bd Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sat, 25 Apr 2009 00:16:27 +0000 Subject: [PATCH] Many more RssAspect tests. --- lib/WebGUI/AssetAspect/RssFeed.pm | 6 ++- t/AssetAspect/RssFeed.t | 80 +++++++++++++++++++++++++--- t/lib/WebGUI/Asset/RssAspectDummy.pm | 1 - 3 files changed, 78 insertions(+), 9 deletions(-) diff --git a/lib/WebGUI/AssetAspect/RssFeed.pm b/lib/WebGUI/AssetAspect/RssFeed.pm index 6a66329bd..718f38e58 100644 --- a/lib/WebGUI/AssetAspect/RssFeed.pm +++ b/lib/WebGUI/AssetAspect/RssFeed.pm @@ -207,7 +207,8 @@ sub exportAssetCollateral { # Get the parent dir's *path* (essentially the name of the dir) relative to # its own parent dir. $filenameBase = $basepath->parent->relative( $basepath->parent->parent )->stringify; - } else { + } + else { # Get the 1st ancestor, since the asset is a file recognized by apache, so # we want our files in the same dir. $filedir = $basepath->parent->absolute->stringify; @@ -429,7 +430,8 @@ sub getFeed { if (!$new_item->guid) { if ($new_item->link) { $new_item->guid( $new_item->link ); - } else { + } + else { $new_item->guid( $self->session->id->generate ); $set_permalink_false = 1; } diff --git a/t/AssetAspect/RssFeed.t b/t/AssetAspect/RssFeed.t index c35d2429c..d0c004b4b 100644 --- a/t/AssetAspect/RssFeed.t +++ b/t/AssetAspect/RssFeed.t @@ -18,6 +18,7 @@ use strict; use lib "$FindBin::Bin/../lib"; use Test::More; use Test::Deep; +use File::Path; use Data::Dumper; use WebGUI::Test; # Must use this before any other WebGUI modules @@ -30,11 +31,12 @@ use WebGUI::Asset::RssAspectDummy; # Init my $session = WebGUI::Test->session; +WebGUI::Test->originalConfig('exportPath'); #---------------------------------------------------------------------------- # Tests -plan tests => 18; # Increment this number for each test you create +plan tests => 21; # Increment this number for each test you create #---------------------------------------------------------------------------- # put your tests here @@ -92,11 +94,12 @@ is($newFeed, $feed, 'getFeed returns the same object'); cmp_deeply( $feed, methods( - title => 'Dummy Title', - description => 'Dummy Synopsis', ##Not description - link => '/home/shawshank', + title => 'Dummy Title', + description => 'Dummy Synopsis', ##Not description + link => '/home/shawshank', + copyright => '', ), - '... title, description, link inherit from asset by default' + '... title, description, link inherit from asset by default, copyright unset' ); cmp_bag( [ $feed->get_item() ], @@ -104,16 +107,81 @@ cmp_bag( methods( title => 'this title', description => 'this description', + 'link' => 'this link', + guid => 'this link', ), methods( title => 'another title', - description => 'another description', ##Not description + description => 'another description', ##Not description + guid => re('^[a-zA-Z0-9\-_]{22}'), ##GUID is a GUID since there's no link ), ], '... contains 2 feed items with the correct contents' ); +$dummy->update({ + feedCopyright => 'copyright 2009 Plain Black Corporation', + feedTitle => 'Rita Hayworth and the Shawshank Redemption', + feedDescription => 'A good movie, providing loads of testing collateral', +}); +$feed = $dummy->getFeed(XML::FeedPP::RSS->new()); + +cmp_deeply( + $feed, + methods( + title => 'Rita Hayworth and the Shawshank Redemption', + description => 'A good movie, providing loads of testing collateral', + link => '/home/shawshank', + copyright => 'copyright 2009 Plain Black Corporation', + ), + '... feed settings override asset defaults, copyright' +); + +##################################################### +# +# exportAssetCollateral +# +##################################################### + +my $exportStorage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($exportStorage); +my $basedir = Path::Class::Dir->new($exportStorage->getPath); +my $assetdir = $basedir->subdir('shawshank'); +my $indexfile = $assetdir->file('index.html'); +mkpath($assetdir->stringify); +$dummy->exportAssetCollateral($indexfile, {}, $session); + +cmp_bag( + $exportStorage->getFiles(), + [qw/ + shawshank.rss shawshank + shawshank.atom + /], + 'exportAssetCollateral: feed files exported, index.html file' +); + +$exportStorage = WebGUI::Storage->create($session); +WebGUI::Test->storagesToDelete($exportStorage); +$basedir = Path::Class::Dir->new($exportStorage->getPath); +my $assetfile = $basedir->file('shawshank.html'); +$dummy->exportAssetCollateral($assetfile, {}, $session); + +cmp_bag( + $exportStorage->getFiles(), + [qw/ + shawshank.html.rss + shawshank.html.atom + /], + 'exportAssetCollateral: feed files exported, shawshank.html file' +); + +##################################################### +# +# exportAssetCollateral +# +##################################################### + #---------------------------------------------------------------------------- # Cleanup END { diff --git a/t/lib/WebGUI/Asset/RssAspectDummy.pm b/t/lib/WebGUI/Asset/RssAspectDummy.pm index 6d7997d2c..dc685b211 100644 --- a/t/lib/WebGUI/Asset/RssAspectDummy.pm +++ b/t/lib/WebGUI/Asset/RssAspectDummy.pm @@ -62,7 +62,6 @@ return [ { title => 'another title', description => 'another description', - 'link' => 'another link', author => 'another author', date => 'another date', },