getUrlPermutations, and a stub for Content::Asset::dispatch so the test doesn't die.

This commit is contained in:
Colin Kuskie 2010-07-28 15:47:00 -07:00
parent 32a75ebe38
commit 35284c0753
2 changed files with 56 additions and 5 deletions

View file

@ -19,6 +19,7 @@ use LWP::MediaTypes qw(guess_media_type);
use Time::HiRes;
use WebGUI::Asset;
use WebGUI::PassiveAnalytics::Logging;
use URI;
use Apache2::Const -compile => qw(OK);
@ -43,6 +44,20 @@ These subroutines are available from this package:
#-------------------------------------------------------------------
=head2 dispatch ( $session, $assetUrl )
Returns the output from an asset.
=cut
sub dispatch {
my $session = shift;
my $assetUrl = shift;
return;
}
#-------------------------------------------------------------------
=head2 getAsset ( session [, assetUrl ] )
Returns an asset based upon the requested asset URL, or optionally pass one in.
@ -75,6 +90,37 @@ sub getRequestedAssetUrl {
#-------------------------------------------------------------------
=head2 getUrlPermutations ( $url )
Returns an array reference of permutations for the URL.
=head3 $url
The URL to permute.
=cut
sub getUrlPermutations {
my $url = shift;
my @permutations = ();
return \@permutations if !$url;
push @permutations, $url;
if ($url =~ /\.\w+$/) {
$url =~ s/\.\w+$//;
push @permutations, $url;
}
my $uri = URI->new($url);
my @fragments = $uri->path_segments();
pop @fragments;
while (@fragments > 1) {
push @permutations, join "/", @fragments;
pop @fragments;
}
return \@permutations;
}
#-------------------------------------------------------------------
=head2 handler ( session )
The content handler for this package.

View file

@ -20,6 +20,7 @@ use Test::More;
use Test::Deep;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Content::Asset;
#----------------------------------------------------------------------------
# Init
@ -78,7 +79,7 @@ WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
#----------------------------------------------------------------------------
# Tests
plan tests => 11; # Increment this number for each test you create
plan tests => 12; # Increment this number for each test you create
#----------------------------------------------------------------------------
# test getUrlPermutation( url ) method
@ -89,19 +90,23 @@ cmp_deeply(
"Handles no URL gracefully",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutation( "one" ),
WebGUI::Content::Asset::getUrlPermutations( "one" ),
[ 'one' ],
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutation( "/one" ),
WebGUI::Content::Asset::getUrlPermutations( "/one" ),
[ '/one', ],
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutation( "/one/two/three" ),
WebGUI::Content::Asset::getUrlPermutations( "one/two/three" ),
[ 'one/two/three', 'one/two', 'one', ],
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three" ),
[ '/one/two/three', '/one/two', '/one', ],
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutation( "/one/two/three.rss" ),
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three.rss" ),
[ '/one/two/three.rss', '/one/two/three', '/one/two', '/one', ],
".ext is a seperate URL permutation",
);