Skip to content

Commit

Permalink
Item13897: RESTTests is working.
Browse files Browse the repository at this point in the history
Inclded ported Foswiki::Request::Rest by George Clark.

- Converted UI::Rest

- Moved redirectto method to Foswiki::App

- Reregistering an existing macro doesn't generate a error but a log entry.

- Converted PageCache.pm

- Partially passing CacheTests
  • Loading branch information
vrurg committed May 26, 2016
1 parent 5f383d3 commit 7b4fbd4
Show file tree
Hide file tree
Showing 15 changed files with 952 additions and 358 deletions.
3 changes: 1 addition & 2 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -635,8 +635,7 @@ sub runOne {
catch {
# If for some reason any code within try just dies then why
# stringify what's not an exception object?
my $exceptionMessage =
ref($_) && $_->can('stringify') ? $_->stringify : $_;
my $exceptionMessage = Foswiki::Exception::errorStr($_);
safe_print "*** ", $exceptionMessage, "\n";
if ( $tester->expecting_failure ) {
$action .=
Expand Down
57 changes: 33 additions & 24 deletions UnitTestContrib/test/unit/CacheTests.pm
Expand Up @@ -210,44 +210,55 @@ around tear_down => sub {
sub check {
my ( $this, $pathinfo ) = @_;

$UI_FN ||= $this->getUIFn( $this->uifn );
$Foswiki::cfg{Cache}{Debug} = 1;
my $query = Unit::Request->new( initializer => { skin => ['none'], } );
$query->path_info($pathinfo);
$query->method('GET');

$this->createNewFoswikiSession( $this->test_user_login,
$query, context => { $this->uifn => 1 }, );
#$UI_FN ||= $this->getUIFn( $this->uifn );
$this->app->cfg->data->{Cache}{Debug} = 1;

$this->createNewFoswikiApp(
requestParams => { initializer => { skin => ['none'], }, },
engineParams => {
simulate => 'cgi',
initialAttributes => {
path_info => $pathinfo,
method => 'GET',
action => $this->uifn,
},
},
context => { $this->uifn => 1 },
user => $this->test_user_login,
);

# This first request should *not* be satisfied from the cache, but
# the cache should be populated with the result.
my $p1start = Benchmark->new();
my ( $one, $result, $stdout, $stderr ) = $this->capture(
sub {
no strict 'refs';
&{$UI_FN}( $this->session );
use strict 'refs';
$Foswiki::engine->finalize( $this->session->response,
$this->session->request );
return $this->app->handleRequest;
}
);
my $p1end = Benchmark->new();

#print STDERR "P1: $stderr\n" if $stderr;

$this->createNewFoswikiSession( $this->test_user_login,
$query, context => { $this->uifn => 1 }, );
$this->createNewFoswikiApp(
requestParams => { initializer => { skin => ['none'], }, },
engineParams => {
simulate => 'cgi',
initialAttributes => {
path_info => $pathinfo,
method => 'GET',
action => $this->uifn,
},
},
context => { $this->uifn => 1, },
user => $this->test_user_login,
);

# This second request should be satisfied from the cache
# How do we know it was?
my $p2start = Benchmark->new();
( my $two, $result, $stdout, $stderr ) = $this->capture(
sub {
no strict 'refs';
&{$UI_FN}( $this->session );
use strict 'refs';
$Foswiki::engine->finalize( $this->session->response,
$this->session->request );
return $this->app->handleRequest;
}
);
my $p2end = Benchmark->new();
Expand All @@ -264,10 +275,8 @@ sub check {
my $two_heads = $1;
$this->assert( $two_heads =~ /^X-Foswiki-Pagecache: 1$/im, $two_heads );

print STDERR "To cache: "
. timestr( timediff( $p1end, $p1start ) ) . "\n";
print STDERR "From cache: "
. timestr( timediff( $p2end, $p2start ) ) . "\n";
print "To cache: " . timestr( timediff( $p1end, $p1start ) ) . "\n";
print "From cache: " . timestr( timediff( $p2end, $p2start ) ) . "\n";

return if $one eq $two;

Expand Down
5 changes: 3 additions & 2 deletions UnitTestContrib/test/unit/FoswikiTestCase.pm
Expand Up @@ -21,6 +21,8 @@ use Assert;
use Data::Dumper;
use Scalar::Util qw(blessed);

require Digest::MD5;

use Foswiki();
use Foswiki::Meta();
use Foswiki::Plugins();
Expand Down Expand Up @@ -428,7 +430,7 @@ sub _check_dependency {
# Eg. Foswiki::Plugins::ZonePlugin,>=3.1,perl
# TODO: type?
if ( $what =~ m/^([^,]+)\s*(,\s*([^,]+),([^,]+))?/ ) {
require Foswiki::Configure::Dependency;
Foswiki::load_package('Foswiki::Configure::Dependency');
my ( $module, $equality, $version ) = ( $1, $3, $4 );
print STDERR "_check_dependency, testing $module "
. ( $equality || '""' ) . ' '
Expand Down Expand Up @@ -1017,7 +1019,6 @@ sub captureWithKey {

# As we won't be clicking using javascript, we have to fake that part too
if ($strikeone) {
require Digest::MD5;
$v = Digest::MD5::md5_hex( $v, Foswiki::Validation::_getSecret($cgis) );
}
$request->param(
Expand Down

0 comments on commit 7b4fbd4

Please sign in to comment.