questionasker.t 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Copyright (C) 2008–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, but
  9. # WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # 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 Test::More tests => 16;
  18. use utf8;
  19. add_module('questionasker.pl');
  20. test_page(get_page('action=edit id=test'),
  21. 'you must answer this question');
  22. test_page_negative(update_page('test', 'edit allowed'),
  23. 'edit allowed');
  24. test_page_negative(update_page('test', 'cheating using preview', '', 0, 0, 'Preview=1'),
  25. 'cheating using preview');
  26. test_page_negative($redirect, 'question%251e1'); # check that cookie is not set after previews
  27. test_page(update_page('test', 'answer question 1', undef, undef, undef,
  28. 'question_num=1', 'answer=4'),
  29. 'answer question 1');
  30. test_page($redirect, 'question%251e1'); # check that the cookie is set after correct answer
  31. test_page(update_page('test', 'admin can edit', undef, undef, 1),
  32. 'admin can edit');
  33. test_page_negative($redirect, 'question%251e1'); # check that cookie is not set after admins
  34. test_page(update_page('test', 'override', undef, undef, undef, "question=1"),
  35. 'override');
  36. # We cannot check that the cookie is not set after cheating because
  37. # cheating sets the very parameter that ends up in the cookie.
  38. # change key and question
  39. AppendStringToFile($ConfigFile, "\$QuestionaskerSecretKey = 'fnord';\n"
  40. . "\$CommentsPrefix = 'Comments on ';\n"
  41. . "\@QuestionaskerQuestions = "
  42. . "(['say hi' => sub { shift =~ /^hi\$/i }]);\n");
  43. test_page_negative(update_page('test', 'using old key', undef, undef, undef,
  44. "question=1"),
  45. 'using old key');
  46. test_page(update_page('test', 'correct key', undef, undef, undef,
  47. "fnord=1"),
  48. 'correct key');
  49. test_page($redirect, 'fnord%251e1'); # check cookie with new secret
  50. test_page(update_page('test', 'answer new question', undef, undef, undef,
  51. 'question_num=0', 'answer=hi'),
  52. 'answer new question');
  53. test_page(get_page('Comments_on_test'),
  54. 'label for="username"',
  55. 'say hi');
  56. # test for corruption of Unicode text
  57. update_page('Umlaute', '<Schröder>');
  58. test_page($redirect, '&lt;Schröder&gt;')