Ready for 7.10.29 development.

This commit is contained in:
Colin Kuskie 2013-03-20 21:38:23 -07:00
commit c806f99b7b
4236 changed files with 1217679 additions and 0 deletions

237
t/Content/Asset.t Normal file
View file

@ -0,0 +1,237 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use Test::MockObject::Extends;
use Test::Deep;
use Data::Dumper;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Content::Asset;
use Encode;
my $output;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
BEGIN {
$INC{'WebGUI/Asset/TestDispatch.pm'} = __FILE__;
$INC{'WebGUI/Asset/TestDecline.pm'} = __FILE__;
}
package WebGUI::Asset::TestDispatch;
our @ISA = ('WebGUI::Asset');
# Override dispatch to handle special /foo URL
sub dispatch {
my ( $self, $fragment ) = @_;
if ( $fragment eq '/foo' ) {
return "bar";
}
return $self->SUPER::dispatch( $fragment );
}
sub www_edit {
my ( $self ) = @_;
return "www_edit " . $self->get('title');
}
sub www_view {
my ( $self ) = @_;
return "www_view " . $self->get('title');
}
package WebGUI::Asset::TestDecline;
our @ISA = ( 'WebGUI::Asset' );
# Override dispatch to decline everything
sub dispatch { return; }
sub www_edit { return "you'll never see me!" }
package main;
my $td
= WebGUI::Asset->getImportNode( $session )->addChild( {
title => "one",
className => 'WebGUI::Asset::TestDispatch',
url => 'testdispatch',
} );
my $utf8_url = "Viel-spa\x{00DF}";
utf8::upgrade $utf8_url;
my $utf8
= WebGUI::Asset->getImportNode( $session )->addChild( {
title => "utf8",
className => 'WebGUI::Asset::TestDispatch',
url => $utf8_url,
} );
WebGUI::Test->addToCleanup( WebGUI::VersionTag->getWorking( $session ) );
#----------------------------------------------------------------------------
# Tests
plan tests => 25; # Increment this number for each test you create
#----------------------------------------------------------------------------
# test getUrlPermutation( url ) method
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( ),
[ '/' ],
"No URL returns /",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( '/' ),
[ '/' ],
"URL with only slash is handled",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "one" ),
[ 'one' ],
"simple one element URL",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "/one" ),
[ '/one', ],
"simple one element URL with leading slash",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "one/two/three" ),
[ 'one/two/three', 'one/two', 'one', ],
"three element URL",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three" ),
[ '/one/two/three', '/one/two', '/one', ],
"three element URL with leading slash",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three.rss" ),
[ '/one/two/three.rss', '/one/two/three', '/one/two', '/one', ],
".ext is a seperate URL permutation",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( $utf8_url ),
[ $utf8_url ],
"UTF-8 handling for URLs",
);
cmp_deeply(
WebGUI::Content::Asset::getUrlPermutations( "/one/two/three/" ),
[ '/one/two/three', '/one/two', '/one', ],
"trailing slashes are ignored",
);
#----------------------------------------------------------------------------
# test dispatch( session, url ) method
is ($session->asset, undef, 'session asset is not defined, yet');
$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch" );
is $output, "www_view one", "Regular www_view";
is $session->asset && $session->asset->getId, $td->getId, 'dispatch set the session asset';
$output = WebGUI::Content::Asset::dispatch( $session, "testdispatch/" );
is $output, "www_view one", "trailing slashes are ignored";
my $_asset = WebGUI::Asset->newByUrl($session, $utf8_url);
isa_ok $_asset, 'WebGUI::Asset::TestDispatch';
$output = WebGUI::Content::Asset::dispatch( $session, $utf8_url );
is $output, "www_view utf8", "dispatch for utf8 urls";
$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
= WebGUI::Asset->getImportNode( $session )->addChild( {
title => "two",
className => 'WebGUI::Asset::TestDispatch',
url => $td->get('url') . '/foo',
} );
WebGUI::Test->addToCleanup($clobberingTime);
is(
WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ),
"www_view two",
"dispatch to the asset with the longest URL",
);
is ($session->asset->getId, $clobberingTime->getId, 'dispatch reset the session asset');
$clobberingTime->purge;
# Add an asset that declines everything instead
my $declined
= WebGUI::Asset->getImportNode( $session )->addChild( {
title => "three",
className => 'WebGUI::Asset::TestDecline',
url => $td->get('url') . '/foo',
} );
is(
WebGUI::Content::Asset::dispatch( $session, "testdispatch/foo" ),
"bar",
"Dispatch passes to TestDispatch asset after declined",
);
# Test ?func= dispatch with declined asset
$session->request->setup_body({
func => "edit",
});
$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);
# Test that requesting a URL that doesn't exist, but one of the permutations does exist, returns undef
$session->request->setup_body({ });
my $nonexistant_url = WebGUI::Asset->getDefault($session)->get('url');
$nonexistant_url = join '/', $nonexistant_url, 'nothing_here_to_see';
$output = WebGUI::Content::Asset::dispatch( $session, $nonexistant_url );
is $output, undef, 'getting a URL which does not exist returns undef';
is $session->asset, undef, '... session asset is not set';
use WebGUI::Asset::RssAspectDummy;
my $dummy = WebGUI::Asset->getImportNode($session)->addChild({
className => 'WebGUI::Asset::RssAspectDummy',
url => '/home/shawshank',
title => 'Dummy Title',
synopsis => 'Dummy Synopsis',
description => 'Dummy Description',
});
WebGUI::Test->addToCleanup($dummy);
$output = WebGUI::Content::Asset::dispatch( $session, '/home/shawshank/no-child-here' );
is $output, undef, 'RSS Aspect propagates the fragment';
#vim:ft=perl

