Skip to content

Commit

Permalink
Item13897: Tests up to Fn_IF, parsing subsytem completely Moo-fied.
Browse files Browse the repository at this point in the history
- Foswiki::Infix::*, Foswiki::Query::*, and Foswiki::If::* are all
completely Moo-fied.

- Few macros got Moo-compatibility fixes.

- ICON, IF, INCLUDE, and QUERY macros was converted to OO. Minus
_ICONSPACE, _EXT2ICON, _KNOWNICON, _ICONSTEMPLATE, evaluating_if,
evaluatingEval and _INCLUDES keys on the session object.

- Foswiki::Query::IP is now Moo::Role. Applies to all Foswiki::Query::OP_*
classes.
  • Loading branch information
vrurg committed Feb 4, 2016
1 parent 0bb52bd commit b86b550
Show file tree
Hide file tree
Showing 73 changed files with 1,192 additions and 1,015 deletions.
22 changes: 18 additions & 4 deletions UnitTestContrib/lib/Unit/TestRunner.pm
Expand Up @@ -606,11 +606,25 @@ sub runOne {
try {
# vrurg Recatch everything to convert perl error into
# exceptions with stacktrace for simplified error tracing.
local $SIG{__DIE__} =
sub { Foswiki::Exception->rethrow(shift) }
local $SIG{__DIE__} = sub {
my $e = shift;
if ( ref($e) && $e->isa('Foswiki::Exception') ) {
Foswiki::Exception->rethrow($e);
}
else {
Foswiki::Exception->throw( text => $e );
}
}
if DEBUG;
local $SIG{__WARN__} =
sub { Foswiki::Exception->rethrow(shift) }
local $SIG{__WARN__} = sub {
my $e = shift;
if ( ref($e) && $e->isa('Foswiki::Exception') ) {
Foswiki::Exception->rethrow($e);
}
else {
Carp::croak($e);
}
}
if DEBUG;
$tester->set_up($test);
$action .=
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_ENCODE.pm
Expand Up @@ -11,7 +11,7 @@ extends qw( FoswikiFnTestCase );
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
return $orig->( $class, testSuite => 'ENCODE', @_ );
return $orig->( $class, @_, testSuite => 'ENCODE' );
};

sub test_default {
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_FORMAT.pm
Expand Up @@ -19,7 +19,7 @@ around BUILDARGS => sub {
my $orig = shift;
my $class = shift;

return $orig->( $class, testSuite => 'SEARCH', @_ );
return $orig->( $class, @_, testSuite => 'SEARCH' );
};

sub BUILD {
Expand Down
2 changes: 1 addition & 1 deletion UnitTestContrib/test/unit/Fn_FORMFIELD.pm
Expand Up @@ -14,7 +14,7 @@ has other_web => ( is => 'rw', );
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;
return $orig->( $class, testSuite => 'FORMFIELD', @_ );
return $orig->( $class, @_, testSuite => 'FORMFIELD' );
};

around set_up => sub {
Expand Down
164 changes: 83 additions & 81 deletions UnitTestContrib/test/unit/Fn_GROUPINFO.pm
@@ -1,83 +1,82 @@
# tests for the correct expansion of GROUPINFO

package Fn_GROUPINFO;
use strict;
use warnings;

use FoswikiFnTestCase();
our @ISA = qw( FoswikiFnTestCase );
use v5.14;

use Foswiki();
use Foswiki::Func();
use Error qw( :try );
use Try::Tiny;

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

sub new {
my ( $class, @args ) = @_;
around BUILDARGS => sub {
my $orig = shift;
my $class = shift;

$Foswiki::cfg{Register}{AllowLoginName} = 1;

return $class->SUPER::new( 'GROUPINFO', @args );
}
return $orig->( $class, @_, testSuite => 'GROUPINFO' );
};

sub set_up {
around set_up => sub {
my $orig = shift;
my $this = shift;
$this->SUPER::set_up(@_);
$orig->( $this, @_ );
my ($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "GropeGroup" );
Foswiki::Func::readTopic( $this->users_web, "GropeGroup" );
$topicObject->text(" * Set GROUP = ScumBag,WikiGuest\n");
$topicObject->save();
$topicObject->finish();
($topicObject) = Foswiki::Func::readTopic( $this->{users_web}, "PopGroup" );
($topicObject) = Foswiki::Func::readTopic( $this->users_web, "PopGroup" );
$topicObject->text(" * Set GROUP = WikiGuest\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "NobodyGroup" );
Foswiki::Func::readTopic( $this->users_web, "NobodyGroup" );
$topicObject->text(" * Set GROUP = \n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "NestingGroup" );
Foswiki::Func::readTopic( $this->users_web, "NestingGroup" );
$topicObject->text(" * Set GROUP = GropeGroup\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "OnlyAdminCanChangeGroup" );
Foswiki::Func::readTopic( $this->users_web, "OnlyAdminCanChangeGroup" );
$topicObject->text(
" * Set GROUP = WikiGuest\n * Set TOPICCHANGE = AdminGroup\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "GroupWithHiddenGroup" );
Foswiki::Func::readTopic( $this->users_web, "GroupWithHiddenGroup" );
$topicObject->text(" * Set GROUP = HiddenGroup,WikiGuest\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "HiddenGroup" );
Foswiki::Func::readTopic( $this->users_web, "HiddenGroup" );
$topicObject->text(
" * Set GROUP = ScumBag\n * Set ALLOWTOPICVIEW = AdminUser\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "HiddenUserGroup" );
Foswiki::Func::readTopic( $this->users_web, "HiddenUserGroup" );
$topicObject->text(" * Set GROUP = ScumBag,HidemeGood\n");
$topicObject->save();
$topicObject->finish();
($topicObject) =
Foswiki::Func::readTopic( $this->{users_web}, "HidemeGood" );
($topicObject) = Foswiki::Func::readTopic( $this->users_web, "HidemeGood" );
my $topText = $topicObject->text();
$topText .= " * Set ALLOWTOPICVIEW = AdminUser\n";
$topText = $topicObject->text($topText);
$topicObject->save();
$topicObject->finish();

return;
}
};

sub test_basic {
my $this = shift;

my $ui = $this->{test_topicObject}->expandMacros('%GROUPINFO%');
my $ui = $this->test_topicObject->expandMacros('%GROUPINFO%');
$this->assert_matches( qr/\bGropeGroup\b/, $ui );
$this->assert_matches( qr/\bPopGroup\b/, $ui );
$this->assert_matches( qr/\bNestingGroup\b/, $ui );
Expand All @@ -90,10 +89,10 @@ sub test_basic {
sub test_withName {
my $this = shift;

my $ui =
$this->{test_topicObject}->expandMacros('%GROUPINFO{"GropeGroup"}%');
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
my $ui = $this->test_topicObject->expandMacros('%GROUPINFO{"GropeGroup"}%');
my $users_web = $this->users_web;
$this->assert_matches( qr/\b$users_web.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );

Expand All @@ -103,25 +102,26 @@ sub test_withName {
sub test_withQualifiedName {
my $this = shift;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros("%GROUPINFO{\"$this->{users_web}.GropeGroup\"}%");
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
$this->test_topicObject->expandMacros(
"%GROUPINFO{\"$users_web.GropeGroup\"}%");
$this->assert_matches( qr/\b$users_web.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );

$ui =
$this->{test_topicObject}
->expandMacros("%GROUPINFO{\"$this->{users_web}/GropeGroup\"}%");
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
$this->test_topicObject->expandMacros(
"%GROUPINFO{\"$users_web/GropeGroup\"}%");
$this->assert_matches( qr/\b$users_web.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
@u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );

$ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"Sandbox.GropeGroup"}%');
$this->test_topicObject->expandMacros(
'%GROUPINFO{"Sandbox.GropeGroup"}%');
$this->assert_equals( '', $ui );

return;
Expand All @@ -131,21 +131,19 @@ sub test_withShow {
my $this = shift;

my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{ show="allowchange"}%');
$this->test_topicObject->expandMacros('%GROUPINFO{ show="allowchange"}%');
$this->assert_does_not_match( qr/NobodyGroup/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 7, scalar(@u) );

$ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{ show="denychange"}%');
$this->test_topicObject->expandMacros('%GROUPINFO{ show="denychange"}%');
$this->assert_matches( qr/NobodyGroup/, $ui );
$this->assert_matches( qr/BaseGroup/, $ui );
@u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );

$ui = $this->{test_topicObject}->expandMacros('%GROUPINFO{ show="all"}%');
$ui = $this->test_topicObject->expandMacros('%GROUPINFO{ show="all"}%');
@u = split( /,/, $ui );
$this->assert_equals( 9, scalar(@u) );
return;
Expand All @@ -154,15 +152,15 @@ sub test_withShow {
sub test_noExpand {
my $this = shift;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"NestingGroup" expand="off"}%');
$this->assert_matches( qr/^$this->{users_web}.GropeGroup$/, $ui );
$this->test_topicObject->expandMacros(
'%GROUPINFO{"NestingGroup" expand="off"}%');
$this->assert_matches( qr/^$users_web.GropeGroup$/, $ui );

$ui =
$this->{test_topicObject}->expandMacros('%GROUPINFO{"NestingGroup"}%');
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
$ui = $this->test_topicObject->expandMacros('%GROUPINFO{"NestingGroup"}%');
$this->assert_matches( qr/\b$users_web.ScumBag\b/, $ui );
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );

Expand All @@ -172,11 +170,12 @@ sub test_noExpand {
sub test_noExpandHidden {
my $this = shift;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"GroupWithHiddenGroup" expand="off"}%');
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
$this->assert_does_not_match( qr/\b$this->{users_web}.HiddenGroup\b/, $ui );
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GroupWithHiddenGroup" expand="off"}%');
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
$this->assert_does_not_match( qr/\b$users_web.HiddenGroup\b/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 1, scalar(@u) );

Expand All @@ -186,17 +185,18 @@ sub test_noExpandHidden {
sub test_expandHidden {
my $this = shift;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"GroupWithHiddenGroup" expand="on"}%');
$this->assert_matches( qr/\b$this->{users_web}.WikiGuest\b/, $ui );
$this->assert_does_not_match( qr/\b$this->{users_web}.HiddenGroup\b/,
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GroupWithHiddenGroup" expand="on"}%');
$this->assert_matches( qr/\b$users_web.WikiGuest\b/, $ui );
$this->assert_does_not_match( qr/\b$users_web.HiddenGroup\b/,
$ui, 'HiddenGroup revealed' );

# SMELL: Tasks/Item10176 - GroupWithHiddenGroup contains HiddenGroup - which contains user ScumBag. However user ScumBag is NOT hidden.
# So even though HiddenGroup is not visible, the users it contains are still revealed if they are not also hidden. Since the HiddenGroup
# itself is not revealed, this bug is questionable.
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,
$this->assert_matches( qr/\b$users_web.ScumBag\b/,
$ui, 'ScumBag revealed' );

my @u = split( /,/, $ui );
Expand All @@ -208,12 +208,13 @@ sub test_expandHidden {
sub test_expandHiddenUser {
my $this = shift;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"HiddenUserGroup" expand="on"}%');
$this->assert_matches( qr/\b$this->{users_web}.ScumBag\b/,
$this->test_topicObject->expandMacros(
'%GROUPINFO{"HiddenUserGroup" expand="on"}%');
$this->assert_matches( qr/\b$users_web.ScumBag\b/,
$ui, 'ScumBag missing from HiddenUserGroup' );
$this->assert_does_not_match( qr/\b$this->{users_web}.HidemeGood\b/,
$this->assert_does_not_match( qr/\b$users_web.HidemeGood\b/,
$ui, 'HidemeGood revealed' );
my @u = split( /,/, $ui );
$this->assert_equals( 1, scalar(@u) );
Expand All @@ -225,20 +226,21 @@ sub test_expandHiddenUserAsAdmin {
my $this = shift;

$this->createNewFoswikiSession( $Foswiki::cfg{AdminUserLogin} );
$this->{test_topicObject}->finish if $this->{test_topicObject};
( $this->{test_topicObject} ) =
Foswiki::Func::readTopic( $this->{test_web}, $this->{test_topic} );
$this->{test_topicObject}->text("BLEEGLE\n");
$this->{test_topicObject}->save();
$this->test_topicObject->finish if $this->test_topicObject;
$this->test_topicObject(
Foswiki::Func::readTopic( $this->test_web, $this->test_topic ) );
$this->test_topicObject->text("BLEEGLE\n");
$this->test_topicObject->save;

my $users_web = $this->users_web;
my $ui =
$this->{test_topicObject}
->expandMacros('%GROUPINFO{"HiddenUserGroup" expand="on"}%');
$this->assert_matches( qr/$this->{users_web}.ScumBag/, $ui );
$this->assert_matches( qr/$this->{users_web}.HidemeGood/, $ui );
$this->test_topicObject->expandMacros(
'%GROUPINFO{"HiddenUserGroup" expand="on"}%');
$this->assert_matches( qr/$users_web.ScumBag/, $ui );
$this->assert_matches( qr/$users_web.HidemeGood/, $ui );
my @u = split( /,/, $ui );
$this->assert_equals( 2, scalar(@u) );
$this->{test_topicObject}->finish();
$this->test_topicObject->finish;

return;
}
Expand All @@ -247,35 +249,35 @@ sub test_formatted {
my $this = shift;

my $ui =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GropeGroup" format="WU$wikiusernameU$usernameW$wikiname"}%'
);
$this->assert_str_equals(
"WU$Foswiki::cfg{UsersWebName}.ScumBagUscumWScumBag, WU$Foswiki::cfg{UsersWebName}.WikiGuestUguestWWikiGuest",
$ui
);
$ui =
$this->{test_topicObject}->expandMacros('%GROUPINFO{format="<$name>"}%');
$this->test_topicObject->expandMacros('%GROUPINFO{format="<$name>"}%');
$this->assert_matches( qr/^<\w+>(, <\w+>)+$/, $ui );

$ui =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GropeGroup" format="<$username>" separator=";"}%');
$this->assert_matches( qr/^<\w+>(;<\w+>)+$/, $ui );

$ui =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GropeGroup" format="<$name>" separator=";"}%');
$this->assert_matches( qr/^<GropeGroup>(;<GropeGroup>)+$/, $ui );

$ui =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GropeGroup" header="H" footer="F" format="<$username>" separator=";"}%'
);
$this->assert_matches( qr/^H<\w+>(;<\w+>)+F$/, $ui );

$ui =
$this->{test_topicObject}->expandMacros(
$this->test_topicObject->expandMacros(
'%GROUPINFO{"GropeGroup" limit="1" limited="L" footer = "F" format="<$username>"}%'
);
$this->assert_matches( qr/^<\w+>LF$/, $ui );
Expand Down

0 comments on commit b86b550

Please sign in to comment.