1 # Copyright (C) 2006 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
21 use Test::More tests => 19;
26 $uri =~ s/ /%20/g; # for cygdrive stuff including spaces
30 add_module('localnames.pl');
32 xpath_test(update_page('LocalNames', "* [http://www.oddmuse.org/ OddMuse]\n"
33 . "* [[ln:$uri/ln.txt]]\n"
34 . "* [[ln:$uri/ln.txt Lion's Namespace]]\n"),
35 '//ul/li/a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="OddMuse"]',
36 '//ul/li/a[@class="url outside ln"][@href="' . $uri . '/ln.txt"][text()="' . $uri . '/ln.txt"]',
37 '//ul/li/a[@class="url outside ln"][@href="' . $uri . '/ln.txt"][text()="Lion\'s Namespace"]');
41 xpath_run_tests(split('\n',<<'EOT'));
42 [http://www.oddmuse.org/ OddMuse]
43 //a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
45 //a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
49 # now check whether the integration with InitVariables works
50 $page = update_page('LocalNamesTest', 'OddMuse [[my blog]]');
51 xpath_test($page, '//a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]');
56 require LWP::UserAgent;
59 skip "LWP::UserAgent not installed", 1 if $@;
61 xpath_test($page, '//a[@class="near"][@title="LocalNames"][@href="http://lion.taoriver.net/"][text()="my blog"]');
65 # verify that automatic update is off by default
66 xpath_test(update_page('LocalNamesTest', 'This is an [http://www.example.org/ Example].'),
67 '//a[@class="url http outside"][@href="http://www.example.org/"][text()="Example"]');
68 negative_xpath_test(get_page('LocalNames'),
69 '//ul/li/a[@class="url http outside"][@href="http://www.example.org/"][text()="Example"]');
71 # check automatic update
72 AppendStringToFile($ConfigFile, "\$LocalNamesCollect = 1;\n");
74 xpath_test(update_page('LocalNamesTest', 'This is an [http://www.example.com/ Example].'),
75 '//a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
76 xpath_test(get_page('LocalNames'),
77 '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
82 xpath_run_tests(split('\n',<<'EOT'));
84 //a[@class="near"][@title="LocalNames"][@href="http://www.oddmuse.org/"][text()="OddMuse"]
86 //a[@class="near"][@title="LocalNames"][@href="http://www.example.com/"][text()="Example"]
89 xpath_test(get_page('action=rc days=1 showedit=1'),
90 '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: Example"]');
92 # more definitions on one page
93 update_page('LocalNamesTest', 'This is an [http://www.example.org/ Example] for [http://www.emacswiki.org EmacsWiki].');
95 xpath_test(get_page('action=rc days=1 showedit=1'),
96 '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: EmacsWiki, and Example"]');
98 update_page('LocalNamesTest', 'This is an [http://www.example.com/ Example] for [http://www.emacswiki.org/ EmacsWiki] and [http://communitywiki.org/ Community Wiki].');
100 xpath_test(get_page('action=rc days=1 showedit=1'),
101 '//a[@class="local"][text()="LocalNames"]/following-sibling::strong[text()="Local names defined on LocalNamesTest: Community Wiki, EmacsWiki, and Example"]');
103 update_page('LocalNamesTest', 'This is [http://www.example.com/ one Example].');
104 xpath_test(get_page('LocalNames'),
105 '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="one Example"]');
107 update_page('LocalNamesTest', 'This is [http://www.example.com/ one simple Example].');
108 negative_xpath_test(get_page('LocalNames'),
109 '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="one simple Example"]');
110 AppendStringToFile($ConfigFile, "\$LocalNamesCollectMaxWords = 1;\n");
112 update_page('LocalNamesTest', 'This is [http://www.example.com/ Example one].');
113 negative_xpath_test(get_page('LocalNames'),
114 '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="Example one"]');