like.t 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # Copyright (C) 2015 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;
  18. use Test::More tests => 17;
  19. add_module('like.pl');
  20. add_module('creole.pl');
  21. # no Like link on an empty page
  22. $page = get_page('Test');
  23. test_page($page, 'This page does not exist');
  24. test_page_negative($page, 'I like this');
  25. # Like link doesn't work for empty pages
  26. get_page('action=like id=Test');
  27. $page = get_page('Test');
  28. test_page($page, 'This page does not exist');
  29. test_page_negative($page, 'persons? liked this');
  30. # create page and like twice, checking counter
  31. $page = update_page('Test',
  32. 'Human history began with an act of disobedience, '
  33. . 'and it is not unlikely that it will be terminated '
  34. . 'by an act of obedience.');
  35. test_page($page, 'Human history', 'I like this');
  36. get_page('action=like id=Test');
  37. test_page(get_page('Test'), '<h4>1 person liked this</h4>');
  38. get_page('action=like id=Test');
  39. $page = get_page('Test');
  40. test_page($page, '<h4>2 persons liked this</h4>');
  41. get_page('action=like id=Test');
  42. $page = get_page('Test');
  43. test_page($page, '<h4>3 persons liked this</h4>');
  44. # verify that we used @MyFooters correctly
  45. test_page_negative($page, '</a>1');
  46. # verify that we didn't introduce more than one newline
  47. OpenPage('Test');
  48. unlike($Page{text}, qr/\n\n\n/, "didn't introduce more newlines");
  49. # let's see whether reconfiguration works using THUMBS UP SIGN
  50. AppendStringToFile($ConfigFile, <<'EOT');
  51. use utf8;
  52. $LikeRegexp = qr'(\d+) 👍\n\z';
  53. $LikeReplacement = "%d 👍";
  54. $LikeFirst = "1 👍";
  55. $Translate{"I like this!"} = "Hell Yeah! 👍";
  56. EOT
  57. # wipe the test page and like it
  58. $page = update_page('Test',
  59. 'The successful revolutionary is a statesman, '
  60. . 'the unsuccessful one a criminal.');
  61. test_page($page, "Hell Yeah! 👍");
  62. get_page('action=like id=Test');
  63. test_page(get_page('Test'), '1 👍');
  64. get_page('action=like id=Test');
  65. $page = get_page('Test');
  66. test_page($page, '2 👍');
  67. # wipe config file for another setup in order to test Creole markup
  68. write_config_file();
  69. AppendStringToFile($ConfigFile, <<'EOT');
  70. $LikeRegexp = qr'\*\*(\d+) persons? liked this\*\*\n\z';
  71. $LikeReplacement = '**%d persons liked this**';
  72. $LikeFirst = '**1 person liked this**';
  73. EOT
  74. $page = update_page('Test',
  75. 'Selfish persons are incapable of loving others, '
  76. . 'but they are not capable of loving themselves either.');
  77. test_page($page, "I like this!");
  78. get_page('action=like id=Test');
  79. test_page(get_page('Test'), '<strong>1 person liked this</strong>');
  80. get_page('action=like id=Test');
  81. $page = get_page('Test');
  82. test_page($page, '<strong>2 persons liked this</strong>');