fix-encoding.t 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright (C) 2012–2013 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 => 22;
  17. use utf8; # tests contain UTF-8 characters and it matters
  18. add_module('fix-encoding.pl');
  19. # make sure no menu shows if no page is provided
  20. test_page_negative(get_page('action=admin'), 'action=fix-encoding');
  21. # make sure no menu shows up if the page does not exists
  22. test_page_negative(get_page('action=admin id=foo'),
  23. 'action=fix-encoding;id=foo',
  24. 'action=fix-escaping;id=foo');
  25. # make sure nothing is saved if the page does not exist
  26. test_page(get_page('action=fix-encoding id=Example'),
  27. 'Location: http://localhost/wiki.pl/Example');
  28. test_page(get_page('action=fix-escaping id=Example'),
  29. 'Location: http://localhost/wiki.pl/Example');
  30. test_page_negative(get_page('action=rc all=1 showedit=1'), 'fix');
  31. # make sure nothing is saved if there is no change
  32. test_page(update_page('Example', 'Pilgerstätte für die Göttin'),
  33. 'Pilgerstätte für die Göttin');
  34. test_page(get_page('action=fix-encoding id=Example'),
  35. 'Location: http://localhost/wiki.pl/Example');
  36. test_page(get_page('action=fix-escaping id=Example'),
  37. 'Location: http://localhost/wiki.pl/Example');
  38. test_page_negative(get_page('action=rc all=1 showedit=1'),
  39. 'Fix Character encoding');
  40. # the menu doesn't show up if the page exists
  41. test_page_negative(get_page('action=admin id=Example'),
  42. 'action=fix-encoding;id=Example',
  43. 'action=fix-escaping;id=Example');
  44. # the menu does show up if the page exists and a username is set
  45. test_page(get_page('action=admin id=Example username=Alex'),
  46. 'action=fix-encoding;id=Example',
  47. 'action=fix-escaping;id=Example');
  48. # here is an actual page with a character encoding error you need to fix
  49. test_page(update_page('Example', 'Pilgerstätte für die Göttin',
  50. 'borked encoding'),
  51. 'Pilgerstätte für die Göttin');
  52. test_page(get_page('action=fix-encoding id=Example'),
  53. 'Location: http://localhost/wiki.pl/Example');
  54. test_page(get_page('Example'),
  55. 'Pilgerstätte für die Göttin');
  56. test_page(get_page('action=rc showedit=1'),
  57. 'Fix character encoding');
  58. # here is an actual page with an HTML escaping error you need to fix
  59. test_page(update_page('Example', '&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;',
  60. 'borked escaping'),
  61. '&amp;lt;b&amp;gt;bold&amp;lt;/b&amp;gt;');
  62. test_page(get_page('action=fix-escaping id=Example'),
  63. 'Location: http://localhost/wiki.pl/Example');
  64. test_page(get_page('Example'),
  65. '&lt;b&gt;bold&lt;/b&gt;');
  66. test_page(get_page('action=rc showedit=1'),
  67. 'Fix HTML escapes');