Fix problems with getting the default page. Fixes bug #11778.
This commit is contained in:
parent
e55e7d21f0
commit
02121fb7a9
3 changed files with 30 additions and 17 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
7.9.12
|
7.9.12
|
||||||
|
- webgui.org homepage gives 404 (#11778)
|
||||||
|
|
||||||
7.9.11
|
7.9.11
|
||||||
- fixed #11755: New cart does not update shipping methods correctly
|
- fixed #11755: New cart does not update shipping methods correctly
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ The URL for this request.
|
||||||
sub dispatch {
|
sub dispatch {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
my $assetUrl = shift;
|
my $assetUrl = shift;
|
||||||
return undef unless $assetUrl;
|
|
||||||
my $permutations = getUrlPermutations($assetUrl);
|
my $permutations = getUrlPermutations($assetUrl);
|
||||||
foreach my $url (@{ $permutations }) {
|
foreach my $url (@{ $permutations }) {
|
||||||
if (my $asset = getAsset($session, $url)) {
|
if (my $asset = getAsset($session, $url)) {
|
||||||
|
|
@ -139,14 +138,17 @@ The URL to permute.
|
||||||
|
|
||||||
sub getUrlPermutations {
|
sub getUrlPermutations {
|
||||||
my $url = shift;
|
my $url = shift;
|
||||||
|
##Handle empty urls (sitename only)
|
||||||
|
return ['/'] if !$url
|
||||||
|
|| $url eq '/';
|
||||||
my @permutations = ();
|
my @permutations = ();
|
||||||
return \@permutations if !$url;
|
|
||||||
if ($url =~ /\.\w+$/) {
|
if ($url =~ /\.\w+$/) {
|
||||||
push @permutations, $url;
|
push @permutations, $url;
|
||||||
$url =~ s/\.\w+$//;
|
$url =~ s/\.\w+$//;
|
||||||
}
|
}
|
||||||
my $uri = URI->new($url);
|
my $uri = URI->new($url);
|
||||||
my @fragments = $uri->path_segments();
|
my @fragments = $uri->path_segments();
|
||||||
|
use Data::Dumper;
|
||||||
FRAG: while (@fragments) {
|
FRAG: while (@fragments) {
|
||||||
last FRAG if $fragments[-1] eq '';
|
last FRAG if $fragments[-1] eq '';
|
||||||
push @permutations, join "/", @fragments;
|
push @permutations, join "/", @fragments;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,8 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Content::Asset;
|
use WebGUI::Content::Asset;
|
||||||
|
|
||||||
|
my $output;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Init
|
# Init
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
@ -74,20 +76,26 @@ my $td
|
||||||
url => 'testdispatch',
|
url => 'testdispatch',
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
diag $td->getId;
|
||||||
WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
|
WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# 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
|
# test getUrlPermutation( url ) method
|
||||||
|
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( ),
|
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(
|
cmp_deeply(
|
||||||
WebGUI::Content::Asset::getUrlPermutations( "one" ),
|
WebGUI::Content::Asset::getUrlPermutations( "one" ),
|
||||||
|
|
@ -119,19 +127,13 @@ cmp_deeply(
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# test dispatch( session, url ) method
|
# test dispatch( session, url ) method
|
||||||
is ($session->asset, undef, 'session asset is not defined, yet');
|
is ($session->asset, undef, 'session asset is not defined, yet');
|
||||||
is(
|
$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch" );
|
||||||
WebGUI::Content::Asset::dispatch( $session, "testdispatch" ),
|
is $output, "www_view one", "Regular www_view";
|
||||||
"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(
|
$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" );
|
||||||
WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ),
|
is $output, "bar", "special /foo handler";
|
||||||
"bar",
|
|
||||||
"special /foo handler",
|
|
||||||
);
|
|
||||||
|
|
||||||
# Add an asset that clobbers the TestDispatch's /foo
|
# Add an asset that clobbers the TestDispatch's /foo
|
||||||
my $clobberingTime
|
my $clobberingTime
|
||||||
|
|
@ -170,8 +172,16 @@ $session->request->setup_body({
|
||||||
func => "edit",
|
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, "you'll never see me!", "func=edit was declined" );
|
||||||
isnt( $output, "www_edit one", "func=edit was not for us" );
|
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
|
#vim:ft=perl
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue