1 # Copyright (C) 2006, 2007, 2009 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 => 38;
19 use utf8; # tests contain UTF-8 characters and it matters
25 # Search for broken regular expressions
27 test_page(get_page('search=%2Btest'),
28 '<h1>Malformed regular expression in \+test</h1>');
32 update_page('SearchAndReplace', 'This is fooz and this is barz.', '', 1);
33 $page = get_page('search=fooz');
35 '<h1>Search for: fooz</h1>',
36 '<p class="result">1 pages found.</p>',
37 'This is <strong>fooz</strong> and this is barz.');
38 xpath_test($page, '//span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/SearchAndReplace"][text()="SearchAndReplace"]');
41 $page = get_page('search=andreplace');
43 '<h1>Search for: andreplace</h1>',
44 '<p class="result">1 pages found.</p>');
45 # FIXME: Not sure this should work... 'Search<strong>AndReplace</strong>'
46 xpath_test($page, '//span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/SearchAndReplace"][text()="SearchAndReplace"]');
48 # Brackets in the page name
50 test_page(update_page('Search (and replace)', 'Muu'),
51 'search=%22Search\+%5c\(and\+replace%5c\)%22');
53 # Make sure only admins can replace
55 test_page(get_page('search=foo replace=bar'),
56 'This operation is restricted to administrators only...');
58 # Simple replace where the replacement pattern is found
60 test_page(get_page('search=fooz replace=fuuz pwd=foo'), split('\n',<<'EOT'));
61 <h1>Replaced: fooz → fuuz</h1>
62 <p class="result">1 pages found.</p>
63 This is <strong>fuuz</strong> and this is barz.
66 # Replace with empty string
68 test_page(get_page('search=this%20is%20 replace= pwd=foo delete=1'), split('\n',<<'EOT'));
69 <h1>Replaced: this is → </h1>
70 <p class="result">1 pages found.</p>
74 # Replace with backreferences, where the replacement pattern is no longer found
76 test_page(get_page('"search=([a-z]%2b)z" replace=x%241 pwd=foo'), '1 pages found');
77 test_page(get_page('SearchAndReplace'), 'xfuu and xbar.');
79 # Create an extra page that should not be found
80 update_page('NegativeSearchTest', 'this page contains an ab');
81 update_page('NegativeSearchTestTwo', 'this page contains another ab');
82 test_page(get_page('search=xb replace=[xa]b pwd=foo'), '1 pages found'); # not two ab!
83 test_page(get_page('SearchAndReplace'), 'xfuu and \[xa\]bar.');
86 test_page(get_page('search=xfuu replace=/fuu/ pwd=foo'), '1 pages found'); # not two ab!
87 test_page(get_page('SearchAndReplace'), '/fuu/ and \[xa\]bar.');
88 test_page(get_page('search=/fuu/ replace={{fuu}} pwd=foo'), '1 pages found');
89 test_page(get_page('SearchAndReplace'), '{{fuu}} and \[xa\]bar.');
91 # Check headers especially the quoting of non-ASCII characters.
93 $page = update_page("Alexander_Schröder", "Edit [[Alexander Schröder]]!");
95 '//h1/a[@title="Click to search for references to this page"][@href="http://localhost/wiki.pl?search=%22Alexander+Schr%c3%b6der%22"][text()="Alexander Schröder" or text()="' . Encode::encode_utf8('Alexander Schröder') . '"]',
96 '//a[@class="local"][@href="http://localhost/wiki.pl/Alexander_Schr%c3%b6der"][text()="Alexander Schröder" or text()="' . Encode::encode_utf8('Alexander Schröder') . '"]');
98 xpath_test(update_page('IncludeSearch',
99 "first line\n<search \"ab\">\nlast line"),
100 '//p[text()="first line "]', # note the NL -> SPC
101 '//div[@class="search"]/p/span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/NegativeSearchTest"][text()="NegativeSearchTest"]',
102 '//div[@class="search"]/p/span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/NegativeSearchTestTwo"][text()="NegativeSearchTestTwo"]',
103 '//p[text()=" last line"]'); # note the NL -> SPC
107 update_page("Zero", "This is about 0 and the empty string ''.");
108 test_page(get_page('search=0'),
109 '<h1>Search for: 0</h1>',
110 '<p class="result">1 pages found.</p>',
111 "This is about <strong>0</strong> and the empty string ''.",
112 'meta name="robots" content="NOINDEX,FOLLOW"');
116 update_page("Tag", "This is <b>bold</b>.");
117 test_page(get_page('search="<b>"'),
118 '<h1>Search for: <b></h1>',
119 '<p class="result">1 pages found.</p>',
120 "This is <strong><b></strong>.");
122 # Test fallback when grep is unavailable
125 local $TODO = "Don't get a decent error when opening the grep pipe";
126 AppendStringToFile($ConfigFile, "\$ENV{PATH} = '';\n");
127 test_page(get_page('search=empty'),