Skip to content

Commit

Permalink
Item1156: Create Release01x00 branch
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x00@2740 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
KennethLavrsen authored and KennethLavrsen committed Feb 26, 2009
1 parent 4570aa3 commit fc60109
Show file tree
Hide file tree
Showing 82 changed files with 22,012 additions and 0 deletions.
45 changes: 45 additions & 0 deletions UnitTestContrib/bin/test
@@ -0,0 +1,45 @@
#!/usr/bin/perl -wT
#
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org and TWiki Contributors
# Copyright (C) 2008-2009 Foswiki Contributors.
# All Rights Reserved. TWiki Contributors and Foswiki Contributors
# are listed in the AUTHORS file in the root of this distribution.
# NOTE: Please extend that file, not this notice.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version. For
# more details read LICENSE in the root of this distribution.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# As per the GPL, removal of this notice is prohibited.


use strict;
use warnings;

BEGIN {
if ( defined $ENV{GATEWAY_INTERFACE} ) {
$Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI';
use CGI::Carp qw(fatalsToBrowser);
$SIG{__DIE__} = \&CGI::Carp::confess;
}
else {
$Foswiki::cfg{Engine} = 'Foswiki::Engine::CLI';
require Carp;
$SIG{__DIE__} = \&Carp::confess;
}
$ENV{FOSWIKI_ACTION} = 'test';
@INC = ('.', grep { $_ ne '.' } @INC);
require 'setlib.cfg';
}

use Foswiki;
use Foswiki::UI;
$Foswiki::engine->run();
60 changes: 60 additions & 0 deletions UnitTestContrib/data/System/UnitTestContrib.txt
@@ -0,0 +1,60 @@
---+!! !UnitTestContrib
<!--
One line description, required for extensions repository catalog.
* Set SHORTDESCRIPTION = Foswiki Unit-Test Framework
-->
<a href="http://wikiring.com"><img src="%ATTACHURL%/logo.gif" style="float:right" /></a>
%SHORTDESCRIPTION%

%TOC%

The Foswiki Unit Test Framework consists of a set of test support packages and scripts, and a number of unit test packages that test many of the features of Foswiki.

At the time of writing this package can only be used with Foswiki and TWiki-4.2 and later.

This Contrib replaces the old Test::Unit based framework that we used previously. That framework works fine, but is overweight for what we require, and hard to install for non-subversion developers.

---++ Usage

To run the unit tests, =cd= to =test/unit= and type =perl ../bin/TestRunner.pl FoswikiSuite.pm=. The FoswikiSuite package will collect all the other tests in the =test/unit= directory and run them. Any test failures are reported during the test run and again at the end of the run.

---+++ Options

*-clean*: Sometimes sessions in a live Foswiki hang around, or a test can fail leaving fragments of fixtures behind. These sessions and fragments may stop the tests from being run again, as the tests require an cleanroom environment to run in. You can instruct the test runner to clean up any fragments passing =-clean= to =TestRunner.pl= - but use it with great care, as it deletes webs and files from =/tmp= without waiting for confirmation from you!

*-log*: Normal test output is printed to the console, so you can redirect it to a file. This is hard to do on some platforms, so the =-log= option is provided. This saves all the test output (STDOUT and STDERR) to a logfile. The logfile is named for the exact time the test run started. Remember that logfiles can get quite large. The logfile can also be useful when you are analysing unexpected output from subprocesses, as it blocks any attempt to redirect to the null device.

---++ Details

The =TestRunner.pl= script accepts a list of the names of test files in the current directory. it performs some preliminaries and environment checking before invoking a =Unit::TestRunner= that does the real work. This class iterates over the list of test files, and runs the tests. It maintains a record of any failures, and reports them at the end of the run.

Test files are built by deriving a class from =Unit::TestCase=. This is usually done via =FoswikiTestCase= or =FoswikiFnTestCase=, which are fixture-building classes designed specifically for use when testing Foswiki. =FoswikiTestCase= is used for tests where the Foswiki configuration ($Foswiki::cfg) must be saved and restored; it is also responsible for making sure the default plugins (and only the default plugins) are enabled. =FoswikiFnTestCase= is used where we are already fairly confident that basic Foswiki work, and we need some pre-registered users and pre-created test webs containing data that the test can work on.

FoswikiSuite automatically includes any Plugin tests it can find in subdirectories below =test/unit=. This is helpful when you want to test a plugin in context with all the other core unit tests.

