grep-filtered.t 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. # Copyright (C) 2006–2020 Alex Schroeder <alex@gnu.org>
  2. #
  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.
  7. #
  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.
  12. #
  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/>.
  15. # These tests were copied from search.t...
  16. require './t/test.pl';
  17. package OddMuse;
  18. use Test::More;
  19. use utf8; # tests contain UTF-8 characters and it matters
  20. add_module('grep-filtered.pl');
  21. # Search for broken regular expressions
  22. test_page(get_page('search=%2Btest'), 'Search for: \+test');
  23. # Test search, make sure ordinary users don't see the replacement form
  24. update_page('SearchAndReplace', 'This is fooz and this is barz.', '', 1);
  25. $page = get_page('search=fooz');
  26. test_page($page,
  27. '<h1>Search for: fooz</h1>',
  28. '<p class="result">1 pages found.</p>',
  29. 'This is <strong>fooz</strong> and this is barz.');
  30. xpath_test($page, '//span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/SearchAndReplace"][text()="SearchAndReplace"]');
  31. test_page_negative($page, 'Replace:');
  32. # Search page name
  33. $page = get_page('search=andreplace');
  34. test_page($page,
  35. '<h1>Search for: andreplace</h1>',
  36. '<p class="result">1 pages found.</p>');
  37. # FIXME: Not sure this should work... 'Search<strong>AndReplace</strong>'
  38. xpath_test($page, '//span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/SearchAndReplace"][text()="SearchAndReplace"]');
  39. # Brackets in the page name
  40. test_page(update_page('Search (and replace)', 'Muu'),
  41. 'search=%22Search\+%5c\(and\+replace%5c\)%22');
  42. # Make sure only admins can replace
  43. test_page(get_page('search=foo pwd=foo'),
  44. 'Replace:');
  45. test_page(get_page('search=foo replace=bar'),
  46. 'This operation is restricted to administrators only...');
  47. # Preview simple replacement operation
  48. test_page(get_page('search=fooz replace=fuuz preview=1 pwd=foo'), split('\n',<<'EOT'));
  49. <h1>Preview: fooz &#x2192; fuuz</h1>
  50. <p class="result">1 pages found.</p>
  51. <div class="old"><p>&lt; This is <strong class="changes">fooz</strong> and this is barz.
  52. <div class="new"><p>&gt; This is <strong class="changes">fuuz</strong> and this is barz.
  53. EOT
  54. # Verify that the change has not been made
  55. test_page(get_page('SearchAndReplace'), 'This is fooz and this is barz.');
  56. # Simple replace where the replacement pattern is found
  57. test_page(get_page('search=fooz replace=fuuz pwd=foo'), split('\n',<<'EOT'));
  58. <h1>Replaced: fooz &#x2192; fuuz</h1>
  59. <p class="result">1 pages found.</p>
  60. This is <strong>fuuz</strong> and this is barz.
  61. EOT
  62. # Verify that the change has been made
  63. test_page(get_page('SearchAndReplace'), 'This is fuuz and this is barz.');
  64. # Replace with empty string
  65. test_page(get_page('search=this%20is%20 replace= pwd=foo delete=1'), split('\n',<<'EOT'));
  66. <h1>Replaced: this is &#x2192; </h1>
  67. <p class="result">1 pages found.</p>
  68. fuuz and barz.
  69. EOT
  70. test_page(get_page('SearchAndReplace'), '<p>fuuz and barz.');
  71. # Creating 12 pages
  72. for my $i ('A' .. 'M') {
  73. OpenPage("Page_$i");
  74. Save("Page_$i", 'Something');
  75. }
  76. # Testing default pagination (10 pages)
  77. $page = get_page('search=Something replace=Other preview=1 pwd=foo');
  78. test_page($page, split('\n',<<'EOT'));
  79. <h1>Preview: Something &#x2192; Other</h1>
  80. <p class="result">13 pages found.</p>
  81. <div class="old"><p>&lt; <strong class="changes">Something</strong>
  82. <div class="new"><p>&gt; <strong class="changes">Other</strong>
  83. EOT
  84. test_page($page, map { "Page_$_" } ('A' .. 'J'));
  85. test_page_negative($page, map { "Page_$_" } ('K' .. 'M'));
  86. xpath_test($page, '//a[@class="more"][@href="http://localhost/wiki.pl?search=Something;preview=1;offset=10;num=10;replace=Other"]');
  87. # Next page
  88. $page = get_page('search=Something preview=1 offset=10 num=10 replace=Other pwd=foo');
  89. test_page($page, map { "Page_$_" } ('K' .. 'M'));
  90. # Now do the replacement
  91. $page = get_page('search=Something replace=Other pwd=foo');
  92. test_page($page, 'Replaced: Something &#x2192; Other', '13 pages found',
  93. map { "Page_$_" } ('A' .. 'M'));
  94. # Verify that the change has been made
  95. test_page(get_page('search=Other'), 'Search for: Other', '13 pages found');
  96. # Replace with backreferences, where the replacement pattern is no longer found.
  97. # Take 'fuuz and barz.' and replace ([a-z]+)z with x$1 results in 'xfuu and xbar.'
  98. test_page(get_page('"search=([a-z]%2b)z" replace=x%241 pwd=foo'), '1 pages found');
  99. test_page(get_page('SearchAndReplace'), 'xfuu and xbar.');
  100. # Create an extra page that should not be found
  101. update_page('NegativeSearchTest', 'this page contains an ab');
  102. update_page('NegativeSearchTestTwo', 'this page contains another ab');
  103. test_page(get_page('search=xb replace=[xa]b pwd=foo'), '1 pages found'); # not two ab!
  104. test_page(get_page('SearchAndReplace'), 'xfuu and \[xa\]bar.');
  105. # Handle quoting
  106. test_page(get_page('search=xfuu replace=/fuu/ pwd=foo'), '1 pages found'); # not two ab!
  107. test_page(get_page('SearchAndReplace'), '/fuu/ and \[xa\]bar.');
  108. test_page(get_page('search=/fuu/ replace={{fuu}} pwd=foo'), '1 pages found');
  109. test_page(get_page('SearchAndReplace'), '\{\{fuu\}\} and \[xa\]bar.');
  110. # Check headers especially the quoting of non-ASCII characters.
  111. $page = update_page("Alexander_Schröder", "Edit [[Alexander Schröder]]!");
  112. xpath_test($page,
  113. '//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') . '"]',
  114. '//a[@class="local"][@href="http://localhost/wiki.pl/Alexander_Schr%c3%b6der"][text()="Alexander Schröder" or text()="' . Encode::encode_utf8('Alexander Schröder') . '"]');
  115. xpath_test(update_page('IncludeSearch',
  116. "first line\n<search \"ab\">\nlast line"),
  117. '//p[text()="first line "]', # note the NL -> SPC
  118. '//div[@class="search"]/p/span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/NegativeSearchTest"][text()="NegativeSearchTest"]',
  119. '//div[@class="search"]/p/span[@class="result"]/a[@class="local"][@href="http://localhost/wiki.pl/NegativeSearchTestTwo"][text()="NegativeSearchTestTwo"]',
  120. '//p[text()=" last line"]'); # note the NL -> SPC
  121. xpath_test(get_page('search=Schröder'),
  122. '//input[@name="search"][@value="Schröder"]');
  123. # Search for zero
  124. update_page("Zero", "This is about 0 and the empty string ''.");
  125. test_page(get_page('search=0'),
  126. '<h1>Search for: 0</h1>',
  127. '<p class="result">1 pages found.</p>',
  128. "This is about <strong>0</strong> and the empty string ''.",
  129. 'meta name="robots" content="NOINDEX,FOLLOW"');
  130. # Search for tags
  131. update_page("Tag", "This is <b>bold</b>.");
  132. test_page(get_page('search="<b>"'),
  133. '<h1>Search for: &lt;b&gt;</h1>',
  134. '<p class="result">1 pages found.</p>',
  135. "This is <strong>&lt;b&gt;</strong>.");
  136. # Search for quoted strings
  137. update_page("Tugend", "Ein wirklich tugendhafter Mensch
  138. bemüht sich nicht um seine Tugend,
  139. darum ist er tugendhaft.");
  140. update_page("Laster", "Ein scheinbar tugendhafter Mensch
  141. bemüht sich dauernd um seine Tugend,
  142. darum ist er nicht wirklich tugendhaft.");
  143. # unordered words
  144. test_page(get_page('search="darum ist er tugendhaft" raw=1'),
  145. 'title: Tugend', 'title: Laster');
  146. # in order
  147. $page = get_page('search="\"darum ist er tugendhaft\"" raw=1');
  148. test_page($page, 'title: Tugend');
  149. test_page_negative($page, 'title: Laster');
  150. done_testing;