namespaces.t 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # Copyright (C) 2006–2015 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 => 77;
  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('Umlaute', '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/Umlaute"]');
  121. # Test potential Latin-1 characters in namespaces (LATIN SMALL LETTER U DIAERESIS)
  122. test_page(update_page('Umlaute', '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/Umlaute"]');
  128. # Test rollbacks
  129. test_page(get_page('action=browse ns=Muu id=Test'),
  130. 'Another Mooo!');
  131. # find first (and only rollback link) for Muu/Test
  132. $to = xpath_test(get_page('action=history id=Test ns=Muu username=Alex'),
  133. '//input[@value="rollback"]/attribute::name');
  134. $to =~ /rollback-([0-9]+)/;
  135. $to = $1;
  136. ok($to > 0, 'found rollback link for Muu/Test');
  137. # do the rollback
  138. test_page(get_page("action=rollback ns=Muu id=Test to=$to username=Alex"),
  139. 'Rolling back changes', 'Test</a> rolled back');
  140. $page = get_page('action=browse ns=Muu id=Test');
  141. test_page_negative($page, 'Another Mooo!');
  142. test_page($page, 'Mooo!');
  143. # verify feed
  144. test_page(get_page('action=rc ns=Muu raw=1'),
  145. 'title: Wiki Muu', 'title: Test', 'title: BackHome');
  146. # now roll back all the pages in the namespace
  147. update_page('Test', 'spam spam spam', 'spam', undef, undef, 'ns=Muu');
  148. # test it with path_info instead of ns parameter
  149. test_page(get_page("'/Muu?rollback-$to=rollback' 'username=Alex' 'pwd=foo'"),
  150. 'Rolling back changes', 'Test</a> rolled back');
  151. $page = get_page('action=browse ns=Muu id=Test');
  152. test_page_negative($page, 'spam');
  153. test_page($page, 'Mooo!');
  154. # verify that local RecentChanges doesn't show anything
  155. test_page_negative(get_page('action=rc ns=Muu raw=1'), 'Rollback');
  156. # verify that global RecentChanges doesn't show anything
  157. test_page_negative(get_page('action=rc raw=1'), 'Rollback');
  158. # test oldrc.log reading
  159. ok(rename("$DataDir/Muu/rc.log", "$DataDir/Muu/oldrc.log"),
  160. "renamed $RcFile to $RcOldFile in the Muu namespace");
  161. # verify the feed
  162. my $feed = get_page('action=rc ns=Muu raw=1');
  163. test_page($feed, 'title: Wiki Muu', 'title: Test');
  164. # this page was now rolled back out of existence
  165. test_page_negative($feed, 'title: BackHome');
  166. # check the entire wiki, too
  167. $feed = get_page('action=rc raw=1');
  168. test_page($feed, 'title: Wiki', 'title: Muu:Test');
  169. # BackHome never existed and Muu:BackHome was rolled back
  170. test_page_negative($feed, 'title: Muu:BackHome', 'title: BackHome');