One test file, =SemiAutomaticTestCaseTests.pm=, reads the semi-automatic tests from the !TestCases web stored in subversion. It will not run if it can't find the !TestCases web, or if the Foswiki:Extensions.TestFixturePlugin is not installed.

---++ Installation Instructions

%$INSTALL_INSTRUCTIONS%

---++ Contrib Info

Another great Foswiki extension from the <a style="text-decoration:none" href="http://wikiring.com"><img src="%ATTACHURLPATH%/wikiringlogo20x20.png" alt="" /> *WikiRing* </a> - working together to improve your wiki experience!

| Contrib Author(s): | Crawford Currie http://c-dot.co.uk and test authors |
| Copyright: | &copy; 2007 Foswiki Contributors |
| License: | [[http://www.gnu.org/licenses/gpl.html][GPL (Gnu General Public License)]] |
| Contrib Version: | %$VERSION% |
| Change History: | <!-- versions below in reverse order -->&nbsp; |
| 5 Sep 2007 | Added logging |
| Dependencies: | %$DEPENDENCIES% |
| Contrib Home: | http://foswiki.org/Extensions/UnitTestContrib |
| Feedback: | http://foswiki.org/Extensions/UnitTestContribDev |

__Related Topics:__ [[%SYSTEMWEB%.Contribs][Contribs]], %SYSTEMWEB%.DeveloperDocumentationCategory, %SYSTEMWEB%.AdminDocumentationCategory, %SYSTEMWEB%.DefaultPreferences, %USERSWEB%.SitePreferences

<!-- Do _not_ attempt to edit this topic; it is auto-generated. Please add comments/questions/remarks to the feedback topic on foswiki.org instead. -->

%META:FILEATTACHMENT{name="wikiringlogo20x20.png" attr="h" comment="" version="1"}%
%META:FILEATTACHMENT{name="logo.gif" attr="h" comment="" version="1"}%
23 changes: 23 additions & 0 deletions UnitTestContrib/lib/Foswiki/Contrib/UnitTestContrib.pm
@@ -0,0 +1,23 @@
# Contrib for Foswiki Collaboration Platform, http://Foswiki.org/
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details, published at
# http://www.gnu.org/copyleft/gpl.html

package Foswiki::Contrib::UnitTestContrib;

use strict;

use vars qw( $VERSION $RELEASE $SHORTDESCRIPTION );

$VERSION = '$Rev$';
$RELEASE = '';
$SHORTDESCRIPTION = '';

@@ -0,0 +1,7 @@
# Dependencies for UnitTestContrib
# Example:
# Time::ParseDate,>=2003.0211,cpan,Required.
# TWiki::Plugins,>=1.15,perl,TWiki 4.1 release.
Algorithm::Diff,>=0,cpan,required
HTML::Entities,>=0,cpan,required
TestFixturePlugin,>=0,perl,optional, used for semi-automatic test cases (TestCases web)
78 changes: 78 additions & 0 deletions UnitTestContrib/lib/Foswiki/Contrib/UnitTestContrib/MANIFEST
@@ -0,0 +1,78 @@
bin/test 0755
lib/Foswiki/Contrib/UnitTestContrib.pm 0644
lib/Foswiki/UI/Test.pm 0644
lib/Unit/Eavesdrop.pm 0644
lib/Unit/CGIEngine.pm 0644
lib/Unit/ExternalEngine.pm 0644
lib/Unit/HTMLDiffer.pm 0644
lib/Unit/Request.pm 0644
lib/Unit/Response.pm 0644
lib/Unit/TestCase.pm 0644
lib/Unit/TestRunner.pm 0644
lib/Unit/TestSuite.pm 0644
test/bin/TestRunner.pl 0755
test/unit/AccessControlTests.pm 0644
test/unit/AttrsTests.pm 0644
test/unit/AutoAttachTests.pm 0644
test/unit/ClientTests.pm 0755
test/unit/ConfigureTests.pm 0644
test/unit/EmptyTests.pm 0644
test/unit/EngineTests.pm 0644
test/unit/ExampleTests.pm 0644
test/unit/ExceptionTests.pm 0644
test/unit/ExtenderTests.pm 0644
test/unit/Fn_ENCODE.pm 0644
test/unit/Fn_GROUPS.pm 0644
test/unit/Fn_IF.pm 0644
test/unit/Fn_INCLUDE.pm 0644
test/unit/Fn_NOP.pm 0644
test/unit/Fn_QUERYPARAMS.pm 0644
test/unit/Fn_REVINFO.pm 0644
test/unit/Fn_SCRIPTURL.pm 0644
test/unit/Fn_SEARCH.pm 0644
test/unit/Fn_SECTION.pm 0644
test/unit/Fn_SEP.pm 0644
test/unit/Fn_URLPARAM.pm 0644
test/unit/Fn_USERINFO.pm 0644
test/unit/Fn_VAR.pm 0644
test/unit/FormDefTests.pm 0644
test/unit/FormattingTests.pm 0644
test/unit/FuncTests.pm 0644
test/unit/FuncUsersTests.pm 0644
test/unit/HierarchicalWebsTests.pm 0644
test/unit/InitFormTests.pm 0644
test/unit/Iterator.pm 0755
test/unit/Logger.pm 0755
test/unit/ManageDotPmTests.pm 0644
test/unit/MergeTests.pm 0644
test/unit/MetaTests.pm 0644
test/unit/PasswordTests.pm 0644
test/unit/PluginHandlerTests.pm 0644
test/unit/PrefsTests.pm 0644
test/unit/QueryTests.pm 0644
test/unit/RcsTests.pm 0644
test/unit/RegisterTests.pm 0644
test/unit/RenameTests.pm 0755
test/unit/RenderFormTests.pm 0644
test/unit/RequestTests.pm 0644
test/unit/ResponseTests.pm 0644
test/unit/RobustnessTests.pm 0644
test/unit/SaveScriptTests.pm 0644
test/unit/SemiAutomaticTestCaseTests.pm 0644
test/unit/StoreSmokeTests.pm 0644
test/unit/StoreTests.pm 0644
test/unit/TOCTests.pm 0644
test/unit/FoswikiFnTestCase.pm 0644
test/unit/FoswikiSuite.pm 0644
test/unit/FoswikiTestCase.pm 0644
test/unit/TemplatesTests.pm 0644
test/unit/TimeTests.pm 0644
test/unit/UploadScriptTests.pm 0644
test/unit/UTF8Tests.pm 0644
test/unit/VariableTests.pm 0644
test/unit/ViewParamSectionTests.pm 0755
test/unit/ViewScriptTests.pm 0644
test/unit/ViewFileScriptTests.pm 0644
pub/System/UnitTestContrib/wikiringlogo20x20.png 0660
pub/System/UnitTestContrib/logo.gif 0660
data/System/UnitTestContrib.txt 0660
26 changes: 26 additions & 0 deletions UnitTestContrib/lib/Foswiki/Contrib/UnitTestContrib/build.pl
@@ -0,0 +1,26 @@
#!/usr/bin/perl -w
BEGIN {
unshift @INC, split( /:/, $ENV{FOSWIKI_LIBS} );
}
use Foswiki::Contrib::Build;

# Create the build object
$build = new Foswiki::Contrib::Build('UnitTestContrib');

# (Optional) Set the details of the repository for uploads.
# This can be any web on any accessible TWiki installation.
# These defaults will be used when expanding tokens in .txt
# files, but be warned, they can be overridden at upload time!

# name of web to upload to
$build->{UPLOADTARGETWEB} = 'Extensions';
# Full URL of pub directory
$build->{UPLOADTARGETPUB} = 'http://foswiki.org/pub';
# Full URL of bin directory
$build->{UPLOADTARGETSCRIPT} = 'http://foswiki.org/bin';
# Script extension
$build->{UPLOADTARGETSUFFIX} = '';

# Build the target on the command line, or the default target
$build->build($build->{target});

23 changes: 23 additions & 0 deletions UnitTestContrib/lib/Foswiki/UI/Test.pm
@@ -0,0 +1,23 @@
package Foswiki::UI::Test;

use strict;
use Storable qw(thaw freeze);

sub test {
my $session = shift;
if ( my $desired = $session->{request}->param('desired_test_response') ) {
%{ $session->{response} } = %{ thaw($desired) };
}
else {
$session->{response}->header( -type => 'application/octet-stream' );
my %response = ( request => $session->{request} );
foreach ( keys %{ $session->{request}{uploads} } ) {
my $fh = $session->{request}{uploads}{$_}->handle;
local $/ = undef;
$response{$_} = <$fh>;
}
$session->{response}->print( freeze( \%response ) );
}
}

1;
130 changes: 130 additions & 0 deletions UnitTestContrib/lib/Unit/CGIEngine.pm
@@ -0,0 +1,130 @@
package Unit::CGIEngine;

use base qw(Unit::TestCase);
use strict;
use warnings;

BEGIN {
$Foswiki::cfg{Engine} = 'Foswiki::Engine::CGI';
$Foswiki::cfg{SwitchBoard}{test} = [ 'Foswiki::UI::Test', 'test', {} ];
}

use Foswiki;
use Foswiki::UI;
use Foswiki::Request;
use Storable qw(freeze thaw);

my $CRLF = "\015\012";

sub _req2cgi {
my $req = shift;
my $in = '';
my %env = (
GATEWAY_INTERFACE => 'CGI/1.1',
SCRIPT_NAME => '/bin/test',
SERVER_NAME => 'EngineTests',
SERVER_PORT => '80',
SERVER_PROTOCOL => 'HTTP/1.1',
SERVER_SOFTWARE => 'Foswiki',
);
$env{REQUEST_METHOD} = $req->method();
if ( $req->method eq 'POST' ) {
use bytes;
if ( keys %{ $req->{uploads} } ) {
my @chars = ( 0 .. 9, 'a' .. 'z', 'A' .. 'Z' );
my $boundary = '-' x 18;
for ( my $i = 0 ; $i < 25 ; $i++ ) {
$boundary .= $chars[ int( rand( scalar @chars ) ) ];
}
$env{CONTENT_TYPE} = "multipart/form-data; boundary=$boundary";
$boundary = '--' . $boundary;
foreach my $p ( $req->param ) {
foreach my $v ( $req->param($p) ) {
$in .= $boundary . $CRLF;
$in .= qq{Content-Disposition: form-data; name="$p"};
if ( my $fh = $req->upload($p) ) {
$in .= qq(; filename="$v");
$in .=
$CRLF . $_ . ': ' . $req->{uploads}{$v}{headers}{$_}
foreach keys %{ $req->{uploads}{$v}->{headers} };
local $/ = undef;
$v = <$fh>;
}
$in .= $CRLF . $CRLF . $v . $CRLF;
}
}
$in .= $boundary . "--" . $CRLF;
}
else {
$in = $req->query_string;
$env{CONTENT_TYPE} = 'application/x-www-form-urlencoded';
}
$env{CONTENT_LENGTH} = length($in);
}
else {
$env{QUERY_STRING} = $req->query_string;
}
foreach my $h ( $req->header ) {
next if $h =~ /^Cookie|Content-Length$/i;
my $v = $req->header($h);
$h =~ tr/-/_/;
$env{ 'HTTP_' . uc($h) } = $v;
}
$env{HTTP_COOKIE} = join(
'; ',
map {
Foswiki::urlEncode($_) . '='
. Foswiki::urlEncode( $req->cookies->{$_}->value )
} keys %{ $req->cookies }
) if scalar %{ $req->cookies };
$env{REMOTE_ADDR} = $req->remote_addr || '127.0.0.1';
if ( $req->remote_user ) {
$env{REMOTE_USER} = $req->remote_user;
$env{AUTH_TYPE} = 'Basic';
}
$env{PATH_INFO} = $req->path_info if $req->path_info;
return \%env, \$in;
}

sub set_up {
my $this = shift;
$this->SUPER::set_up(@_);
CGI::initialize_globals();
}

sub make_request {
my ( $this, $req ) = @_;

my ( $env, $in ) = _req2cgi($req);

# Saving STDIN
open my $stdin, '<&=', \*STDIN or die "Can't dup STDIN: $!";
close STDIN;

# Redirecting STDIN to the CGI input
open STDIN, '<', $in or die "Can't redirect STDIN to \$in: $!";

# Saving STDOUT
open my $stdout, '>&=', \*STDOUT or die "Can't dup STDOUT: $!";
close STDOUT;
my $out = '';

# Redirecting STDOUT to $out to grap the CGI output
open STDOUT, '>', \$out or die "Can't redirect STDOUT to \$out: $!";
local %ENV = %$env;
eval {
$ENV{FOSWIKI_ACTION} = 'test';
$Foswiki::engine->run();
};

# Restoring STDIN
open STDIN, '<&=', $stdin or die "Can't restore STDIN: $!";
close $stdin;

# Restoring STDOUT
open STDOUT, '>&=', $stdout or die "Can't restore STDOUT: $!";
close $stdout;
return HTTP::Message->parse($out);
}

1;

0 comments on commit fc60109

Please sign in to comment.