34
t/Content/Maintenance.t Normal file
View file

@ -0,0 +1,34 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Content::Maintenance;
# load your modules here
use Test::More tests => 3; # increment this value for each test you create
my $session = WebGUI::Test->session;
# put your tests here
$session->{_request} = undef;
$session->setting->set("specialState", "upgrading");
isnt(WebGUI::Content::Maintenance::handler($session), undef, "Maintenance should return some output when in upgrade special state");
$session->setting->set("specialState", "degrading");
is(WebGUI::Content::Maintenance::handler($session), undef, "Maintenance returns undef if specialState is not 'upgrading'");
$session->setting->remove("specialState");
is(WebGUI::Content::Maintenance::handler($session), undef, "Maintenance shouldn't return anything when no special state is present");

55
t/Content/SetLanguage.t Normal file
View file

@ -0,0 +1,55 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Content::SetLanguage;
# load your modules here
use Test::More tests => 5; # increment this value for each test you create
my $session = WebGUI::Test->session;
# put your tests here
my $formvariables = {
'op' =>'setLanguage',
'language' => 'English'
};
#test 1
$session->request->setup_body($formvariables);
WebGUI::Content::SetLanguage::handler($session);
is($session->scratch->getLanguageOverride, 'English', 'the language was not set');
#test2
$formvariables->{'language'} = 'delete';
$session->request->setup_body($formvariables);
WebGUI::Content::SetLanguage::handler($session);
is($session->scratch->getLanguageOverride, undef, 'language delete should remove the scratch variable');
#test3
$formvariables->{'op'} = 'SetLanguage';
$formvariables->{'language'} = 'English';
$session->request->setup_body($formvariables);
WebGUI::Content::SetLanguage::handler($session);
is($session->scratch->getLanguageOverride, undef, 'Naming the method wrongly should not change anything');
#test4
$formvariables->{'op'} = 'setLanguage';
$formvariables->{'language'} = 'MyImaginaryLanguageThatIsNotInstalled';
$session->request->setup_body($formvariables);
WebGUI::Content::SetLanguage::handler($session);
is($session->scratch->getLanguageOverride, undef, 'Giving a non installed language should not change anything');
#test5
$formvariables->{'language'} = undef;
$session->request->setup_body($formvariables);
WebGUI::Content::SetLanguage::handler($session);
is($session->scratch->getLanguageOverride, undef, 'Passing an empty language variable should return undef');

76
t/Content/Setup.t Normal file
View file

