1 # Copyright (C) 2006, 2007 Alex Schroeder <alex@gnu.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 3 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, see <http://www.gnu.org/licenses/>.
18 use Test::More tests => 25;
19 use utf8; # tests contain UTF-8 characters and it matters
23 add_module('permanent-anchors.pl');
25 # define permanent anchor
26 test_page(update_page('Jack_DeJohnette', 'A friend of [::Gary Peacock]'),
29 'name="Gary_Peacock"',
31 'title="Click to search for references to this permanent anchor"');
32 # get the page again to trigger a dirty/cache error
33 negative_xpath_test(get_page('Jack_DeJohnette'),
34 '//a[@class="definition"]/following-sibling::a[@class="definition"]');
36 # link to a permanent anchor
37 test_page(update_page('Keith_Jarret', 'Plays with [[Gary Peacock]]'),
39 'wiki.pl/Jack_DeJohnette#Gary_Peacock',
42 # verify that the link target redirects to the permanent anchor
43 test_page(get_page('Gary_Peacock'),
45 'Location: .*wiki.pl/Jack_DeJohnette#Gary_Peacock');
46 # undefine the permanent anchor
47 test_page(update_page('Jack_DeJohnette', 'A friend of Gary Peacock.'),
48 'A friend of Gary Peacock.');
49 # verify that the link to it turns into an edit link
50 test_page(get_page('Keith_Jarret'),
51 'wiki.pl\?action=edit;id=Gary_Peacock');
52 # repeat with an existing page
53 test_page(update_page('Thelonius_Mönk', 'first revision', 'start here'),
55 test_page(update_page('Thelonius_Mönk', 'second revision', 'this is next'),
57 # check warning message for existing page
58 $page = update_page('Keith_Jarret', 'plays unlike [::Thelonius Mönk]');
59 like($page, qr(the page (.*?) also exists), 'the page ... also exists');
60 $page =~ qr(the page (.*?) also exists);
62 xpath_test($link, '//a[@class="local"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk"][text()="Thelonius Mönk"]');
63 # verify that the redirection works
64 test_page(get_page('action=browse id=Thelonius_Mönk'),
66 'Location: .*wiki.pl/Keith_Jarret#Thelonius_M%c3%b6nk');
67 # verify that the anchor=0 parameter has the desired effect
68 test_page(get_page('action=browse anchor=0 id=Thelonius_Mönk'),
70 # verify that the history page uses anchor=0 for its links
71 xpath_test(get_page('action=history id=Thelonius_Mönk'),
72 '//a[@class="revision"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk;revision=1"][text()="Revision 1"]',
73 # not sure whether it makes sure to have the class "local" here!
74 '//a[@class="local"][@href="http://localhost/wiki.pl?action=browse;anchor=0;id=Thelonius_M%c3%b6nk"][text()="Revision 2"]');
75 # verify that the history page of ordinary pages remains unaffected
76 xpath_test(get_page('action=history id=Jack_DeJohnette'),
77 '//a[@class="revision"][@href="http://localhost/wiki.pl?action=browse;id=Jack_DeJohnette;revision=1"][text()="Revision 1"]',
78 # not sure whether it makes sure to have the class "local" here!
79 '//a[@class="local"][@href="http://localhost/wiki.pl/Jack_DeJohnette"][text()="Revision 2"]');
81 # create an anchored object
82 update_page('TheGame', qq{The game has rules and props. [::TheRules] Simple and elegant. [::TheProps] Expensive and brittle.\n----\nThat's how not to do it!});
83 update_page('TheTest', qq{The rules are supposed to be\n<include "TheRules">});