edit-paragraphs.t 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. # Copyright (C) 2014 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 => 56;
  17. use utf8;
  18. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");
  19. add_module('edit-paragraphs.pl');
  20. my $text = q{Give me a torch: I am not for this ambling;
  21. Being but heavy, I will bear the light.
  22. Nay, gentle Romeo, we must have you dance.
  23. Not I, believe me: you have dancing shoes
  24. With nimble soles: I have a soul of lead
  25. So stakes me to the ground I cannot move.
  26. };
  27. my $page = update_page('Romeo_and_Mercutio', $text);
  28. for my $paragraph (split(/\n\n+/, $text)) {
  29. test_page($page, 'action=edit-paragraph;title=Romeo_and_Mercutio;around=\d*;paragraph='
  30. . UrlEncode($paragraph));
  31. }
  32. # Check whether the form is right.
  33. ok($page =~ /action=edit-paragraph;title=Romeo_and_Mercutio;around=(\d*);paragraph=([^"]*)/, 'found example link to use');
  34. my $around = $1;
  35. my $enc = $2;
  36. my $par = UrlDecode($enc);
  37. xpath_test(get_page("action=edit-paragraph title=Romeo_and_Mercutio around=$around paragraph=$enc"),
  38. q'//input[@type="hidden"][@value="Romeo_and_Mercutio"][@name="title"]',
  39. q'//input[@type="hidden"][@value="edit-paragraph"][@name="action"]',
  40. qq'//textarea[text()="$par"]',
  41. qq'//input[\@type="hidden"][\@value="$around"][\@name="around"]');
  42. # Test for extra links in empty paragraphs before and after tables.
  43. add_module('creole.pl');
  44. $text = q{|PARIS |JULIET |
  45. |Come you to make confession to this father? |To answer that, I should confess to you. |
  46. |Do not deny to him that you love me. |I will confess to you that I love him. |
  47. |So will ye, I am sure, that you love me. | |
  48. -- William Shakespeare, Romeo and Juliet, Act IV, Scene I
  49. };
  50. $page = update_page('Paris_and_Juliet', $text);
  51. test_page_negative($page, '\|', '</table><p><a ');
  52. for my $row (split(/\n/, $text)) {
  53. test_page($page, 'action=edit-paragraph;title=Paris_and_Juliet;around=\d*;paragraph='
  54. . UrlEncode($row));
  55. }
  56. $text = q{== Romeo and Juliet, Act III, Scene II
  57. * Tybalt is gone, and Romeo banished;
  58. Romeo that kill'd him, he is banished.
  59. * O God! did Romeo's hand shed Tybalt's blood?
  60. * It did, it did; alas the day, it did!
  61. };
  62. $page = update_page('Nurse_and_Juliet', $text);
  63. for my $item (split(/\n(?=[*])/, $text)) {
  64. my $str = UrlEncode($item);
  65. $str =~ s/\*/\\*/g;
  66. test_page($page, 'action=edit-paragraph;title=Nurse_and_Juliet;around=\d*;paragraph='
  67. . $str);
  68. }
  69. $text = q{Benvolio: Tell me in sadness, who is that you love.
  70. Romeo: What, shall I groan and tell thee?
  71. Benvolio: Groan! why, no. But sadly tell me who.
  72. Romeo: Bid a sick man in sadness make his will: Ah, word ill urged to
  73. one that is so ill! In sadness, cousin, I do love a woman.
  74. Benvolio: I aim'd so near, when I supposed you loved.
  75. Romeo: A right good mark-man! And she's fair I love.
  76. Benvolio: A right fair mark, fair coz, is soonest hit.
  77. };
  78. # Replace the first occurence.
  79. test_page(update_page('Benvolio_and_Romeo', $text),
  80. 'Benvolio: Tell me in sadness');
  81. test_page(get_page('action=edit-paragraph title=Benvolio_and_Romeo '
  82. . 'around=0 paragraph=Benvolio text=Ben'),
  83. # not using update_page because of the parameters
  84. 'Status: 302');
  85. test_page(get_page('Benvolio_and_Romeo'),
  86. 'Ben: Tell me in sadness',
  87. 'Benvolio: Groan!');
  88. # Reset and try again but replace the occurence around 105.
  89. update_page('Benvolio_and_Romeo', $text);
  90. test_page(get_page('action=edit-paragraph title=Benvolio_and_Romeo '
  91. . 'around=105 '
  92. . 'paragraph=Benvolio text=Ben'),
  93. # not using update_page because of the parameters
  94. 'Status: 302');
  95. test_page(get_page('Benvolio_and_Romeo'),
  96. 'Benvolio: Tell me in sadness',
  97. 'Ben: Groan!');
  98. SKIP: {
  99. skip "We don't do fuzzy matching anymore.", 3;
  100. # Try again but now let's simulate a page changed in the background
  101. # such that the text is now not exactly at the expected position, but
  102. # close by.
  103. $text =~ s/tell thee/tell you/;
  104. update_page('Benvolio_and_Romeo', $text);
  105. test_page(get_page('action=edit-paragraph title=Benvolio_and_Romeo '
  106. . 'around=105 '
  107. . 'paragraph=Benvolio text=Ben'),
  108. # not using update_page because of the parameters
  109. 'Status: 302');
  110. test_page(get_page('Benvolio_and_Romeo'),
  111. 'Benvolio: Tell me in sadness',
  112. 'Ben: Groan!');
  113. }
  114. # HTML encoding.
  115. $text = q{I am hurt.
  116. <em>A plague o' both your houses!</em> I am sped.
  117. };
  118. xpath_test(get_page('action=edit-paragraph title=Mercutio paragraph="' . UrlEncode($text) . '"'),
  119. qq'//textarea[text()="$text"]');
  120. # Make sure the link at the very end is shown.
  121. $text = q{
  122. {{{
  123. BENVOLIO Romeo, away, be gone!
  124. The citizens are up, and Tybalt slain.
  125. Stand not amazed: the prince will doom thee death,
  126. If thou art taken: hence, be gone, away!
  127. ROMEO O, I am fortune's fool!
  128. }}}
  129. ----
  130. William Shakespeare, Romeo and Juliet, Act III, Scene I
  131. };
  132. $page = update_page('Benvolio_and_Romeo', $text);
  133. test_page_negative($page, '</pre><p><a ', '<p><a ');
  134. test_page($page, 'fool!<a ', '</pre><hr ?/><p>William', 'Scene I<a');
  135. # Mixed lists.
  136. $text = q{* One
  137. ## Two
  138. };
  139. $page = update_page('Alex_Daniel', $text);
  140. for my $item (split(/\n(?=[\*\#])/, $text)) {
  141. my $str = UrlEncode($item);
  142. $str =~ s/\*/\\*/g;
  143. test_page($page, 'action=edit-paragraph;title=Alex_Daniel;around=\d*;paragraph='
  144. . $str);
  145. }
  146. # Comments, the last element in particular.
  147. $text = q{Test
  148. -- Anonymous
  149. ----
  150. Test
  151. -- Real Anonymous
  152. };
  153. $page = update_page('Comments_on_Alex_Daniel', $text);
  154. test_page($page, 'action=edit-paragraph;title=Comments_on_Alex_Daniel;around=\d*;paragraph=--%20Real%20Anonymous%0a');
  155. # More than one newline at the end.
  156. $text = q{one
  157. two
  158. };
  159. $page = update_page('Alex_Daniel', $text);
  160. for my $item (split(/\n+/, $text)) {
  161. my $str = UrlEncode($item);
  162. $str =~ s/\*/\\*/g;
  163. test_page($page, 'action=edit-paragraph;title=Alex_Daniel;around=\d*;paragraph='
  164. . $str);
  165. }
  166. # More HTML encoding.
  167. $text = q{Test.
  168. <test1>
  169. <test2>
  170. <test3>
  171. };
  172. $page = update_page('Test', $text);
  173. test_page_negative(get_page('action=browse id=Test raw=1'), '&lt;');
  174. # HTML encoded text is longer: every < > counts adds 3. Thus 33 + 6x3 = 51.
  175. my $action = 'action=edit-paragraph;title=Test;around=51;paragraph=' . UrlEncode("<test3>\n");
  176. test_page($page, $action);
  177. test_page(get_page(join(' ', split(';', $action))), QuoteHtml("<test3>\n"));
  178. # test error
  179. test_page(get_page('action=edit-paragraph title=Test'
  180. . ' paragraph=' . UrlEncode("<test3>\n") # old
  181. . ' text=' . UrlEncode("<test30>\n") # new
  182. . ' around=1'),
  183. 'Could not identify the paragraph you were editing',
  184. '<pre>' . QuoteHtml("<test3>\n") . '</pre>');
  185. test_page(get_page('action=edit-paragraph title=Test'
  186. . ' paragraph=' . UrlEncode("<test3>\n") # old
  187. . ' text=' . UrlEncode("<test30>\n") # new
  188. . ' around=51'), 'Status: 302');
  189. $text =~ s/test3/test30/;
  190. test_page(get_page('action=browse id=Test raw=1'), $text);
  191. # ampersand in a pagename
  192. $text = q{d4
  193. d5
  194. d8
  195. d10
  196. };
  197. $page = update_page('D%26D', $text);
  198. my $action = 'action=edit-paragraph;title=D%26D;around=8;paragraph=d5%0a%0a';
  199. test_page($page, $action);
  200. test_page(get_page(join(' ', split(';', $action))), 'd5');
  201. # test error
  202. test_page(get_page('action=edit-paragraph title=D%26D'
  203. . ' paragraph=d5%0a%0a' # old
  204. . ' text=d6%0a%0a' # new
  205. . ' around=8'),
  206. 'Status: 302');
  207. $text =~ s/d5/d6/;
  208. test_page(get_page('action=browse id=D%26D raw=1'), $text);
  209. # questionmark, square brackets, bullet lists in the edited text
  210. $text = q{* who?
  211. * [where]?
  212. * why?
  213. * what?
  214. };
  215. $page = update_page('Questions', $text);
  216. my $action = 'action=edit-paragraph;title=Questions;around=18;paragraph=*%20%5bwhere%5d%3f%0a';
  217. test_page($page, quotemeta($action));
  218. test_page(get_page(join(' ', split(';', $action))), '\[where\]\?');
  219. # test error
  220. test_page(get_page('action=edit-paragraph title=Questions'
  221. . ' paragraph=*%20%5bwhere%5d%3f%0a' # old
  222. . ' text=*%20how%3f%0a' # new
  223. . ' around=18'),
  224. 'Status: 302');
  225. $text =~ s/\[where\]\?/how?/;
  226. test_page(get_page('action=browse id=Questions raw=1'), quotemeta($text));