@ -0,0 +1,76 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Content::Setup;
# load your modules here
use Test::More tests => 10; # increment this value for each test you create
my $session = WebGUI::Test->session;
# put your tests here
$session->setting->set("specialState", "init");
isnt(WebGUI::Content::Setup::handler($session), undef, "Setup should return some output when in init special state");
$session->setting->remove("specialState");
is(WebGUI::Content::Setup::handler($session), undef, "Setup shouldn't return anything when no special state is present");
$session->request->setup_body({
wizard_class => 'WebGUI::Wizard::Setup',
wizard_step => 'adminAccount',
timeZone => 'America/New_York',
language => 'Spanish',
});
$session->setting->set("specialState", "init");
WebGUI::Content::Setup::handler($session);
my $admin = WebGUI::User->new($session, '3');
is($admin->get('language'), 'Spanish', 'Admin language set to Spanish');
is($admin->get('timeZone'), 'America/New_York', 'Admin timezone set to America/New_York');
my $visitor = WebGUI::User->new($session, '1');
is($visitor->get('language'), 'Spanish', 'Visitor language set to Spanish');
is($visitor->get('timeZone'), 'America/New_York', 'Visitor timezone set to America/New_York');
my $zoneField = WebGUI::ProfileField->new($session, 'timeZone');
is $zoneField->get('dataDefault'), 'America/New_York', 'timezone profile field default set to America/New_York';
my $languageField = WebGUI::ProfileField->new($session, 'language');
is $languageField->get('dataDefault'), 'Spanish', 'timezone profile field default set to Spanish';
$admin->update( { language => 'English' } );
$visitor->update({ language => 'English' } );
$admin->update( { timeZone => 'America/Chicago' } );
$visitor->update({ timeZone => 'America/Chicago' } );
my $properties;
$properties = $zoneField->get();
$properties->{dataDefault} = 'America/Chicago';
$zoneField->set($properties);
$properties = $languageField->get();
$properties->{dataDefault} = 'English';
$languageField->set($properties);
$session->setting->remove("specialState");
my $u1 = WebGUI::User->new($session, '1');
is $u1->get('language'), 'English', 'returned Visitor to English';
my $u3 = WebGUI::User->new($session, '3');
is $u3->get('language'), 'English', 'returned Admin to English';

81
t/Content/SiteIndex.t Normal file
View file

@ -0,0 +1,81 @@
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use WebGUI::Test;
use WebGUI::Session;
use WebGUI::Content::SiteIndex;
# load your modules here
use Test::More tests => 5; # increment this value for each test you create
use Test::Deep;
use XML::Simple;
my $session = WebGUI::Test->session;
# put your tests here
my $output = WebGUI::Content::SiteIndex::handler($session);
is $output, undef, 'no content returned unless sitemap.xml is requested';
$session->request->uri('/sitemap.xml');
$output = WebGUI::Content::SiteIndex::handler($session);
my $xmlData = XMLin($output,
KeepRoot => 1,
ForceArray => ['url'],
);
my @actual_urls = map { $_->{loc} } @{ $xmlData->{urlset}->{url} };
my @expected_urls = map { $session->url->getSiteURL . '/' . $_ } qw{ home getting_started your_next_step documentation join_us site_map };
cmp_deeply(
\@actual_urls,
\@expected_urls,
'correct set of urls'
);
my $hiddenPage = WebGUI::Asset->getDefault($session)->addChild({
className => 'WebGUI::Asset::Wobject::Layout',
isHidden => 1,
title => 'seekrit hidden page',
url => 'hidden_page',
});
my $versionTag = WebGUI::VersionTag->getWorking($session);
$versionTag->commit;
addToCleanup($versionTag);
$output = WebGUI::Content::SiteIndex::handler($session);
$xmlData = XMLin($output,
KeepRoot => 1,
ForceArray => ['url'],
);
cmp_deeply(
\@actual_urls,
\@expected_urls,
'hidden pages hidden'
);
$session->config->set('siteIndex', { showHiddenPages => 1} );
is $session->config->get('siteIndex')->{showHiddenPages}, 1, 'showHiddenPages set to true';
$output = WebGUI::Content::SiteIndex::handler($session);
$xmlData = XMLin($output,
KeepRoot => 1,
ForceArray => ['url'],
);
@actual_urls = map { $_->{loc} } @{ $xmlData->{urlset}->{url} };
@expected_urls = map { $session->url->getSiteURL . '/' . $_ } qw{ home getting_started your_next_step documentation join_us site_map hidden_page };
cmp_deeply(
\@actual_urls,
\@expected_urls,
'hidden pages shown'
);

54
t/Content/Wizard.t Normal file
View file

@ -0,0 +1,54 @@
# vim:syntax=perl
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2009 Plain Black Corporation.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Make sure the Wizard content handler does its job correctly
#
#
use FindBin;
use strict;
use lib "$FindBin::Bin/../lib";
use Test::More;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
#----------------------------------------------------------------------------
# Init
my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 3; # Increment this number for each test you create
#----------------------------------------------------------------------------
#
use_ok( 'WebGUI::Content::Wizard' );
ok( !WebGUI::Content::Wizard::handler( $session ), "Declines correctly" );
$session->request->setup_body( {
op => 'wizard',
wizard_class => 'WebGUI::Wizard::HelloWorld',
} );
is( WebGUI::Content::Wizard::handler( $session ), "Hello World!\n", "Accepts request and returns response" );
package WebGUI::Wizard::HelloWorld;
use base "WebGUI::Wizard";
sub _get_steps { return ["hello"] }
sub www_hello { return "Hello World!\n" }
sub wrapStyle { return $_[1] }
#vim:ft=perl