mail.t 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. # Copyright (C) 2009 Alex Schroeder <alex@gnu.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 utf8; # tests contain UTF-8 characters and it matters
  18. use Test::More tests => 52;
  19. AppendStringToFile($ConfigFile, "\$CommentsPrefix = 'Comments on ';\n");
  20. add_module('mail.pl');
  21. Init(); # set $MailFile
  22. # tests migration
  23. require DB_File;
  24. tie %h, "DB_File", $MailFile;
  25. $h{'alex@gnu.org'} = 'Unregelmässige_Spieler';
  26. $h{'Unregelmässige_Spieler'} = 'alex@gnu.org';
  27. untie %h;
  28. test_page(get_page('action=migrate-subscriptions pwd=foo'),
  29. 'Migrated 2 rows');
  30. test_page(get_page('action=migrate-subscriptions pwd=foo'),
  31. 'migration not necessary');
  32. test_page(get_page('action=subscriptionlist pwd=foo raw=1'),
  33. 'alex@gnu.org Unregelmässige_Spieler',
  34. 'Unregelmässige_Spieler alex@gnu.org');
  35. # make a test with a character that cannot be Latin-1 encoded
  36. # ★ #x2605 => xE2 #x98 #x85 in UTF-8
  37. test_page(get_page('title=Comments_on_%e2%98%85 aftertext=test username=Alex '
  38. . 'mail=berta@example.com notify=1'),
  39. 'Set-Cookie:.*mail%251eberta%40example.com');
  40. test_page(get_page('action=subscriptionlist pwd=foo raw=1'),
  41. 'Comments_on_★ berta@example.com',
  42. 'berta@example.com Comments_on_★');
  43. # edit page
  44. $page = get_page('Comments_on_Foo');
  45. xpath_test($page,
  46. '//label[@for="mail"][contains(text(), "Email")]',
  47. '//input[@name="mail"]',
  48. '//input[@type="checkbox"][@name="notify"][@value="1"]');
  49. # verify that the email address was stored in the cookie
  50. test_page(get_page('title=Comments_on_Foo aftertext=test username=Alex '
  51. . 'mail=alex@example.com notify=1'),
  52. 'Set-Cookie:.*mail%251ealex%40example.com');
  53. # subscribe to a page (second comment page)
  54. get_page('title=Comments_on_Bar aftertext=test username=Alex '
  55. . 'mail=alex@example.com notify=1');
  56. # subscribe to a page (does not work for non-comment pages)
  57. get_page('title=Quux text=test username=Alex '
  58. . 'mail=alex@example.com notify=1');
  59. # subscribe to a page (does not work for non-existing pages)
  60. get_page('action=browse id=Comment_on_Baz username=Alex '
  61. . 'mail=alex@example.com notify=1');
  62. # check for link in admin page with and without admin permission
  63. $page = get_page('action=admin');
  64. xpath_test($page, '//a[@class="subscriptions"][@href="http://localhost/wiki.pl?action=subscriptions"][text()="Your mail subscriptions"]');
  65. test_page_negative($page, 'All mail subscriptions');
  66. $page = get_page('action=admin pwd=foo');
  67. test_page($page, 'Your mail subscriptions');
  68. xpath_test($page, '//a[@class="subscriptionlist"][@href="http://localhost/wiki.pl?action=subscriptionlist"][text()="All mail subscriptions"]');
  69. # check the list of subscriptions without email
  70. xpath_test(get_page('action=subscriptions'),
  71. '//label[@for="mail"][text()="Email: "]',
  72. '//input[@type="text"][@name="mail"]');
  73. # check the list of subscriptions with email
  74. $page = get_page('action=subscriptions mail=alex@example.com');
  75. negative_xpath_test($page,
  76. '//label[@for="mail"]',
  77. '//input[@name="mail"]');
  78. test_page($page,
  79. 'Subscriptions for alex@example.com',
  80. 'Comments on Foo', 'Comments on Bar');
  81. test_page_negative($page, 'Comment on Baz', 'Quux');
  82. xpath_test($page,
  83. '//p/input[@type="checkbox"][@name="pages"][@value="Comments_on_Foo"]',
  84. '//p/input[@type="checkbox"][@name="pages"][@value="Comments_on_Bar"]');
  85. # check the debugging option
  86. test_page(get_page('action=subscriptionlist pwd=foo raw=1'),
  87. 'Comments_on_Foo alex@example.com',
  88. 'Comments_on_Bar alex@example.com',
  89. 'alex@example.com Comments_on_Bar Comments_on_Foo');
  90. # verify mass unsubscribe link
  91. $page = get_page('action=unsubscribe mail=alex@example.com pages=Comments_on_Foo pages=Comments_on_Bar');
  92. test_page($page,
  93. '<h1>Subscriptions</h1>',
  94. 'Unsubscribed alex@example.com from the following');
  95. xpath_test($page,
  96. '//li/a[@class="local"][@href="http://localhost/wiki.pl/Comments_on_Foo"][text()="Comments on Foo"]',
  97. '//li/a[@class="local"][@href="http://localhost/wiki.pl/Comments_on_Bar"][text()="Comments on Bar"]');
  98. # check that it worked
  99. test_page_negative(get_page('action=subscriptionlist pwd=foo'),
  100. 'Comments_on_Foo',
  101. 'Comments_on_Bar',
  102. 'alex@example.com');
  103. # test for subscribe checkbox on comment page
  104. $page = get_page('action=browse id=Comments_on_Foo mail=alex@example.com');
  105. xpath_test($page,
  106. '//label[@for="mail"][contains(text(), "Email")]',
  107. '//input[@name="mail"][@value="alex@example.com"]',
  108. '//input[@type="checkbox"][@name="notify"][@value="1"]',
  109. '//a[@class="subscribe"][@href="http://localhost/wiki.pl?action=subscribe;pages=Comments_on_Foo"][text()="subscribe"]');
  110. # test subscribe action
  111. $page = get_page('action=subscribe mail=alex@example.com pages=Comments_on_Foo pages=Comments_on_Bar pages=Fail');
  112. test_page($page,
  113. 'Subscribed alex@example.com to the following pages',
  114. 'The remaining pages do not exist');
  115. xpath_test($page,
  116. '//li/a[@class="local"][@href="http://localhost/wiki.pl/Comments_on_Foo"][text()="Comments on Foo"]',
  117. '//li/a[@class="local"][@href="http://localhost/wiki.pl/Comments_on_Bar"][text()="Comments on Bar"]');
  118. # test for unsubscribe link on comment page
  119. $page = get_page('action=browse id=Comments_on_Foo mail=alex@example.com');
  120. xpath_test($page,
  121. '//label[@for="mail"][contains(text(), "Email")]',
  122. '//input[@name="mail"][@value="alex@example.com"]',
  123. '//a[@class="unsubscribe"][@href="http://localhost/wiki.pl?action=unsubscribe;pages=Comments_on_Foo"][text()="unsubscribe"]');
  124. negative_xpath_test($page, '//input[@type="checkbox"][@name="notify"]');
  125. # interaction with local names
  126. add_module('localnames.pl');
  127. AppendStringToFile($ConfigFile, "\$LocalNamesCollect = 1;\n");
  128. # Fake a comment on an ordinary page without actually setting the
  129. # $CommentsPrefix such that a local name is also defined.
  130. get_page('title=MyPage aftertext="This is an [http://www.example.com/ Example]."'
  131. . ' mail=alex@example.com notify=1');
  132. xpath_test(get_page('MyPage'),
  133. '//a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
  134. xpath_test(get_page('LocalNames'),
  135. '//ul/li/a[@class="url http outside"][@href="http://www.example.com/"][text()="Example"]');
  136. $page = get_page('action=subscriptions mail=alex@example.com');
  137. test_page($page, 'MyPage');
  138. test_page_negative($page, 'LocalNames');