rc-pagination.t 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Copyright (C) 2009 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 Test::More tests => 42;
  18. $RcDefault = 7;
  19. AppendStringToFile($ConfigFile, "\$RcDefault = $RcDefault;\n");
  20. my $now = time - 10;
  21. my $day = 24*60*60;
  22. for my $i (reverse 0 .. 20, 50 .. 60) {
  23. my $ts = $now - $i * $day;
  24. AppendStringToFile($RcFile, "$ts${FS}test$i${FS}${FS}test$i${FS}${FS}${FS}1${FS}${FS}\n");
  25. }
  26. # default page lists correct number of pages
  27. my $rc = get_page('action=rc');
  28. xpath_test($rc, map { "//a[text()='test$_']" } (0..6));
  29. # 7 is exactly 7 * 24h + 10 seconds in the past, ie. it should not show up
  30. negative_xpath_test($rc, map { "//a[text()='test$_']" } (7..10));
  31. # at least one line
  32. xpath_test($rc, '//div[@class="rc"]');
  33. # find "more" link
  34. my $url = xpath_test($rc, '//a[text()="More..."][@class="more"]/attribute::href');
  35. my ($from, $upto) = $url =~ /from=(\d+);upto=(\d+)/;
  36. is($from + $RcDefault * $day, $upto, "upto param set to 7d after from param");
  37. ok(abs($now+10 - $RcDefault * $day - $upto) <= 2,
  38. "upto param really close to 7d before present");
  39. # get second page
  40. $rc = get_page("action=rc from=$from upto=$upto");
  41. negative_xpath_test($rc, map { "//a[text()='test$_']" } (3..6));
  42. xpath_test($rc, map { "//a[text()='test$_']" } (7..13));
  43. negative_xpath_test($rc, map { "//a[text()='test$_']" } (14..17));
  44. # get a page far in the past
  45. $from = $now - 100 * $day;
  46. $upto = $from + $RcDefault * $day;
  47. $rc = get_page("action=rc from=$from upto=$upto");
  48. # there should be no links
  49. xpath_test($rc, '//div[@class="rc"]');
  50. negative_xpath_test($rc, '//ul/li/span[@class="time"]');
  51. # get a page with some links
  52. $from = $now - 52 * $day;
  53. $upto = $from + $RcDefault * $day;
  54. $rc = get_page("action=rc from=$from upto=$upto");
  55. # there should be links from 50 .. 52
  56. negative_xpath_test($rc, map { "//a[text()='test$_']" } (45 .. 49));
  57. xpath_test($rc, map { "//a[text()='test$_']" } (50 .. 52));
  58. negative_xpath_test($rc, map { "//a[text()='test$_']" } (53 .. 54));