comments.t 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. # Copyright (C) 2006–2017 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 => 44;
  17. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");
  18. # $EditAllowed
  19. test_page(get_page('Comments_on_Test'),
  20. 'There are no comments, yet. Be the first to leave a comment!');
  21. $page = update_page('Test', 'Can edit page by default');
  22. test_page($page, 'Can edit page by default');
  23. xpath_test($page,
  24. '//a[@class="comment local"][@href="http://localhost/wiki.pl/Comments_on_Test"][text()="Comments on Test"]',
  25. '//a[@class="edit"][@href="http://localhost/wiki.pl?action=edit;id=Test"][text()="Edit this page"]');
  26. $page = update_page('Comments_on_Test', 'Can edit comment by default');
  27. test_page($page, 'Can edit comment by default');
  28. xpath_test($page,
  29. '//a[@class="original local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  30. '//a[@class="edit"][@href="http://localhost/wiki.pl?action=edit;id=Comments_on_Test"][text()="Edit this page"]',
  31. '//textarea[@name="aftertext"]');
  32. # There used to be a bug where we returned status 200 for a non-existing comment
  33. # page if the corresponding page existed. The bug meant that we browsed a page
  34. # with no title.
  35. update_page('Yes', 'test');
  36. test_page(get_page('Comments_on_Yes'),
  37. 'There are no comments, yet. Be the first to leave a comment!');
  38. AppendStringToFile($ConfigFile, "\$EditAllowed = 0;\n");
  39. $page = update_page('Test', 'Cannot edit page with edit allowed eq 0');
  40. test_page($page, 'Can edit page by default');
  41. xpath_test($page,
  42. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  43. $page = update_page('Comments_on_Test', 'Cannot edit comments with edit allowed eq 0');
  44. test_page($page, 'Can edit comment by default');
  45. xpath_test($page,
  46. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  47. negative_xpath_test($page, '//textarea[@name="aftertext"]');
  48. AppendStringToFile($ConfigFile, "\$EditAllowed = 2;\n");
  49. $page = update_page('Test', 'Cannot edit page with edit allowed eq 2');
  50. test_page($page, 'Can edit page by default');
  51. xpath_test($page,
  52. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  53. $page = update_page('Comments_on_Test', 'Can edit comments with edit allowed eq 2');
  54. test_page($page, 'Can edit comments with edit allowed eq 2');
  55. xpath_test($page,
  56. '//a[@class="original local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  57. '//a[@class="edit"][@href="http://localhost/wiki.pl?action=edit;id=Comments_on_Test"][text()="Edit this page"]',
  58. '//textarea[@name="aftertext"]');
  59. AppendStringToFile($ConfigFile, "\$EditAllowed = 3;\n");
  60. $page = update_page('Test', 'Cannot edit page with edit allowed = 3');
  61. test_page($page, 'Can edit page by default');
  62. xpath_test($page,
  63. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  64. $page = update_page('Comments_on_Test', 'Can edit comments with edit allowed eq 3');
  65. test_page($page, 'Can edit comments with edit allowed eq 2');
  66. xpath_test($page,
  67. '//a[@class="original local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  68. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]',
  69. '//textarea[@name="aftertext"]');
  70. $page = update_page('Comments_on_Test', '', '', 1, '', 'aftertext=Cannot%20add%20minor%20comments%20with%20edit%20allowed%20eq%203');
  71. test_page_negative($page, 'Cannot add minor comments with edit allowed eq 3');
  72. $page = update_page('Comments_on_Test', '', '', '', '', 'aftertext=Can%20add%20comments%20with%20edit%20allowed%20eq%203');
  73. test_page($page, 'Can add comments with edit allowed eq 3');
  74. # Other tests
  75. AppendStringToFile($ConfigFile, "\$EditAllowed = 1;\n");
  76. get_page('title=Yadda', 'aftertext=This%20is%20my%20comment%20on%20an%20ordinary%20page.', 'username=Alex');
  77. test_page(get_page('Yadda'), 'This is my comment on an ordinary page\.');
  78. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20my%20comment%20on%20a%20comment%20page.', 'username=Alex');
  79. test_page(get_page('Comments_on_Yadda'), 'This is my comment on a comment page\.', '-- Alex');
  80. test_page(get_page('action=rc raw=1'), 'title: Comments on Yadda',
  81. 'description: This is my comment on a comment page\.', 'generator: Alex');
  82. # No wiping with empty comment
  83. get_page('title=Comments_on_Yadda', 'aftertext=', 'username=Berta');
  84. $page = get_page('Comments_on_Yadda');
  85. test_page($page, 'This is my comment on a comment page\.');
  86. test_page_negative('Berta');
  87. # No wiping with a comment that evaluates to false
  88. get_page('title=Comments_on_Yadda', 'aftertext=0', 'username=Berta');
  89. test_page(get_page('Comments_on_Yadda'),
  90. 'This is my comment on a comment page\.',
  91. '<p>0</p>',
  92. 'Berta');
  93. # homepage
  94. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20another%20comment.',
  95. 'username=Alex', 'homepage=http%3a%2f%2fwww%2eoddmuse%2eorg%2f');
  96. xpath_test(get_page('Comments_on_Yadda'),
  97. '//p[contains(text(),"This is my comment on a comment page.")]', # not wiped
  98. '//p[contains(text(),"This is another comment.")]', # not wiped
  99. '//a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="Alex"]');
  100. # variant without protocol
  101. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20yet%20another%20comment.',
  102. 'username=Berta', 'homepage=alexschroeder%2ech');
  103. xpath_test(get_page('Comments_on_Yadda'),
  104. '//a[@class="url http outside"][@href="http://alexschroeder.ch"][text()="Berta"]');
  105. my $textarea = '//textarea[@name="aftertext"][@id="aftertext"]';
  106. xpath_test(get_page('Comments_on_Yadda'), $textarea);
  107. get_page('action=pagelock set=1 id=Comments_on_Yadda pwd=foo');
  108. negative_xpath_test(get_page('Comments_on_Yadda'), $textarea);