Skip to content

Commit

Permalink
Item13897: Huge but rather intermidiate commit.
Browse files Browse the repository at this point in the history
- Moo-fied parsing and iteration subsystems.

- Iterator tests are passing.

- Foswiki::Iterator converted from a base class into a Role.

- New option for Foswiki::Object::isaCLASS - does. Check if object not only
inherits from a certain class but does some role. If it is necessary to
check role only Foswiki::Object may be used as the base class to check
against.

- Eliminating

eval "require SomeModule"; die $@ if $@;

pieces from code. Replacing with uniform Foswiki::load_package.

- Foswiki::load_package was unable to properly load macro modules because
while being separate files they're essentially part of Foswiki class. Thus
isa() check doesn't do the job properly. Yet, it was using preencoded '/'
as path separator which would most definitely cause problems on Win
platforms. Fixed both problems by making use of File::Spec->catfile() and
%INC hash.
  • Loading branch information
vrurg committed Feb 8, 2016
1 parent be0e7c1 commit 901a48c
Show file tree
Hide file tree
Showing 48 changed files with 1,785 additions and 1,670 deletions.
2 changes: 1 addition & 1 deletion UnitTestContrib/lib/Unit/TestCase.pm
Expand Up @@ -263,7 +263,7 @@ sub assert {
$mess ||= "Assertion failed";
$mess = join( "\n", @{ $this->annotations } ) . "\n" . $mess;
$mess = Carp::longmess($mess);
die $mess;
Foswiki::Exception::ASSERT->throw( text => $mess, object => $this );
}

=begin TML
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -495,7 +495,7 @@ DIE
eval "use $suite";
die $@ if $@;

my $tester = $suite->new($suite);
my $tester = $suite->new( testSuite => $suite );

my $log = "stdout.$$.log";
require Unit::Eavesdrop;
Expand Down
6 changes: 3 additions & 3 deletions UnitTestContrib/test/unit/Fn_QUERY.pm
Expand Up @@ -132,12 +132,12 @@ sub test_badQUERY {
unless ($post11);

foreach my $test (@tests) {
my $text = '%QUERY{"' . $test->test . '"}%';
my $text = '%QUERY{"' . $test->{test} . '"}%';
my $result = $this->test_topicObject->expandMacros($text);
$result =~ s/^.*foswikiAlert'>\s*//s;
$result =~ s/\s*<\/span>\s*//s;
$this->assert( $result =~ s/^.*}:\s*//s, $text );
$this->assert_str_equals( $test->expect, $result );
$this->assert_str_equals( $test->{expect}, $result );
}
my $result = $this->test_topicObject->expandMacros('%QUERY%');

Expand Down Expand Up @@ -393,7 +393,7 @@ SMELL
$topicObject0Att->save();

my $text = <<PONG;
%QUERY{ "'$test_web}.DeadHerring'/META:FIELD[name='Wibble'].value"}%
%QUERY{ "'$test_web.DeadHerring'/META:FIELD[name='Wibble'].value"}%
PONG
my $result = $this->test_topicObject->expandMacros($text);
$this->assert_equals( <<THIS, $result );
Expand Down
148 changes: 74 additions & 74 deletions UnitTestContrib/test/unit/Fn_QUERYPARAMS.pm
Expand Up @@ -2,20 +2,15 @@
#
#
package Fn_QUERYPARAMS;
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );
use v5.14;

use strict;
use Moo;
extends qw( FoswikiFnTestCase );

sub new {
my $self = shift()->SUPER::new( 'QUERYPARAMS', @_ );
return $self;
}

sub set_up {
my $this = shift;
$this->SUPER::set_up(@_);
}
around BUILDARGS => sub {
my $orig = shift;
return $orig->( @_, testSuite => 'QUERYPARAMS' );
};

sub test_default {
my $this = shift;
Expand All @@ -24,17 +19,17 @@ sub test_default {

# test default parameter

$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_str_equals( '', "$str" );

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_str_equals( 'foo=&#60;evil script&#62;&#39;&#34;&#37;',
"$str" );

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;&#39;&#34;&#37;\nfee=free", "$str" );
}
Expand All @@ -46,17 +41,17 @@ sub test_multi {

# test multiple parameters

$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_str_equals( '', "$str" );

$this->{request}->param( -name => 'foo', -value => ( 'beer', 'free' ) );
$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$this->request->param( -name => 'foo', -value => ( 'beer', 'free' ) );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_matches( qr/foo=free/, "$str" );
$this->assert_matches( qr/foo=beer/, "$str" );
$this->assert_equals( length($str), 17 );

$this->{request}->param( -name => 'foo', -value => ( 'beer', 'beer' ) );
$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS%');
$this->request->param( -name => 'foo', -value => ( 'beer', 'beer' ) );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS%');
$this->assert_matches( qr/^foo=beer\nfoo=beer$/, "$str" );
}

Expand All @@ -65,47 +60,55 @@ sub test_encode {

my $str;

$this->{request}
->param( -name => 'foo', -value => "<evil script>\n&\'\"%*A" );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param(
-name => 'foo',
-value => "<evil script>\n&\'\"%*A"
);
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}
->expandMacros('%QUERYPARAMS{encoding="entity"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="entity"}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;\n&#38;&#39;&#34;&#37;&#42;A\nfee=free",
"$str" );

$this->{request}
->param( -name => 'foo', -value => "<evil script>\n&\'\"%*A" );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param(
-name => 'foo',
-value => "<evil script>\n&\'\"%*A"
);
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="safe"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="safe"}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;\n&&#39;&#34;&#37;*A\nfee=free", "$str" );

