comments.t 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 => 43;
  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. AppendStringToFile($ConfigFile, "\$EditAllowed = 0;\n");
  33. $page = update_page('Test', 'Cannot edit page with edit allowed eq 0');
  34. test_page($page, 'Can edit page by default');
  35. xpath_test($page,
  36. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  37. $page = update_page('Comments_on_Test', 'Cannot edit comments with edit allowed eq 0');
  38. test_page($page, 'Can edit comment by default');
  39. xpath_test($page,
  40. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  41. negative_xpath_test($page, '//textarea[@name="aftertext"]');
  42. AppendStringToFile($ConfigFile, "\$EditAllowed = 2;\n");
  43. $page = update_page('Test', 'Cannot edit page with edit allowed eq 2');
  44. test_page($page, 'Can edit page by default');
  45. xpath_test($page,
  46. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  47. $page = update_page('Comments_on_Test', 'Can edit comments with edit allowed eq 2');
  48. test_page($page, 'Can edit comments with edit allowed eq 2');
  49. xpath_test($page,
  50. '//a[@class="original local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  51. '//a[@class="edit"][@href="http://localhost/wiki.pl?action=edit;id=Comments_on_Test"][text()="Edit this page"]',
  52. '//textarea[@name="aftertext"]');
  53. AppendStringToFile($ConfigFile, "\$EditAllowed = 3;\n");
  54. $page = update_page('Test', 'Cannot edit page with edit allowed = 3');
  55. test_page($page, 'Can edit page by default');
  56. xpath_test($page,
  57. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]');
  58. $page = update_page('Comments_on_Test', 'Can edit comments with edit allowed eq 3');
  59. test_page($page, 'Can edit comments with edit allowed eq 2');
  60. xpath_test($page,
  61. '//a[@class="original local"][@href="http://localhost/wiki.pl/Test"][text()="Test"]',
  62. '//a[@class="password"][@href="http://localhost/wiki.pl?action=password"][text()="This page is read-only"]',
  63. '//textarea[@name="aftertext"]');
  64. $page = update_page('Comments_on_Test', '', '', 1, '', 'aftertext=Cannot%20add%20minor%20comments%20with%20edit%20allowed%20eq%203');
  65. test_page_negative($page, 'Cannot add minor comments with edit allowed eq 3');
  66. $page = update_page('Comments_on_Test', '', '', '', '', 'aftertext=Can%20add%20comments%20with%20edit%20allowed%20eq%203');
  67. test_page($page, 'Can add comments with edit allowed eq 3');
  68. # Other tests
  69. AppendStringToFile($ConfigFile, "\$EditAllowed = 1;\n");
  70. get_page('title=Yadda', 'aftertext=This%20is%20my%20comment%20on%20an%20ordinary%20page.', 'username=Alex');
  71. test_page(get_page('Yadda'), 'This is my comment on an ordinary page\.');
  72. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20my%20comment%20on%20a%20comment%20page.', 'username=Alex');
  73. test_page(get_page('Comments_on_Yadda'), 'This is my comment on a comment page\.', '-- Alex');
  74. test_page(get_page('action=rc raw=1'), 'title: Comments on Yadda',
  75. 'description: This is my comment on a comment page\.', 'generator: Alex');
  76. # No wiping with empty comment
  77. get_page('title=Comments_on_Yadda', 'aftertext=', 'username=Berta');
  78. $page = get_page('Comments_on_Yadda');
  79. test_page($page, 'This is my comment on a comment page\.');
  80. test_page_negative('Berta');
  81. # No wiping with a comment that evaluates to false
  82. get_page('title=Comments_on_Yadda', 'aftertext=0', 'username=Berta');
  83. test_page(get_page('Comments_on_Yadda'),
  84. 'This is my comment on a comment page\.',
  85. '<p>0</p>',
  86. 'Berta');
  87. # homepage
  88. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20another%20comment.',
  89. 'username=Alex', 'homepage=http%3a%2f%2fwww%2eoddmuse%2eorg%2f');
  90. xpath_test(get_page('Comments_on_Yadda'),
  91. '//p[contains(text(),"This is my comment on a comment page.")]', # not wiped
  92. '//p[contains(text(),"This is another comment.")]', # not wiped
  93. '//a[@class="url http outside"][@href="http://www.oddmuse.org/"][text()="Alex"]');
  94. # variant without protocol
  95. get_page('title=Comments_on_Yadda', 'aftertext=This%20is%20yet%20another%20comment.',
  96. 'username=Berta', 'homepage=alexschroeder%2ech');
  97. xpath_test(get_page('Comments_on_Yadda'),
  98. '//a[@class="url http outside"][@href="http://alexschroeder.ch"][text()="Berta"]');
  99. my $textarea = '//textarea[@name="aftertext"][@id="aftertext"]';
  100. xpath_test(get_page('Comments_on_Yadda'), $textarea);
  101. get_page('action=pagelock set=1 id=Comments_on_Yadda pwd=foo');
  102. negative_xpath_test(get_page('Comments_on_Yadda'), $textarea);