conflict.t 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. # Copyright (C) 2006–2015 Alex Schroeder <alex@emacswiki.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. require './t/test.pl';
  16. package OddMuse;
  17. use Test::More tests => 26;
  18. # Using the example files from the diff3 manual
  19. my $lao_file = q{The Way that can be told of is not the eternal Way;
  20. The name that can be named is not the eternal name.
  21. The Nameless is the origin of Heaven and Earth;
  22. The Named is the mother of all things.
  23. Therefore let there always be non-being,
  24. so we may see their subtlety,
  25. And let there always be being,
  26. so we may see their outcome.
  27. The two are the same,
  28. But after they are produced,
  29. they have different names.
  30. };
  31. my $lao_file_1 = q{The Tao that can be told of is not the eternal Tao;
  32. The name that can be named is not the eternal name.
  33. The Nameless is the origin of Heaven and Earth;
  34. The Named is the mother of all things.
  35. Therefore let there always be non-being,
  36. so we may see their subtlety,
  37. And let there always be being,
  38. so we may see their outcome.
  39. The two are the same,
  40. But after they are produced,
  41. they have different names.
  42. };
  43. my $lao_file_2 = q{The Way that can be told of is not the eternal Way;
  44. The name that can be named is not the eternal name.
  45. The Nameless is the origin of Heaven and Earth;
  46. The Named is the mother of all things.
  47. Therefore let there always be non-being,
  48. so we may see their simplicity,
  49. And let there always be being,
  50. so we may see the result.
  51. The two are the same,
  52. But after they are produced,
  53. they have different names.
  54. };
  55. my $tzu_file = q{The Nameless is the origin of Heaven and Earth;
  56. The named is the mother of all things.
  57. Therefore let there always be non-being,
  58. so we may see their subtlety,
  59. And let there always be being,
  60. so we may see their outcome.
  61. The two are the same,
  62. But after they are produced,
  63. they have different names.
  64. They both may be called deep and profound.
  65. Deeper and more profound,
  66. The door of all subtleties!
  67. };
  68. my $tao_file = q{The Way that can be told of is not the eternal Way;
  69. The name that can be named is not the eternal name.
  70. The Nameless is the origin of Heaven and Earth;
  71. The named is the mother of all things.
  72. Therefore let there always be non-being,
  73. so we may see their subtlety,
  74. And let there always be being,
  75. so we may see their result.
  76. The two are the same,
  77. But after they are produced,
  78. they have different names.
  79. -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  80. };
  81. # simple edit
  82. $ENV{'REMOTE_ADDR'} = 'confusibombus';
  83. test_page(update_page('ConflictTest', $lao_file),
  84. 'The Way that can be told of is not the eternal Way');
  85. # edit from another address should result in conflict warning
  86. $ENV{'REMOTE_ADDR'} = 'megabombus';
  87. test_page(update_page('ConflictTest', $tzu_file),
  88. 'The Nameless is the origin of Heaven and Earth');
  89. # test cookie!
  90. test_page($redirect, map { UrlEncode($_); }
  91. ('This page was changed by somebody else',
  92. 'Please check whether you overwrote those changes'));
  93. # test normal merging -- first get oldtime, then do two conflicting edits
  94. # we need to wait at least a second after the last test in order to not
  95. # confuse oddmuse.
  96. sleep(2);
  97. update_page('ConflictTest', $lao_file);
  98. my $oldtime = xpath_test(get_page('action=edit id=ConflictTest'),
  99. '//input[@name="oldtime"]/attribute::value');
  100. sleep(2);
  101. $ENV{'REMOTE_ADDR'} = 'confusibombus';
  102. update_page('ConflictTest', $lao_file_1);
  103. sleep(2);
  104. # merge success has lines from both lao_file_1 and lao_file_2
  105. $ENV{'REMOTE_ADDR'} = 'megabombus';
  106. test_page(update_page('ConflictTest', $lao_file_2,
  107. '', '', '', "oldtime=$oldtime"),
  108. 'The Tao that can be told of', # file 1
  109. 'The name that can be named', # both
  110. 'so we may see their simplicity'); # file 2
  111. # test conflict during merging -- first get oldtime, then do two conflicting edits
  112. sleep(2);
  113. update_page('ConflictTest', $tzu_file);
  114. $oldtime = xpath_test(get_page('action=edit id=ConflictTest'),
  115. '//input[@name="oldtime"]/attribute::value');
  116. sleep(2);
  117. $ENV{'REMOTE_ADDR'} = 'confusibombus';
  118. update_page('ConflictTest', $tao_file);
  119. sleep(2);
  120. $ENV{'REMOTE_ADDR'} = 'megabombus';
  121. test_page(update_page('ConflictTest', $lao_file,
  122. '', '', '', "oldtime=$oldtime"),
  123. q{<pre class="conflict">&lt;&lt;&lt;&lt;&lt;&lt;&lt; ancestor
  124. =======
  125. The Way that can be told of is not the eternal Way;
  126. The name that can be named is not the eternal name.
  127. &gt;&gt;&gt;&gt;&gt;&gt;&gt; other
  128. </pre>},
  129. q{<pre class="conflict">&lt;&lt;&lt;&lt;&lt;&lt;&lt; you
  130. ||||||| ancestor
  131. They both may be called deep and profound.
  132. Deeper and more profound,
  133. The door of all subtleties!
  134. =======
  135. -- The Way of Lao-Tzu, tr. Wing-tsit Chan
  136. &gt;&gt;&gt;&gt;&gt;&gt;&gt; other
  137. </pre>});
  138. @Test = split('\n',<<'EOT');
  139. This page was changed by somebody else
  140. The changes conflict
  141. EOT
  142. test_page($redirect, map { UrlEncode($_); } @Test); # test cookie!
  143. # Test conflict during merging without diff3! -- First get oldtime,
  144. # then do two conflicting edits, and notice how merging no longer
  145. # works.
  146. sleep(2);
  147. update_page('ConflictTest', $lao_file);
  148. $oldtime = xpath_test(get_page('action=edit id=ConflictTest'),
  149. '//input[@name="oldtime"]/attribute::value');
  150. sleep(2);
  151. $ENV{'REMOTE_ADDR'} = 'confusibombus';
  152. update_page('ConflictTest', $lao_file_1);
  153. sleep(2);
  154. $ENV{'REMOTE_ADDR'} = 'megabombus';
  155. # We remove diff3 by setting the PATH environment variable to ''.
  156. diag('Warnings saying that diff and diff3 cannot be found are expected because PATH has been unset.');
  157. AppendStringToFile($ConfigFile, "\$ENV{'PATH'} = '';\n");
  158. test_page(update_page('ConflictTest', $lao_file_2,
  159. '', '', '', "oldtime=$oldtime"),
  160. 'The Way that can be told of is not the eternal Way', # file 2 -- no merging!
  161. 'so we may see their simplicity', # file 2
  162. 'so we may see the result'); # file 2
  163. # Rewrite config file and thus restore access to diff and diff3.
  164. write_config_file();
  165. test_page($redirect, map { UrlEncode($_) }
  166. ('This page was changed by somebody else',
  167. 'Please check whether you overwrote those changes')); # test cookie!
  168. # verify that a preview does not loose oldtime
  169. $page = get_page('action=edit id=ConflictTest');
  170. my ($ts, $title, $text) = xpath_test($page,
  171. '//input[@name="oldtime"]/attribute::value',
  172. '//input[@name="title"]/attribute::value',
  173. '//textarea[@name="text"]/text()');
  174. $text = UrlEncode($text);
  175. is(xpath_test(get_page(qq{title="$title" oldtime="$ts" text="$text" Preview=Preview}),
  176. '//input[@name="oldtime"]/attribute::value'),
  177. $ts, 'Timestamp unchanged after a preview');
  178. # now another user changes the file
  179. sleep(2);
  180. $ENV{'REMOTE_ADDR'} = 'confusibombus';
  181. update_page('ConflictTest', $lao_file_1);
  182. # and we run the same preview again, without reloading!
  183. is(xpath_test(get_page(qq{title="$title" oldtime="$ts" text="$text" Preview=Preview}),
  184. '//input[@name="oldtime"]/attribute::value'),
  185. $ts, 'Timestamp of preview still unchanged even though somebody else changed the page');