Skip to content

Commit

Permalink
Item13897: Tests up to and including ExtensionInstallerTests
Browse files Browse the repository at this point in the history
- EngineTests is skipped because the engines role in the core has changed.
  • Loading branch information
vrurg committed May 30, 2016
1 parent 29b0874 commit c8a6fae
Show file tree
Hide file tree
Showing 17 changed files with 189 additions and 150 deletions.
3 changes: 2 additions & 1 deletion RCSStoreContrib/lib/Foswiki/Store/Rcs/Store.pm
Expand Up @@ -554,7 +554,8 @@ sub recordChange {
# Support for Foswiki < 2
my $topic = '.';
if ( $web =~ /\./ ) {
( $web, $topic ) = Foswiki->normalizeWebTopicName( undef, $web );
( $web, $topic ) =
$this->app->request->normalizeWebTopicName( undef, $web );
}

my $handler = $this->getHandler($web);
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/AccessControlTests.pm
Expand Up @@ -891,7 +891,7 @@ THIS
requestParams => {
initializer => {
webName => [ $this->test_web ],
topicName => ["$test_topic"],
topicName => [$test_topic],
},
},
engineParams => {
Expand Down
15 changes: 9 additions & 6 deletions UnitTestContrib/test/unit/ConfigureSaveTests.pm
Expand Up @@ -18,8 +18,10 @@ extends qw( ConfigureTestCase );

# TODO: this needs to test that backups are correctly made
sub test_changecfg {
my $this = shift;

my $cfg = $this->app->cfg;

my $this = shift;
my $params = {
set => {

Expand All @@ -43,9 +45,10 @@ sub test_changecfg {
}
};

Foswiki::Configure::Load::readConfig( 0, 0 );
$cfg->readConfig( 0, 0 );

my $wizard = Foswiki::Configure::Wizards::Save->new($params);
my $wizard =
Foswiki::Configure::Wizards::Save->new( param_source => $params );
my $reporter = Foswiki::Configure::Reporter->new();
$wizard->save($reporter);

Expand Down Expand Up @@ -125,11 +128,11 @@ q<| {UnitTestContrib}{Configure}{REGEX} | ('^regex$') | '(black&#124;white)+' |>
$c = Foswiki::Sandbox::untaintUnchecked($c);
my %blah;
eval $c;
%Foswiki::cfg = (); #{ConfigurationFinished} = 0;
Foswiki::Configure::Load::readConfig( 1, 1 );
$cfg->clear_data; #{ConfigurationFinished} = 0;
$cfg->readConfig( 1, 1 );

#print STDERR Data::Dumper->Dump([\%Foswiki::cfg]);
delete $Foswiki::cfg{ConfigurationFinished};
delete $cfg->data->{ConfigurationFinished};

$this->assert_null( $blah{TempfileDir} );
$this->assert_num_equals( 99, $blah{UnitTestContrib}{Configure}{NUMBER} );
Expand Down
12 changes: 6 additions & 6 deletions UnitTestContrib/test/unit/DependencyTests.pm
Expand Up @@ -17,7 +17,7 @@ sub test_check_dep_not_perl {

# Check an external dependency
# 0, Module is type external, and cannot be automatically checked.
my $dep = new Foswiki::Configure::Dependency(
my $dep = Foswiki::Configure::Dependency->new(
type => "external",
module => "libpcap",
version => "1.0.0"
Expand All @@ -32,7 +32,7 @@ sub test_check_dep_last_resort1 {

# Check a module that won't load, so that the
# last resort "code scraping" is used to recover version.
my $dep = new Foswiki::Configure::Dependency(
my $dep = Foswiki::Configure::Dependency->new(
type => "perl",
module => "Foswiki::Contrib::UnitTestContrib::LastResortWontLoad",
);
Expand All @@ -49,7 +49,7 @@ sub test_check_dep_not_module {

# Check a non-existing module
# 0,
my $dep = new Foswiki::Configure::Dependency(
my $dep = Foswiki::Configure::Dependency->new(
type => "perl",
module => "Non::Existing::Module"
);
Expand All @@ -65,7 +65,7 @@ qr/Non::Existing::Module version >=0 required\s*--\s*perl module is not installe
sub test_check_foswiki_rev {
my ($this) = @_;

my $dep = new Foswiki::Configure::Dependency(
my $dep = Foswiki::Configure::Dependency->new(
type => 'perl',
module => 'Foswiki',
version => '1.1.3'
Expand All @@ -83,7 +83,7 @@ sub test_check_dep_carp {
# Check a normally installed dependency
# 1, Carp v1.03 installed
my $dep =
new Foswiki::Configure::Dependency( type => "cpan", module => "Carp" );
Foswiki::Configure::Dependency->new( type => "cpan", module => "Carp" );
my ( $ok, $message ) = $dep->checkDependency();
$this->assert_equals( 1, $ok );
$this->assert_matches( qr/Carp version .* installed/, $message );
Expand All @@ -95,7 +95,7 @@ sub test_check_dep_carp_with_version {

# Check a normally installed dependency
# 1, Carp v1.03 installed
my $dep = new Foswiki::Configure::Dependency(
my $dep = Foswiki::Configure::Dependency->new(
type => "cpan",
module => "Carp",
version => 0.1
Expand Down
29 changes: 14 additions & 15 deletions UnitTestContrib/test/unit/EmptyTests.pm
Expand Up @@ -18,22 +18,25 @@ around set_up => sub {

# You can now safely modify $Foswiki::cfg

my $topicquery = Unit::Request->new( initializer => '' );
$topicquery->path_info('/TestCases/WebHome');
try {
$this->createNewFoswikiSession( 'AdminUser' || '' );
my $user = $this->session->user;
$this->createNewFoswikiApp(
requestParams => { initializer => '', },
engineParams =>
{ initialAttributes => { path_info => '/TestCases/WebHome', }, },
user => 'AdminUser',
);
my $user = $this->app->user;

# You can create webs here; don't forget to tear them down

# Create a web like this:
my $webObject =
$this->populateNewWeb( "Temporarytestweb1", "_default" );
$webObject->finish();
undef $webObject;

# Copy a system web like this:
$webObject = $this->populateNewWeb( "Temporarysystemweb", "System" );
$webObject->finish();
undef $webObject;

# Create a topic like this:

Expand All @@ -42,15 +45,11 @@ around set_up => sub {

}
catch {
my $e = $_;
if ( $e->isa('Foswiki::AccessControlException') ) {
$this->assert( 0, $e->stringify() );
}
elsif ( $e->isa('Error::Simple') ) {
$this->assert( 0, $e->stringify() || '' );
if ( $_->isa('Foswiki::AccessControlException') ) {
$this->assert( 0, $_->stringify() );
}
else {
$e->throw;
Foswiki::Exception::Fatal->rethrow($_);
}
};

Expand All @@ -63,8 +62,8 @@ around tear_down => sub {

# Remove fixture webs; warning, if one of these
# dies, you may end up with spurious test webs
$this->removeWebFixture( $this->session, "Temporarytestweb1" );
$this->removeWebFixture( $this->session, "Temporarysystemweb" );
$this->removeWebFixture("Temporarytestweb1");
$this->removeWebFixture("Temporarysystemweb");

# Always do this, and always do it last
$orig->($this);
Expand Down
5 changes: 5 additions & 0 deletions UnitTestContrib/test/unit/EngineTests.pm
Expand Up @@ -24,6 +24,11 @@ BEGIN {
}
}

sub skip {
return
"Foswiki engines has changed too drastically for this suite to make any sense. Shall be replaced with Plack::Test perhaps.";
}

#use Storable qw(freeze thaw); # unreliable
sub freeze {
return Data::Dumper->Dump( [ $_[0] ] );
Expand Down
115 changes: 62 additions & 53 deletions UnitTestContrib/test/unit/ExceptionTests.pm
Expand Up @@ -9,35 +9,23 @@ use Moo;
use namespace::clean;
extends qw( FoswikiFnTestCase );

my $UI_FN;

around set_up => sub {
my $orig = shift;
my $this = shift;
$orig->( $this, @_ );
$UI_FN ||= $this->getUIFn('oops');

return;
};

# Check an OopsException with one non-array parameter
sub test_simpleOopsException {
my $this = shift;
try {
Foswiki::OopsException->throw(
'templatename',
web => 'webname',
topic => 'topicname',
def => 'defname',
keep => 1,
params => 'phlegm'
app => $this->app,
template => 'templatename',
web => 'webname',
topic => 'topicname',
def => 'defname',
keep => 1,
params => 'phlegm'
);
}
catch {
my $e = $_;
my $e = Foswiki::Exception::Fatal->transmute( $_, 0 );
if ( $e->isa('Foswiki::OopsException') ) {
my $e = shift;
$this->assert( $e->isa('Foswiki::OopsException') );
$this->assert_str_equals( 'webname', $e->web );
$this->assert_str_equals( 'topicname', $e->topic );
$this->assert_str_equals( 'defname', $e->def );
Expand All @@ -50,7 +38,7 @@ qr/^OopsException\(templatename\/defname web=>webname topic=>topicname keep=>1 p
);
}
else {
$e->throw;
$e->rethrow;
}
};

Expand All @@ -62,16 +50,16 @@ sub test_multiparamOopsException {
my $this = shift;
try {
Foswiki::OopsException->throw(
'templatename',
web => 'webname',
topic => 'topicname',
params => [ 'phlegm', '<pus>' ]
app => $this->app,
template => 'templatename',
web => 'webname',
topic => 'topicname',
params => [ 'phlegm', '<pus>' ]
);
}
catch {
my $e = $_;
my $e = Foswiki::Exception::Fatal->transmute( $_, 0 );
if ( $e->isa('Foswiki::OopsException') ) {
$this->assert( $e->isa('Foswiki::OopsException') );
$this->assert_str_equals( 'webname', $e->web );
$this->assert_str_equals( 'topicname', $e->topic );
$this->assert_str_equals( 'templatename', $e->template );
Expand All @@ -83,31 +71,31 @@ qr/^OopsException\(templatename web=>webname topic=>topicname params=>\[phlegm,<
);
}
else {
$e->throw;
$e->rethrow;
}
};

return;
}

sub upchuck {
my $session = shift;
my $e = Foswiki::OopsException->new(
'templatename',
web => 'webname',
topic => 'topicname',
params => [ 'phlegm', '<pus>' ]
my $this = shift;
my $e = Foswiki::OopsException->create(
template => 'templatename',
web => 'webname',
topic => 'topicname',
params => [ 'phlegm', '<pus>' ]
);
$e->redirect($session);
$e->redirect;

return;
}

# Test for DEPRECATED redirect
sub deprecated_test_redirectOopsException {
my $this = shift;
$this->createNewFoswikiSession();
my ($output) = $this->capture( \&upchuck, $this->session );
$this->createNewFoswikiApp;
my ($output) = $this->capture( \&upchuck );
$this->assert_matches( qr/^Status: 302.*$/m, $output );
$this->assert_matches(
qr#^Location: http.*/oops/webname/topicname?template=oopstemplatename;param1=phlegm;param2=%26%2360%3bpus%26%2362%3b$#m,
Expand All @@ -119,8 +107,13 @@ qr#^Location: http.*/oops/webname/topicname?template=oopstemplatename;param1=phl

sub test_AccessControlException {
my $this = shift;
my $ace = Foswiki::AccessControlException->new( 'FRY', 'burger', 'Spiders',
'FlumpNuts', 'Because it was there.' );
my $ace = Foswiki::AccessControlException->new(
mode => 'FRY',
user => 'burger',
web => 'Spiders',
topic => 'FlumpNuts',
reason => 'Because it was there.'
);
$this->assert_str_equals(
"AccessControlException: Access to FRY Spiders.FlumpNuts for burger is denied. Because it was there.",
$ace->stringify()
Expand All @@ -130,22 +123,38 @@ sub test_AccessControlException {
}

sub test_oopsScript {
my $this = shift;
my $query = Unit::Request->new(
initializer => {
skin => 'none',
template => 'oopsgeneric',
def => 'message',
param1 => 'heading',
param2 => '<pus>',
param3 => 'snot@dot.dat',
param4 => 'phlegm',
param5 => "the cat\nsat on\nthe rat"
my $this = shift;
my $oopsWeb = "Flum";
my $oopsTopic = "DeDum";
$this->createNewFoswikiApp(
requestParams => {
initializer => {
skin => 'none',
template => 'oopsgeneric',
def => 'message',
param1 => 'heading',
param2 => '<pus>',
param3 => 'snot@dot.dat',
param4 => 'phlegm',
param5 => "the cat\nsat on\nthe rat",
},
},
engineParams => {
simulate => 'cgi',
initialAttributes => {
path_info => "/$oopsWeb/$oopsTopic",
uri => $this->app->cfg->getScriptUrl(
0, 'oops', $oopsWeb, $oopsTopic
),
action => 'oops',
},
},
);
my ($output) = $this->capture(
sub {
$this->app->handleRequest;
}
);
$this->createNewFoswikiSession( undef, $query );
my ($output) =
$this->capture( $UI_FN, $this->session, "Flum", "DeDum", $query, 0 );
$this->assert_matches( qr/^phlegm$/m, $output );
$this->assert_matches( qr/^&#60;pus&#62;$/m, $output );
$this->assert_matches( qr/^snot&#64;dot.dat$/m, $output );
Expand Down

0 comments on commit c8a6fae

Please sign in to comment.