Skip to content

Commit

Permalink
Item8500: perltidy
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.foswiki.org/branches/Release01x00@8158 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
AndrewJones authored and AndrewJones committed Jul 13, 2010
1 parent ac320b7 commit eb24755
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 48 deletions.
16 changes: 12 additions & 4 deletions InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin.pm
Expand Up @@ -69,8 +69,9 @@ sub initPlugin {
my $man = $Foswiki::regex{mixedAlphaNum};
my $ua = $Foswiki::regex{upperAlpha};
%interSiteTable = ();
$sitePattern = "([$ua][$man]+)";
$pagePattern = "([${man}_\/][$man" . '"\'\.\/\+\_\,\&\;\:\=\!\?\%\#\@\-]*?)';
$sitePattern = "([$ua][$man]+)";
$pagePattern =
"([${man}_\/][$man" . '"\'\.\/\+\_\,\&\;\:\=\!\?\%\#\@\-]*?)';

# Get plugin preferences from InterwikiPlugin topic
$interLinkFormat =
Expand All @@ -83,8 +84,15 @@ sub initPlugin {
|| 'InterWikis'
);

if(! Foswiki::Func::checkAccessPermission( 'VIEW', $user, undef, $interTopic, $interWeb ) ){
Foswiki::Func::writeWarning("InterwikiPlugin: user '$user' did not have permission to read the rules topic at '$interWeb.$interTopic'");
if (
!Foswiki::Func::checkAccessPermission(
'VIEW', $user, undef, $interTopic, $interWeb
)
)
{
Foswiki::Func::writeWarning(
"InterwikiPlugin: user '$user' did not have permission to read the rules topic at '$interWeb.$interTopic'"
);
return 1;
}
my $text = Foswiki::Func::readTopicText( $interWeb, $interTopic, undef, 1 );
Expand Down
10 changes: 5 additions & 5 deletions InterwikiPlugin/lib/Foswiki/Plugins/InterwikiPlugin/build.pl
Expand Up @@ -5,16 +5,16 @@
use strict;

BEGIN {
foreach my $pc (split(/:/, $ENV{FOSWIKI_LIBS})) {
unshift @INC, $pc;
}
foreach my $pc ( split( /:/, $ENV{FOSWIKI_LIBS} ) ) {
unshift @INC, $pc;
}
}

use Foswiki::Contrib::Build;

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

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

90 changes: 51 additions & 39 deletions InterwikiPlugin/test/unit/InterwikiPlugin/InterwikiPluginTests.pm
Expand Up @@ -22,22 +22,22 @@ sub set_up {
}

sub tear_down {
my $this = shift;
$this->SUPER::tear_down();
my $this = shift;
$this->SUPER::tear_down();
}

############################################################

sub test_link_from_default_rules_topic {
my $this = shift;
$this->assert_html_equals(
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/Perl" title="\'Perl\' on \'Wikipedia\'"><noautolink>Wikipedia:Perl</noautolink></a>',
Foswiki::Func::renderText("Wikipedia:Perl", $this->{test_web})
);
my $this = shift;
$this->assert_html_equals(
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/Perl" title="\'Perl\' on \'Wikipedia\'"><noautolink>Wikipedia:Perl</noautolink></a>',
Foswiki::Func::renderText( "Wikipedia:Perl", $this->{test_web} )
);
}

sub test_link_from_local_rules_topic {
my $this = shift;
my $this = shift;
my $localRulesTopic = "LocalInterWikis";

Foswiki::Func::saveTopic( $this->{test_web}, $localRulesTopic, undef,
Expand All @@ -50,25 +50,27 @@ sub test_link_from_local_rules_topic {
</nautolink>
HERE

Foswiki::Func::setPreferencesValue("INTERWIKIPLUGIN_RULESTOPIC", "$this->{test_web}.$localRulesTopic");
Foswiki::Plugins::InterwikiPlugin::initPlugin($this->{test_web}, $this->{test_topic}, $this->{test_user}, $Foswiki::cfg{SystemWebName});
Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
"$this->{test_web}.$localRulesTopic" );
Foswiki::Plugins::InterwikiPlugin::initPlugin(
$this->{test_web}, $this->{test_topic},
$this->{test_user}, $Foswiki::cfg{SystemWebName}
);

$this->assert_html_equals(
'<a class="interwikiLink" href="http://rule.invalid.url?page=Topage" title="Local rule"><noautolink>Localrule:Topage</noautolink></a>',
Foswiki::Func::renderText("Localrule:Topage", $this->{test_web})
);
$this->assert_html_equals(
'<a class="interwikiLink" href="http://rule.invalid.url?page=Topage" title="Local rule"><noautolink>Localrule:Topage</noautolink></a>',
Foswiki::Func::renderText( "Localrule:Topage", $this->{test_web} )
);
}


# FIXME: Not sure why this unit test doesn't pass
# same one passes on trunk, and the plugin code is the sam
# I have tested this feature manually and it works as it should
sub FIXME_test_cant_view_rules_topic {
my $this = shift;
my $this = shift;
my $rulesTopic = "CantReadInterWikis";

Foswiki::Func::saveTopic( $this->{test_web}, $rulesTopic, undef,
<<'HERE');

Foswiki::Func::saveTopic( $this->{test_web}, $rulesTopic, undef, <<'HERE');
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
Expand All @@ -79,35 +81,41 @@ sub FIXME_test_cant_view_rules_topic {
* Set DENYTOPICVIEW = %USERSWEB%.WikiGuest
HERE

Foswiki::Func::setPreferencesValue("INTERWIKIPLUGIN_RULESTOPIC", "$this->{test_web}.$rulesTopic");
Foswiki::Plugins::InterwikiPlugin::initPlugin($this->{test_web}, $this->{test_topic}, 'guest', $Foswiki::cfg{SystemWebName});

$this->assert_html_equals(
'Localrule:Topage',
Foswiki::Func::renderText("Localrule:Topage", $this->{test_web})
);
Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
"$this->{test_web}.$rulesTopic" );
Foswiki::Plugins::InterwikiPlugin::initPlugin( $this->{test_web},
$this->{test_topic}, 'guest', $Foswiki::cfg{SystemWebName} );

$this->assert_html_equals( 'Localrule:Topage',
Foswiki::Func::renderText( "Localrule:Topage", $this->{test_web} ) );
}

sub test_link_with_url {
my $this = shift;
$this->assert_html_equals(
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/http://www.google.com/search?q=foswiki" title="\'http://www.google.com/search?q=foswiki\' on \'Wikipedia\'"><noautolink>Wikipedia:http://www.google.com/search?q=foswiki</noautolink></a>',
Foswiki::Func::renderText("Wikipedia:http://www.google.com/search?q=foswiki", $this->{test_web})
);
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/http://www.google.com/search?q=foswiki" title="\'http://www.google.com/search?q=foswiki\' on \'Wikipedia\'"><noautolink>Wikipedia:http://www.google.com/search?q=foswiki</noautolink></a>',
Foswiki::Func::renderText(
"Wikipedia:http://www.google.com/search?q=foswiki",
$this->{test_web}
)
);
}

# tests the following characters:
# ' . & = " /
sub test_link_with_complex_url {
my $this = shift;
$this->assert_html_equals(
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'" title="\'http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'\' on \'Wikipedia\'"><noautolink>Wikipedia:http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'</noautolink></a>',
Foswiki::Func::renderText('Wikipedia:http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'', $this->{test_web})
);
'<a class="interwikiLink" href="http://en.wikipedia.org/wiki/http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'" title="\'http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'\' on \'Wikipedia\'"><noautolink>Wikipedia:http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'</noautolink></a>',
Foswiki::Func::renderText(
'Wikipedia:http://www.google.com/search?q=foswiki&foo="bar"/\'baz.\'',
$this->{test_web}
)
);
}

sub test_link_with_topic_name {
my $this = shift;
my $this = shift;
my $localRulesTopic = "LocalInterWikis";

Foswiki::Func::saveTopic( $this->{test_web}, $localRulesTopic, undef,
Expand All @@ -119,13 +127,17 @@ sub test_link_with_topic_name {
</nautolink>
HERE

Foswiki::Func::setPreferencesValue("INTERWIKIPLUGIN_RULESTOPIC", "$this->{test_web}.$localRulesTopic");
Foswiki::Plugins::InterwikiPlugin::initPlugin($this->{test_web}, $this->{test_topic}, $this->{test_user}, $Foswiki::cfg{SystemWebName});
Foswiki::Func::setPreferencesValue( "INTERWIKIPLUGIN_RULESTOPIC",
"$this->{test_web}.$localRulesTopic" );
Foswiki::Plugins::InterwikiPlugin::initPlugin(
$this->{test_web}, $this->{test_topic},
$this->{test_user}, $Foswiki::cfg{SystemWebName}
);

$this->assert_html_equals(
'<a class="interwikiLink" href="http://rule.invalid.url?page=Topage" title="Local rule"><noautolink>WebHome:Topage</noautolink></a>',
Foswiki::Func::renderText("WebHome:Topage", $this->{test_web})
);
$this->assert_html_equals(
'<a class="interwikiLink" href="http://rule.invalid.url?page=Topage" title="Local rule"><noautolink>WebHome:Topage</noautolink></a>',
Foswiki::Func::renderText( "WebHome:Topage", $this->{test_web} )
);
}

1;

0 comments on commit eb24755

Please sign in to comment.