journal2.t 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # Copyright (C) 2006 Alex Schroeder <alex@emacswiki.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 => 8;
  18. # Now let us test a more elaborate setup: Use TimeToRFC822 for pages.
  19. # Change JournalSort and Today accordingly, and test the past and
  20. # future stuff.
  21. sub DateToRFC822 {
  22. my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
  23. return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
  24. qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
  25. }
  26. $today = DateToRFC822($Now);
  27. $tomorrow = DateToRFC822($Now + 24*60*60);
  28. $yesterday = DateToRFC822($Now - 24*60*60);
  29. update_page($yesterday, "Freitag");
  30. update_page($today, "Samstag");
  31. update_page($tomorrow, "Sonntag");
  32. AppendStringToFile($ConfigFile, q{
  33. sub DateToRFC822 {
  34. my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
  35. return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
  36. qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
  37. }
  38. sub RFC822toISO {
  39. $_ = NormalToFree(shift);
  40. ($wday, $mday, $mon, $year) = /^(Sun|Mon|Tue|Wed|Thu|Fri|Sat), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d\d\d\d)$/;
  41. %month = qw(Jan 1 Feb 2 Mar 3 Apr 4 May 5 Jun 6 Jul 7 Aug 8 Sep 9 Oct 10 Nov 11 Dec 12);
  42. $mon = $month{$mon};
  43. return sprintf("%04d-%02d-%02d", $year, $mon, $mday);
  44. }
  45. sub JournalSort { RFC822toISO($b) cmp RFC822toISO($a); }
  46. push(@MyInitVariables, sub { $Today = FreeToNormal(DateToRFC822($Now)); });
  47. });
  48. # now check all pages
  49. test_page(update_page('Summary', q{Counting down:
  50. <journal "^(Sun|Mon|Tue|Wed|Thu|Fri|Sat),_(\d\d)_(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)_(\d\d\d\d)">}),
  51. "$tomorrow.*$today.*$yesterday");
  52. # check reverse order
  53. test_page(update_page('Summary', q{Counting up:
  54. <journal "^(Sun|Mon|Tue|Wed|Thu|Fri|Sat),_(\d\d)_(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)_(\d\d\d\d)" reverse>}),
  55. "$yesterday.*$today.*$tomorrow");
  56. # check past; use xpath because $today will also match "Last edited ... by ..."
  57. $page = update_page('Summary', q{Only past pages:
  58. <journal "^(Sun|Mon|Tue|Wed|Thu|Fri|Sat),_(\d\d)_(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)_(\d\d\d\d)" past>});
  59. xpath_test($page, "//a[text()='$yesterday']");
  60. negative_xpath_test($page, "//a[text()='$today']",
  61. "//a[text()='$tomorrow']");
  62. # check future
  63. $page = update_page('Summary', q{Only future pages:
  64. <journal "^(Sun|Mon|Tue|Wed|Thu|Fri|Sat),_(\d\d)_(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)_(\d\d\d\d)" future>});
  65. xpath_test($page, "//a[text()='$tomorrow']");
  66. negative_xpath_test($page, "//a[text()='$today']",
  67. "//a[text()='$yesterday']");