From 02121fb7a972cd4f0f9cebf6c031c2da6bf7f1ae Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Wed, 11 Aug 2010 08:37:21 -0700 Subject: [PATCH] Fix problems with getting the default page. Fixes bug #11778. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Content/Asset.pm | 6 ++++-- t/Content/Asset.t | 40 +++++++++++++++++++++++-------------- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 9d66af361..111001b19 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -1,4 +1,5 @@ 7.9.12 + - webgui.org homepage gives 404 (#11778) 7.9.11 - fixed #11755: New cart does not update shipping methods correctly diff --git a/lib/WebGUI/Content/Asset.pm b/lib/WebGUI/Content/Asset.pm index d07005a79..dff7f50b5 100644 --- a/lib/WebGUI/Content/Asset.pm +++ b/lib/WebGUI/Content/Asset.pm @@ -64,7 +64,6 @@ The URL for this request. sub dispatch { my $session = shift; my $assetUrl = shift; - return undef unless $assetUrl; my $permutations = getUrlPermutations($assetUrl); foreach my $url (@{ $permutations }) { if (my $asset = getAsset($session, $url)) { @@ -139,14 +138,17 @@ The URL to permute. sub getUrlPermutations { my $url = shift; + ##Handle empty urls (sitename only) + return ['/'] if !$url + || $url eq '/'; my @permutations = (); - return \@permutations if !$url; if ($url =~ /\.\w+$/) { push @permutations, $url; $url =~ s/\.\w+$//; } my $uri = URI->new($url); my @fragments = $uri->path_segments(); + use Data::Dumper; FRAG: while (@fragments) { last FRAG if $fragments[-1] eq ''; push @permutations, join "/", @fragments; diff --git a/t/Content/Asset.t b/t/Content/Asset.t index aee6f1eba..c746df170 100644 --- a/t/Content/Asset.t +++ b/t/Content/Asset.t @@ -22,6 +22,8 @@ use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; use WebGUI::Content::Asset; +my $output; + #---------------------------------------------------------------------------- # Init my $session = WebGUI::Test->session; @@ -74,20 +76,26 @@ my $td url => 'testdispatch', } ); +diag $td->getId; WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) ); #---------------------------------------------------------------------------- # Tests -plan tests => 15; # Increment this number for each test you create +plan tests => 17; # Increment this number for each test you create #---------------------------------------------------------------------------- # test getUrlPermutation( url ) method cmp_deeply( WebGUI::Content::Asset::getUrlPermutations( ), - [ ], - "Handles no URL gracefully", + [ '/' ], + "No URL returns /", +); +cmp_deeply( + WebGUI::Content::Asset::getUrlPermutations( '/' ), + [ '/' ], + "URL with only slash is handled", ); cmp_deeply( WebGUI::Content::Asset::getUrlPermutations( "one" ), @@ -119,19 +127,13 @@ cmp_deeply( #---------------------------------------------------------------------------- # test dispatch( session, url ) method is ($session->asset, undef, 'session asset is not defined, yet'); -is( - WebGUI::Content::Asset::dispatch( $session, "testdispatch" ), - "www_view one", - "Regular www_view", -); +$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch" ); +is $output, "www_view one", "Regular www_view"; -is ($session->asset->getId, $td->getId, 'dispatch set the session asset'); +is $session->asset && $session->asset->getId, $td->getId, 'dispatch set the session asset'; -is( - WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ), - "bar", - "special /foo handler", -); +$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ); +is $output, "bar", "special /foo handler"; # Add an asset that clobbers the TestDispatch's /foo my $clobberingTime @@ -170,8 +172,16 @@ $session->request->setup_body({ func => "edit", }); -my $output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ); +$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ); isnt( $output, "you'll never see me!", "func=edit was declined" ); isnt( $output, "www_edit one", "func=edit was not for us" ); +# Test that empty URL returns the default page. +$session->request->setup_body({ }); +my $originalDefaultPage = $session->setting->get('defaultPage'); +$session->setting->set('defaultPage', $td->getId); +$output = WebGUI::Content::Asset::dispatch( $session ); +is $output, 'www_view one', 'an empty URL returns the default asset'; +$session->setting->set('defaultPage', $originalDefaultPage); + #vim:ft=perl