wiki.pl: Port some fixes from upstream
[Orgmuse.git] / t / links.t
blob0f832a5b26f93a1ad56eb6a6f332959f1c5886af
1 # Copyright (C) 2006, 2008  Alex Schroeder <alex@emacswiki.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the
15 #    Free Software Foundation, Inc.
16 #    59 Temple Place, Suite 330
17 #    Boston, MA 02111-1307 USA
19 require 't/test.pl';
20 package OddMuse;
21 use Test::More tests => 55;
23 clear_pages();
24 add_module('links.pl');
26 update_page('InterMap',
27             " Oddmuse http://www.emacswiki.org/cgi-bin/oddmuse.pl?\n",
28             'required', 0, 1);
30 update_page('a', 'Oddmuse:foo(no) [Oddmuse:bar] [Oddmuse:baz text] '
31             . '[Oddmuse:bar(no)] [Oddmuse:baz(no) text] '
32             . '[[Oddmuse:foo_(bar)]] [[[Oddmuse:foo (baz)]]] [[Oddmuse:foo (quux)|text]]');
33 $InterInit = 0;
34 InitVariables();
36 my @Test = map { quotemeta } split('\n',<<'EOT');
37 "a" -> "Oddmuse:foo"
38 "a" -> "Oddmuse:bar"
39 "a" -> "Oddmuse:baz"
40 "a" -> "Oddmuse:foo_(bar)"
41 "a" -> "Oddmuse:foo (baz)"
42 "a" -> "Oddmuse:foo (quux)"
43 EOT
45 test_page_negative(get_page('action=links raw=1'), @Test);
46 test_page(get_page('action=links raw=1 inter=1'), @Test);
48 @Test = split('\n',<<'EOT');
49 //a[@class="local"][@href="http://localhost/wiki.pl/a"][text()="a"]
50 //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="page"][text()="foo"]
51 //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?bar"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="page"][text()="bar"]
52 //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?baz"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="page"][text()="baz"]
53 //a[@class="inter Oddmuse"][@href="http://www.emacswiki.org/cgi-bin/oddmuse.pl?foo_(bar)"]/span[@class="site"][text()="Oddmuse"]/following-sibling::span[@class="separator"][text()=":"]/following-sibling::span[@class="page"][text()="foo_(bar)"]
54 EOT
56 negative_xpath_test(get_page('action=links'), @Test);
57 xpath_test(get_page('action=links inter=1'), @Test);
59 AppendStringToFile($ConfigFile, "\$BracketWiki = 0;\n");
61 update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar [FooBaz] [FooQuux fnord] ');
62 $page = get_page('action=links raw=1');
64 test_page($page, split('\n',<<'EOT'));
65 "a" -> "b"
66 "a" -> "c"
67 "a" -> "FooBar"
68 "a" -> "FooBaz"
69 "a" -> "FooQuux"
70 EOT
72 test_page_negative($page, '"a" -> "d"');
74 AppendStringToFile($ConfigFile, "\$BracketWiki = 1;\n");
76 update_page('a', '[[b]] [[[c]]] [[d|e]] FooBar [FooBaz] [FooQuux fnord] '
77             . 'http://www.oddmuse.org/ [http://www.emacswiki.org/] '
78             . '[http://www.communitywiki.org/ cw]');
80 @Test1 = split('\n',<<'EOT');
81 "a" -> "b"
82 "a" -> "c"
83 "a" -> "d"
84 "a" -> "FooBar"
85 "a" -> "FooBaz"
86 "a" -> "FooQuux"
87 EOT
89 @Test2 = split('\n',<<'EOT');
90 "a" -> "http://www.oddmuse.org/"
91 "a" -> "http://www.emacswiki.org/"
92 "a" -> "http://www.communitywiki.org/"
93 EOT
95 $page = get_page('action=links raw=1');
96 test_page($page, @Test1);
97 test_page_negative($page, @Test2);
98 $page = get_page('action=links raw=1 url=1');
99 test_page($page, @Test1, @Test2);
100 $page = get_page('action=links raw=1 links=0 url=1');
101 test_page_negative($page, @Test1);
102 test_page($page, @Test2);