namespaces.t 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. # Copyright (C) 2006–2019 Alex Schroeder <alex@gnu.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify it under
  4. # the terms of the GNU General Public License as published by the Free Software
  5. # Foundation; either version 3 of the License, or (at your option) any later
  6. # version.
  7. #
  8. # This program is distributed in the hope that it will be useful, but WITHOUT
  9. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  10. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. require './t/test.pl';
  15. package OddMuse;
  16. use Test::More tests => 89;
  17. use utf8; # tests contain UTF-8 characters and it matters
  18. add_module('namespaces.pl');
  19. AppendStringToFile($ConfigFile, "\$WikiLinks = 1;\n");
  20. test_page_negative(get_page('/Test?username=alex'), 'Wiki Test: Test');
  21. # editing pages
  22. test_page(get_page('Test'),
  23. '<title>Wiki: Test</title>',
  24. 'Status: 404 NOT FOUND');
  25. test_page(update_page('Test', 'Muuu!', 'main ns', undef, undef,
  26. 'username=Alex'),
  27. '<p>Muuu!</p>');
  28. test_page(get_page('action=browse id=Test ns=Muu'),
  29. '<title>Wiki Muu: Test</title>',
  30. 'Status: 404 NOT FOUND');
  31. test_page(update_page('Test', 'Mooo!', 'muu ns', undef, undef,
  32. 'ns=Muu', 'username=Berta'),
  33. '<title>Wiki Muu: Test</title>',
  34. '<p>Mooo!</p>');
  35. test_page(get_page('action=browse id=Test ns=Muu'),
  36. '<title>Wiki Muu: Test</title>',
  37. '<p>Mooo!</p>');
  38. # history
  39. xpath_test(get_page('action=history id=Test ns=Muu'),
  40. '//table[@class="history"]/tr/td/a[text()="Revision 1"]',
  41. '//h1[text()="History of Test"]');
  42. test_page(get_page('action=history id=Test ns=Muu raw=1'),
  43. "link: http://localhost/wiki.pl/Muu\\?action=history;id=Test;raw=1\n",
  44. "link: http://localhost/wiki.pl/Muu/Test\n");
  45. # search
  46. $page = get_page('/Muu?search=Mooo raw=1');
  47. test_page($page, 'description: Mooo!');
  48. test_page_negative($page, 'description: Muuu!');
  49. $page = get_page('search=Muuu raw=1');
  50. test_page_negative($page, 'description: Mooo!');
  51. test_page($page, 'description: Muuu!');
  52. # recent changes
  53. test_page(get_page('action=rc raw=1'),
  54. 'generator: Alex',
  55. 'generator: Muu:Berta');
  56. xpath_test(get_page('action=rc'),
  57. '//a[@class="author"][text()="Alex"][@href="http://localhost/wiki.pl/Alex"]',
  58. '//a[@class="author"][text()="Muu:Berta"][@href="http://localhost/wiki.pl/Muu/Berta"]');
  59. # redirect from Main:Mu to Muu:Mu
  60. update_page('Mu', '#REDIRECT Muu:Mu');
  61. test_page(get_page('action=browse id=Mu'),
  62. 'Status: 302',
  63. 'Location: http://localhost/wiki.pl\?action=browse;ns=Muu;oldid=Main:Mu;id=Mu');
  64. # check the edit link
  65. xpath_test(get_page('action=browse id=Mu ns=Muu oldid=Main:Mu'),
  66. '//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl?action=edit;id=Mu"][text()="Main:Mu"]');
  67. # redirect from Muu:Mu
  68. update_page('Mu', '#REDIRECT Ford:Goo', undef, undef, undef, 'ns=Muu');
  69. test_page(get_page('action=browse id=Mu ns=Muu'),
  70. 'Status: 302',
  71. 'Location: http://localhost/wiki.pl\?action=browse;ns=Ford;oldid=Muu:Mu;id=Goo');
  72. # check the edit link
  73. xpath_test(get_page('action=browse id=Goo ns=Ford oldid=Muu:Mu'),
  74. '//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl/Muu?action=edit;id=Mu"][text()="Muu:Mu"]');
  75. # check Main:Mu and verify that only a single redirection hop is allowed
  76. xpath_test(get_page('action=browse id=Mu ns=Muu oldid=Main:Mu'),
  77. '//div/p[contains(text(),"#REDIRECT")]/a[@href="http://localhost/wiki.pl/Ford/Goo"][@class="inter Ford"]/span[@class="site"][text()="Ford"]/following-sibling::span[@class="interpage"][text()="Goo"]');
  78. # redirecting back to the Main namespace is different, so test separately
  79. test_page(update_page('BackHome', '#REDIRECT Main:HomePage', undef, undef, undef, 'ns=Muu'),
  80. 'Status: 302',
  81. 'Location: http://localhost/wiki.pl\?action=browse;ns=Main;oldid=Muu:BackHome;id=HomePage');
  82. # check the edit link
  83. xpath_test(get_page('action=browse id=HomePage ns=Main oldid=Muu:BackHome'),
  84. '//div[@class="message"]/p[contains(text(),"redirected from")]/a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl/Muu?action=edit;id=BackHome"][text()="Muu:BackHome"]');
  85. # continue with regular tests
  86. test_page(get_page('action=browse id=Test ns=Main'),
  87. '<title>Wiki: Test</title>',
  88. '<p>Muuu!</p>');
  89. test_page(get_page('action=rc raw=1'),
  90. 'description: main ns',
  91. 'description: muu ns');
  92. test_page_negative(get_page('action=rc raw=1 local=1'),
  93. 'description: muu ns');
  94. test_page(get_page('action=rc raw=1 ns=Muu'),
  95. 'description: muu ns');
  96. test_page_negative(get_page('action=rc raw=1 ns=Muu'),
  97. 'description: main ns');
  98. # add two more edits so that RC will show diff links
  99. update_page('Test', 'Another Muuu!', 'main ns');
  100. update_page('Test', 'Another Mooo!', 'muu ns', undef, undef, 'ns=Muu');
  101. xpath_test(get_page('action=rc'),
  102. '//a[@class="local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  103. '//a[@class="history"][@href="http://localhost/wiki.pl?action=history;id=Test"][text()="history"]',
  104. '//a[@class="diff"][@href="http://localhost/wiki.pl?action=browse;diff=1;id=Test"][text()="diff"]',
  105. '//a[@class="local"][@href="http://localhost/wiki.pl/Muu/Test"][text()="Muu:Test"]',
  106. '//a[@class="history"][@href="http://localhost/wiki.pl/Muu?action=history;id=Test"][text()="history"]',
  107. '//a[@class="diff"][@href="http://localhost/wiki.pl/Muu?action=browse;diff=1;id=Test"][text()="diff"]',
  108. );
  109. test_page(get_page('action=rss'),
  110. '<title>Muu:Mu</title>',
  111. '<link>http://localhost/wiki.pl/Muu/Mu</link>',
  112. '<wiki:history>http://localhost/wiki.pl/Muu\?action=history;id=Mu</wiki:history>',
  113. '<wiki:diff>http://localhost/wiki.pl/Muu\?action=browse;diff=1;id=Mu</wiki:diff>');
  114. # Test Unicode characters in namespaces (BLACK HEART SUIT)
  115. test_page(update_page('Ümlaute', 'namespace mit herz',
  116. 'wo steckt das ü', undef, undef,
  117. 'ns=Zürich♥'), 'namespace mit herz');
  118. xpath_test(get_page('action=rc'),
  119. # the exact result depends on filesystem encoding!
  120. '//a[@class="local"][@href="http://localhost/wiki.pl/Z%c3%bcrich%e2%99%a5/%c3%9cmlaute"]');
  121. # Test potential Latin-1 characters in namespaces (LATIN SMALL LETTER U DIAERESIS)
  122. test_page(update_page('Ümlaute', 'namespace mit umlaut',
  123. 'wo steckt das ü', undef, undef,
  124. 'ns=Zürich'), 'namespace mit umlaut');
  125. xpath_test(get_page('action=rc'),
  126. # the exact result depends on filesystem encoding!
  127. '//a[@class="local"][@href="http://localhost/wiki.pl/Z%c3%bcrich/%c3%9cmlaute"]');
  128. # And using path_info
  129. test_page(get_page('/Zürich/Ümlaute?'),
  130. 'namespace mit umlaut');
  131. # Test rollbacks
  132. test_page(get_page('action=browse ns=Muu id=Test'),
  133. 'Another Mooo!');
  134. # find first (and only rollback link) for Muu/Test
  135. $to = xpath_test(get_page('action=history id=Test ns=Muu username=Alex'),
  136. '//input[@value="rollback"]/attribute::name');
  137. $to =~ /rollback-([0-9]+)/;
  138. $to = $1;
  139. ok($to > 0, 'found rollback link for Muu/Test');
  140. # do the rollback
  141. test_page(get_page("action=rollback ns=Muu id=Test to=$to username=Alex"),
  142. 'Rolling back changes', 'Test</a> rolled back');
  143. $page = get_page('action=browse ns=Muu id=Test');
  144. test_page_negative($page, 'Another Mooo!');
  145. test_page($page, 'Mooo!');
  146. # verify feed
  147. test_page(get_page('action=rc ns=Muu raw=1'),
  148. 'title: Wiki Muu', 'title: Test', 'title: BackHome');
  149. # now roll back all the pages in the namespace
  150. update_page('Test', 'spam spam spam', 'spam', undef, undef, 'ns=Muu');
  151. # test it with path_info instead of ns parameter
  152. test_page(get_page("'/Muu?rollback-$to=rollback' 'username=Alex' 'pwd=foo'"),
  153. 'Rolling back changes', 'Test</a> rolled back');
  154. $page = get_page('action=browse ns=Muu id=Test');
  155. test_page_negative($page, 'spam');
  156. test_page($page, 'Mooo!');
  157. # verify that local RecentChanges doesn't show anything
  158. test_page_negative(get_page('action=rc ns=Muu raw=1'), 'Rollback');
  159. # verify that global RecentChanges doesn't show anything
  160. test_page_negative(get_page('action=rc raw=1'), 'Rollback');
  161. # test oldrc.log reading
  162. ok(rename("$DataDir/Muu/rc.log", "$DataDir/Muu/oldrc.log"),
  163. "renamed $RcFile to $RcOldFile in the Muu namespace");
  164. # verify the feed
  165. my $feed = get_page('action=rc ns=Muu raw=1');
  166. test_page($feed, 'title: Wiki Muu', 'title: Test');
  167. # this page was now rolled back out of existence
  168. test_page_negative($feed, 'title: BackHome');
  169. # check the entire wiki, too
  170. $feed = get_page('action=rc raw=1');
  171. test_page($feed, 'title: Wiki', 'title: Muu:Test');
  172. # BackHome never existed and Muu:BackHome was rolled back
  173. test_page_negative($feed, 'title: Muu:BackHome', 'title: BackHome');
  174. AppendStringToFile($ConfigFile, <<'EOT');
  175. $InterSitePattern = '[\p{Uppercase}\d][\w_ ]*';
  176. $InterLinkPattern = "($InterSitePattern:[-a-zA-Z0-9\x{0080}-\x{fffd}_=!?#\$\@~`\%&*+\\/:;.,]*[-a-zA-Z0-9\x{0080}-\x{fffd}_=#\$\@~`\%&*+\\/])$QDelim";
  177. $FreeInterLinkPattern = "($InterSitePattern:[-a-zA-Z0-9\x{0080}-\x{fffd}_=!?#\$\@~`\%&*+\\/:;.,()' ]+)";
  178. EOT
  179. test_page(update_page('Bond', 'My name is Bond', '007 ns', undef, undef,
  180. 'ns=007', 'username=James'),
  181. '<title>Wiki 007: Bond</title>',
  182. '<p>My name is Bond</p>');
  183. test_page(get_page('action=browse id=Bond ns=007'),
  184. '<title>Wiki 007: Bond</title>',
  185. '<p>My name is Bond</p>');
  186. # BannedHosts are shared! Editing the BannedHosts in a namespace results in the root BannedHosts getting written.
  187. test_page(update_page('BannedHosts', '^127\.0\.0\.1', 'ban myself', undef, 1, 'ns=007', 'username=James'),
  188. '<title>Wiki 007: Banned Hosts</title>', 'This page does not exist');
  189. test_page(get_page('BannedHosts'), quotemeta('^127\.0\.0\.1'));
  190. test_page(update_page('Mr._Q', 'Hello'), 'This page does not exist');
  191. test_page(update_page('Mr._Q', 'Hello', undef, undef, undef, 'ns=007'), 'This page does not exist');
  192. test_page(update_page('Mr._Q', 'Hello', undef, undef, undef, 'ns=008'), 'This page does not exist');
  193. update_page('BannedHosts', '', 'unban myself', undef, 1);
  194. test_page(update_page('Mr._Q', 'Hello'), 'Hello');