drafts.t 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2006, 2012 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 => 26;
  17. use utf8;
  18. # No draft button by default
  19. test_page_negative(get_page('action=edit id=HomePage'),
  20. 'Save Draft');
  21. # Adding the module adds button to edit page; no draft saved
  22. add_module('drafts.pl');
  23. $page = get_page('action=edit id=HomePage');
  24. test_page($page, 'Save Draft');
  25. test_page_negative($page, 'action=draft');
  26. # Saving draft uses 204 No Content status
  27. test_page(get_page('title=HomePage text=foo username=Alex Draft=1'),
  28. 'Status: 204');
  29. # Visiting the main page now shows a draft available, if the username
  30. # matches
  31. test_page_negative(get_page('FooBar'), 'action=draft', 'Recover Draft');
  32. test_page(get_page('action=browse id=FooBar username=Alex'),
  33. 'action=draft', 'Recover Draft');
  34. # No username, no draft
  35. test_page(get_page('action=draft'), 'No draft available to recover',
  36. 'Status: 404');
  37. # Recover draft shows original content with username
  38. test_page(get_page('action=draft username=Alex'), 'Preview', 'foo', 'HomePage');
  39. # Another recover draft shows nothing
  40. test_page(get_page('action=draft username=Alex'), 'No draft available to recover',
  41. 'Status: 404');
  42. # Saving second draft
  43. get_page('title=HomePage text=foo username=Alex Draft=1');
  44. get_page('title=HomePage text=foo username=.berta Draft=1');
  45. # Ordinary maintenance deletes nothing
  46. $page = get_page('action=maintain');
  47. test_page($page, 'was kept');
  48. test_page_negative($page, 'was deleted');
  49. # Date back one file
  50. utime($Now-1300000, $Now-1300000, "$DraftDir/.berta");
  51. # Second maintenance requires admin password and deletes one draft
  52. $page = get_page('action=maintain pwd=foo');
  53. test_page($page, 'Alex was last modified [^<>]* and was kept');
  54. test_page($page, '.berta was last modified [^<>]* and was deleted');
  55. ok(-f "$DraftDir/Alex", "$DraftDir/Alex is still there");
  56. ok(! -f "$DraftDir/.berta", "$DraftDir/.berta is gone");
  57. # Date back the other file
  58. utime($Now-1300000, $Now-1300000, "$DraftDir/Alex");
  59. # Second maintenance requires admin password and deletes one draft
  60. test_page(get_page('action=maintain pwd=foo'), 'Alex was last modified [^<>]* ago and was deleted');
  61. ok(! -f "$DraftDir/.berta", "$DraftDir/Alex is gone");
  62. # Testing UTF-8
  63. # Saving draft uses 204 No Content status
  64. test_page(get_page('title=HomePage text=foo username=Schröder Draft=1'),
  65. 'Status: 204', 'username%251eSchr%C3%B6der');
  66. test_page(get_page('action=maintain pwd=foo'),
  67. 'Schröder was last modified [^<>]* and was kept');