$this->{request}
->param( -name => 'foo', -value => "<evil script>\n&\'\"%*A" );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param(
-name => 'foo',
-value => "<evil script>\n&\'\"%*A"
);
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="html"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="html"}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;&#10;&#38;&#39;&#34;&#37;&#42;A\nfee=free",
"$str" );

$this->{request}
->param( -name => 'foo', -value => "<evil script>\n&\'\"%*A" );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param(
-name => 'foo',
-value => "<evil script>\n&\'\"%*A"
);
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}
->expandMacros('%QUERYPARAMS{encoding="quotes"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="quotes"}%');
$this->assert_str_equals( "foo=<evil script>\n&\'\\\"%*A\nfee=free",
"$str" );

$this->{request}
->param( -name => 'foo', -value => "<evil script>\n&\'\"%*A" );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param(
-name => 'foo',
-value => "<evil script>\n&\'\"%*A"
);
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros('%QUERYPARAMS{encoding="url"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{encoding="url"}%');
$this->assert_str_equals(
"foo=%3cevil%20script%3e%0a%26%27%22%25*A\nfee=free", "$str" );
}
Expand All @@ -115,11 +118,11 @@ sub test_format {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}
->expandMacros('%QUERYPARAMS{format="$name is equal to $value"}%');
$this->test_topicObject->expandMacros(
'%QUERYPARAMS{format="$name is equal to $value"}%');
$this->assert_str_equals(
"foo is equal to &#60;evil script&#62;&#39;&#34;&#37;\nfee is equal to free",
"$str"
Expand All @@ -132,9 +135,9 @@ sub test_no_format_no_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$str = $this->{test_topicObject}->expandMacros('%QUERYPARAMS{}%');
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS{}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;&#39;&#34;&#37;\nfee=free", "$str" );
}
Expand All @@ -144,11 +147,10 @@ sub test_no_format_with_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}
->expandMacros('%QUERYPARAMS{separator="NEXT"}%');
$this->test_topicObject->expandMacros('%QUERYPARAMS{separator="NEXT"}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;&#39;&#34;&#37;NEXTfee=free", "$str" );
}
Expand All @@ -158,10 +160,9 @@ sub test_no_format_empty_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros('%QUERYPARAMS{separator=""}%');
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str = $this->test_topicObject->expandMacros('%QUERYPARAMS{separator=""}%');
$this->assert_str_equals(
"foo=&#60;evil script&#62;&#39;&#34;&#37;fee=free", "$str" );
}
Expand All @@ -171,11 +172,11 @@ sub test_with_format_no_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}
->expandMacros('%QUERYPARAMS{format="$name is equal to $value"}%');
$this->test_topicObject->expandMacros(
'%QUERYPARAMS{format="$name is equal to $value"}%');
$this->assert_str_equals(
"foo is equal to &#60;evil script&#62;&#39;&#34;&#37;\nfee is equal to free",
"$str"
Expand All @@ -187,10 +188,10 @@ sub test_with_format_with_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%QUERYPARAMS{format="$name is equal to $value" separator="NEXT"}%');
$this->assert_str_equals(
"foo is equal to &#60;evil script&#62;&#39;&#34;&#37;NEXTfee is equal to free",
Expand All @@ -203,10 +204,9 @@ sub test_with_format_empty_separator {

my $str;

$this->{request}->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->{request}->param( -name => 'fee', -value => 'free' );
$str =
$this->{test_topicObject}->expandMacros(
$this->request->param( -name => 'foo', -value => '<evil script>\'"%' );
$this->request->param( -name => 'fee', -value => 'free' );
$str = $this->test_topicObject->expandMacros(
'%QUERYPARAMS{format="$name is equal to $value" separator=""}%');
$this->assert_str_equals(
"foo is equal to &#60;evil script&#62;&#39;&#34;&#37;fee is equal to free",
Expand All @@ -219,10 +219,10 @@ sub test_stdescapes_not_expanded {

my $str;

$this->{request}->param( -name => 'percent', -value => '$percnt' );
$this->{request}->param( -name => 'dollar', -value => '$dollar' );
$this->request->param( -name => 'percent', -value => '$percnt' );
$this->request->param( -name => 'dollar', -value => '$dollar' );
$str =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%QUERYPARAMS{format="$dollarname $name is equal to $dollarvalue $value" separator="$n"}%'
);
my $expected = <<'FOO';
Expand Down

0 comments on commit 901a48c

Please sign in to comment.