cache.t 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright (C) 2006, 2007 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 => 8;
  17. sub get_etag {
  18. my $str = shift;
  19. return $1 if $str =~ /Etag: (.*)\r\n/;
  20. }
  21. sub get_last_modified {
  22. my $str = shift;
  23. return $1 if $str =~ /Last-Modified: (.*)\r\n/i;
  24. }
  25. # Get the ts from the page db and compare it to the Etag
  26. update_page('CacheTest', 'something');
  27. OpenPage('CacheTest');
  28. my $ts1 = $Page{ts};
  29. my $ts2 = get_etag(get_page('CacheTest'));
  30. ok(abs($ts1 - $ts2) <= 2, "Latest edit of this page: $ts1 and $ts2 are close");
  31. # When updating another page, that page's ts is the new Etag for all of them
  32. update_page('OtherPage', 'something');
  33. OpenPage('OtherPage');
  34. $ts1 = $Page{ts};
  35. $ts2 = get_etag(get_page('OtherPage'));
  36. ok(abs($ts1 - $ts2) <= 2, "Latest edit of other page: $ts1 and $ts2 are close");
  37. # Getting it raw should use the original timestamp
  38. OpenPage('CacheTest');
  39. $ts1 = $Page{ts};
  40. $page = get_page('/raw/CacheTest?');
  41. $ts2 = get_etag($page);
  42. ok(abs($ts1 - $ts2) <= 2, "Latest edit of raw page: $ts1 and $ts2 based on etag are close");
  43. SKIP: {
  44. eval { require Date::Parse };
  45. skip ("Date::Parse not installed", 1) if $@;
  46. $ts2 = Date::Parse::str2time(get_last_modified($page));
  47. ok(abs($ts1 - $ts2) <= 2, "Latest edit of raw page: $ts1 and $ts2 based on last-modified timestamp are close");
  48. }
  49. $str = 'This is a WikiLink.';
  50. # this setting produces no link.
  51. AppendStringToFile($ConfigFile, "\$WikiLinks = 0;\n");
  52. test_page(update_page('CacheTest', $str, '', 1), $str);
  53. # now change the setting, you still get no link because the cache has
  54. # not been updated.
  55. AppendStringToFile($ConfigFile, "\$WikiLinks = 1;\n");
  56. test_page(get_page('CacheTest'), $str);
  57. # refresh the cache
  58. test_page(get_page('action=clear pwd=foo'), 'Clear Cache');
  59. # now there is a link
  60. # This is a WikiLink<a class="edit" title="Click to edit this page" href="http://localhost/wiki.pl\?action=edit;id=WikiLink">\?</a>.
  61. xpath_test(get_page('CacheTest'), '//a[@class="edit"][@title="Click to edit this page"][@href="http://localhost/wiki.pl?action=edit;id=WikiLink"][text()="?"]');