/
InterwikiPluginTests.pm
121 lines (96 loc) · 3.93 KB
/
InterwikiPluginTests.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package InterwikiPluginTests;
use strict;
use FoswikiFnTestCase;
our @ISA = qw( FoswikiFnTestCase );
use Foswiki;
use Foswiki::Func;
use Foswiki::Plugins::InterwikiPlugin;
sub new {
my $self = shift()->SUPER::new(@_);
return $self;
}
sub set_up {
my $this = shift;
$this->SUPER::set_up();
$this->{test_user} = 'scum';
}
sub 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})
);
}
sub test_link_from_local_rules_topic {
my $this = shift;
my $localRulesTopic = "LocalInterWikis";
Foswiki::Func::saveTopic( $this->{test_web}, $localRulesTopic, undef,
<<'HERE');
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Localrule | http://rule.invalid.url?page= | Local rule |
| Wiki | http://c2.com/cgi/wiki? | Redefined global rule to wiki page |
</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});
$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 $rulesTopic = "CantReadInterWikis";
Foswiki::Func::saveTopic( $this->{test_web}, $rulesTopic, undef,
<<'HERE');
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| Localrule | http://rule.invalid.url?page= | Local rule |
| Wiki | http://c2.com/cgi/wiki? | Redefined global rule to wiki page |
</nautolink>
* 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})
);
}
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})
);
}
sub test_link_with_topic_name {
my $this = shift;
my $localRulesTopic = "LocalInterWikis";
Foswiki::Func::saveTopic( $this->{test_web}, $localRulesTopic, undef,
<<'HERE');
---+++ Local rules
<noautolink>
| *Alias:* | *URL:* | *Tooltip Text:* |
| WebHome | http://rule.invalid.url?page= | Local rule |
</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});
$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;