conflict.t 7.5 KB

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