Skip to content

Commit

Permalink
Item13897: Converted SemiAutomaticTestCaseTests
Browse files Browse the repository at this point in the history
The test is passing except for test_TestCaseAutoFormattedSearchDetails
which is most likely failing due to uncaught bug in search.

- Few bugfixes to macros URLENCODE, SPACEDTOPIC.

- Made INCLUDE macro more informative about failed handler loading.

- Converted IncludeHandlers.
  • Loading branch information
vrurg committed Aug 11, 2016
1 parent b611f55 commit 76d5836
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 98 deletions.
12 changes: 7 additions & 5 deletions RCSStoreContrib/lib/Foswiki/Store/Rcs/Handler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,12 @@ around BUILDARGS => sub {

my %params = @_;
ASSERT( UNTAINTED( $params{web} ), "web $params{web} is tainted!" )
if DEBUG;
if DEBUG && $params{web};
ASSERT( UNTAINTED( $params{topic} ), "topic $params{topic} is tainted!" )
if DEBUG && $params{topic};
ASSERT( UNTAINTED( $params{attachment} ) ) if DEBUG && $params{attachment};
ASSERT( UNTAINTED( $params{attachment} ) )
if DEBUG
&& $params{attachment};

Foswiki::Exception->throw( text => $class
. "::new cannot be called directly, use loadCache() instead." )
Expand Down Expand Up @@ -623,10 +625,10 @@ sub getTopicNames {
# the name filter is used to ensure we don't return filenames
# that contain illegal characters as topic names.
my @topicList =
map { $_->[0] }
map { $_->[0] }
sort { $a->[1] cmp $b->[1] }
map { [ $_, NFKD($_) ] }
map { /^(.*)\.txt$/; $1; }
map { [ $_, NFKD($_) ] }
map { /^(.*)\.txt$/; $1; }
grep { !/$Foswiki::cfg{NameFilter}/ && /\.txt$/ }

# Must _decode before applying the NameFilter and sort
Expand Down
123 changes: 81 additions & 42 deletions UnitTestContrib/test/unit/SemiAutomaticTestCaseTests.pm
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package SemiAutomaticTestCaseTests;
use v5.14;

use Foswiki();
use Foswiki::UI::View();
use Foswiki;
use Try::Tiny;

use Moo;
use Foswiki::Class;
use namespace::clean;
extends qw( FoswikiFnTestCase );

Expand Down Expand Up @@ -134,55 +133,56 @@ around set_up => sub {
$orig->( $this, @_ );

# Testcases are written using good anchors
$Foswiki::cfg{RequireCompatibleAnchors} = 0;
$this->app->cfg->data->{RequireCompatibleAnchors} = 0;

# Test using an RCS store, fo which we have some bogus topics.
$Foswiki::cfg{Store}{Implementation} = 'Foswiki::Store::RcsLite';
$this->app->cfg->data->{Store}{Implementation} = 'Foswiki::Store::RcsLite';
for ( my $i = 1 ; $i <= scalar @test_comma_v ; $i++ ) {
my $f = "$Foswiki::cfg{DataDir}/TestCases/SearchTestTopic$i.txt,v";
my $f = $this->app->cfg->data->{DataDir}
. "/TestCases/SearchTestTopic$i.txt,v";
unlink $f if -e $f;
open( F, '>', $f ) || die $!;
print F $test_comma_v[ $i - 1 ];
close(F);
}

$VIEW_UI_FN ||= $this->getUIFn('view');
#$VIEW_UI_FN ||= $this->getUIFn('view');

# This user is used in some testcases. All we need to do is make sure
# their topic exists in the test users web
if (
!$this->session->topicExists(
$Foswiki::cfg{UsersWebName}, 'WikiGuest'
!$this->app->store->topicExists(
$this->app->cfg->data->{UsersWebName}, 'WikiGuest'
)
)
{
my ($to) =
Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName}, 'WikiGuest' );
$this->app->readTopic( $this->app->cfg->data->{UsersWebName},
'WikiGuest' );
$to->text('This user is used in some testcases');
$to->save();
$to->finish();
$to->save;
undef $to;
}
if (
!$this->session->topicExists(
$Foswiki::cfg{UsersWebName},
!$this->app->store->topicExists(
$this->app->cfg->data->{UsersWebName},
'UnknownUser'
)
)
{
my ($to) =
Foswiki::Func::readTopic( $Foswiki::cfg{UsersWebName},
my ($to) = $this->app->readTopic( $this->app->cfg->data->{UsersWebName},
'UnknownUser' );
$to->text('This user is used in some testcases');
$to->save();
$to->finish();
$to->save;
}
};

around tear_down => sub {
my $orig = shift;
my $this = shift;
for ( my $i = 1 ; $i <= scalar @test_comma_v ; $i++ ) {
my $f = "$Foswiki::cfg{DataDir}/TestCases/SearchTestTopic$i.txt,v";
my $f = $this->app->cfg->data->{DataDir}
. "/TestCases/SearchTestTopic$i.txt,v";
unlink $f if -e $f;
}
$orig->($this);
Expand All @@ -193,8 +193,8 @@ around list_tests => sub {
my ( $this, $suite ) = @_;
my @set = $orig->( $this, @_ );

$this->createNewFoswikiSession();
unless ( $this->session->webExists('TestCases') ) {
$this->createNewFoswikiApp;
unless ( $this->app->store->webExists('TestCases') ) {
print STDERR
"Cannot run semi-automatic test cases; TestCases web not found";
return;
Expand All @@ -205,48 +205,87 @@ around list_tests => sub {
"Cannot run semi-automatic test cases; could not find TestFixturePlugin";
return;
}
foreach my $case ( Foswiki::Func::getTopicList('TestCases') ) {
foreach my $case ( $this->app->getTopicList('TestCases') ) {
next unless $case =~ m/^TestCaseAuto/;
my $test = 'SemiAutomaticTestCaseTests::test_' . $case;
no strict 'refs';
*{$test} = sub { shift->run_testcase($case) };
use strict 'refs';
push( @set, $test );
}
$this->finishFoswikiSession();
$this->createNewFoswikiApp;
return @set;
};

sub run_testcase {
my ( $this, $testcase ) = @_;
my $query = Unit::Request->new(
initializer => {
test => 'compare',
debugenableplugins =>
'TestFixturePlugin,SpreadSheetPlugin,InterwikiPlugin',
skin => 'pattern'
}
);
$query->path_info("/TestCases/$testcase");
$Foswiki::cfg{INCLUDE}{AllowURLs} = 1;
$Foswiki::cfg{Plugins}{TestFixturePlugin}{Enabled} = 1;
$Foswiki::cfg{Plugins}{TestFixturePlugin}{Module} =
$this->app->cfg->data->{INCLUDE}{AllowURLs} = 1;
$this->app->cfg->data->{Plugins}{TestFixturePlugin}{Enabled} = 1;
$this->app->cfg->data->{Plugins}{TestFixturePlugin}{Module} =
'Foswiki::Plugins::TestFixturePlugin';
$this->createNewFoswikiSession( $this->test_user_login, $query );
$this->createNewFoswikiApp(
requestParams => {
initializer => {
test => 'compare',
debugenableplugins =>
'TestFixturePlugin,SpreadSheetPlugin,InterwikiPlugin',
skin => 'pattern'
}
},
engineParams => {
initialAttributes => {
path_info => "/TestCases/$testcase",
user => $this->test_user_login,
action => 'view',
},
},
);
my ($topicObject) =
Foswiki::Func::readTopic( $this->users_web, 'ProjectContributor' );
$this->app->readTopic( $this->users_web, 'ProjectContributor' );
$topicObject->text('none');
$topicObject->save();
$topicObject->finish();
my ($text) = $this->capture( $VIEW_UI_FN, $this->session );
$topicObject->save;
undef $topicObject;
$this->createNewFoswikiApp(
requestParams => {
initializer => {
test => 'compare',
debugenableplugins =>
'TestFixturePlugin,SpreadSheetPlugin,InterwikiPlugin',
skin => 'pattern'
}
},
engineParams => {
initialAttributes => {
path_info => "/TestCases/$testcase",
user => $this->test_user_login,
action => 'view',
},
},
);
my ($text) = $this->capture( sub { $this->app->handleRequest } );

unless ( $text =~ m#<font color="green">ALL TESTS PASSED</font># ) {
$this->assert(
open( my $F, '>:encoding(utf8)', "${testcase}_run.html" ) );
print $F $text;
$this->assert( close $F );
$query->delete('test');
($text) = $this->capture( $VIEW_UI_FN, $this->session );
$this->createNewFoswikiApp(
requestParams => {
initializer => {
debugenableplugins =>
'TestFixturePlugin,SpreadSheetPlugin,InterwikiPlugin',
skin => 'pattern'
}
},
engineParams => {
initialAttributes => {
path_info => "/TestCases/$testcase",
user => $this->test_user_login,
action => 'view',
},
},
);
($text) = $this->capture( sub { $this->app->handleRequest } );
$this->assert( open( $F, '>:encoding(utf8)', "${testcase}.html" ) );
print $F $text;
$this->assert( close $F );
Expand Down
7 changes: 4 additions & 3 deletions core/lib/Foswiki/App.pm
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ sub create {
---++ ObjectMethod deepWebList($filter, $web) -> @list
Deep list subwebs of the named web. $filter is a Foswiki::WebFilter
Deep list subwebs of the named web. $filter is a =Foswiki::WebFilter=
object that is used to filter the list. The listing of subwebs is
dependent on $Foswiki::cfg{EnableHierarchicalWebs} being true.
Expand Down Expand Up @@ -1236,10 +1236,11 @@ sub writeCompletePage {
# Don't expire the validation key through login, or when
# endpoint is an error.
Foswiki::Validation::expireValidationKeys($cgis)
unless ( $this->request->action() eq 'login'
unless ( $this->request->action eq 'login'
or ( $ENV{REDIRECT_STATUS} || 0 ) >= 400 );

my $usingStrikeOne = $Foswiki::cfg{Validation}{Method} eq 'strikeone';
my $usingStrikeOne =
$this->cfg->data->{Validation}{Method} eq 'strikeone';
if ($usingStrikeOne) {

# add the validation cookie
Expand Down
5 changes: 3 additions & 2 deletions core/lib/Foswiki/Class.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,22 @@ use Moo;
with
<verbtaim>
<verbatim>
use Foswiki::Class;
</verbatim>
---++ Parameters
The following parameters are support by this module:
| *Parameter* | *Description* |
| =callbacks= | Provide support for callbacks |
---++ Callbacks support.
When =callbacks= parameter is used:
<verbtaim>
<verbatim>
use Foswiki::Class qw(callbacks);
</verbatim>
Expand Down
35 changes: 18 additions & 17 deletions core/lib/Foswiki/IncludeHandlers/doc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,28 @@ use constant PUBLISHED_API_TOPIC => 'PublishedAPI';

# Include embedded doc in a core module
sub INCLUDE {
my ( $ignore, $session, $control, $params ) = @_;
my ( $includeMacro, $control, $params ) = @_;

my $app = $includeMacro->app;
my %removedblocks = ();
my $class = $control->{_DEFAULT} || 'doc:Foswiki';
my $publicOnly = ( $params->{publicOnly} || '' ) eq 'on';
Foswiki::Func::setPreferencesValue( 'SMELLS', '' );
$app->prefs->setSessionPreferences( 'SMELLS', '' );

# SMELL This is no longer being used in PerlDoc ...
# Foswiki::Func::setPreferencesValue( 'DOC_PARENT', '' );
Foswiki::Func::setPreferencesValue( 'DOC_CHILDREN', '' );
Foswiki::Func::setPreferencesValue( 'DOC_TITLE', '---++ !! !%TOPIC%' );
# $app->prefs->setSessionPreferences( 'DOC_PARENT', '' );
$app->prefs->setSessionPreferences( 'DOC_CHILDREN', '' );
$app->prefs->setSessionPreferences( 'DOC_TITLE', '---++ !! !%TOPIC%' );
$class =~ s/[a-z]+://; # remove protocol
$class ||= 'Foswiki'; # provide a reasonable default

# return '' unless $class && $class =~ m/^Foswiki/;
$class =~ s/[^\w:]//g;

my %publicPackages = map { $_ => 1 } _loadPublishedAPI();
my %publicPackages = map { $_ => 1 } _loadPublishedAPI($app);
my $visibility = exists $publicPackages{$class} ? 'public' : 'internal';
_setNavigation( $class, $publicOnly, \%publicPackages );
Foswiki::Func::setPreferencesValue( 'DOC_TITLE',
_setNavigation( $app, $class, $publicOnly, \%publicPackages );
$app->prefs->setSessionPreferences( 'DOC_TITLE',
"---++ !! =$visibility package= " . _renderTitle($class) );

my $pmfile;
Expand All @@ -65,7 +67,7 @@ sub INCLUDE {
my $inPod = 0;
my $pod = '';
my $howSmelly = 0;
my $showSmells = !Foswiki::Func::isGuest();
my $showSmells = !$app->isGuest();
local $/ = undef;
my $perl = <$PMFILE>;
my $isa;
Expand Down Expand Up @@ -127,12 +129,11 @@ s/^---\+(?:!!)?\s+package\s*(.*)/---+ =$visibility package= $1/;
. " *SMELL / FIX / TODO count: $howSmelly*\n"
. '</blockquote>';
$pod .= $podSmell;
Foswiki::Func::setPreferencesValue( 'SMELLS', $podSmell );
$app->prefs->setSessionPreferences( 'SMELLS', $podSmell );
}

$pod =
Foswiki::Macros::INCLUDE::applyPatternToIncludedText( $pod,
$control->{pattern} )
$includeMacro->applyPatternToIncludedText( $pod, $control->{pattern} )
if ( $control->{pattern} );

# Adjust the root heading level
Expand All @@ -150,14 +151,14 @@ s/^---\+(?:!!)?\s+package\s*(.*)/---+ =$visibility package= $1/;

# set DOC_CHILDREN preference value to a list of sub-packages.
sub _setNavigation {
my ( $class, $publicOnly, $publicPackages ) = @_;
my ( $app, $class, $publicOnly, $publicPackages ) = @_;
my @children;
my %childrenDesc;
my $classPrefix = $class . '::';

# my $classParent = $class;
# $classParent =~ s/::[^:]+$//;
# Foswiki::Func::setPreferencesValue( 'DOC_PARENT', _doclink($classParent) );
# $app->prefs->setSessionPreferences( 'DOC_PARENT', _doclink($classParent) );
$class =~ s#::#/#g;

foreach my $inc (@INC) {
Expand Down Expand Up @@ -189,7 +190,7 @@ sub _setNavigation {
}
}
$children .= '</ul>';
Foswiki::Func::setPreferencesValue( 'DOC_CHILDREN', $children );
$app->prefs->setSessionPreferences( 'DOC_CHILDREN', $children );
}

# get a summary of the pod documentation by looking directly after the ---+ package TML.
Expand Down Expand Up @@ -241,9 +242,9 @@ sub _getPackSummary ($) {
}

sub _loadPublishedAPI {
my $app = shift;
my ( $meta, $text ) =
Foswiki::Func::readTopic( $Foswiki::cfg{SystemWebName},
PUBLISHED_API_TOPIC );
$app->readTopic( $Foswiki::cfg{SystemWebName}, PUBLISHED_API_TOPIC );
my @ret;
for my $line ( split /\r?\n/, $text ) {

Expand Down

0 comments on commit 76d5836

Please sign in to comment.