journal2.t 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 2 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, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. require 't/test.pl';
  19. package OddMuse;
  20. use Test::More tests => 8;
  21. # Now let us test a more elaborate setup: Use TimeToRFC822 for pages.
  22. # Change JournalSort and Today accordingly, and test the past and
  23. # future stuff.
  24. sub DateToRFC822 {
  25. my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
  26. return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
  27. qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
  28. }
  29. $today = DateToRFC822($Now);
  30. $tomorrow = DateToRFC822($Now + 24*60*60);
  31. $yesterday = DateToRFC822($Now - 24*60*60);
  32. update_page($yesterday, "Freitag");
  33. update_page($today, "Samstag");
  34. update_page($tomorrow, "Sonntag");
  35. AppendStringToFile($ConfigFile, q{
  36. sub DateToRFC822 {
  37. my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
  38. return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
  39. qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
  40. }
  41. sub RFC822toISO {
  42. $_ = NormalToFree(shift);
  43. ($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)$/;
  44. %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);
  45. $mon = $month{$mon};
  46. return sprintf("%04d-%02d-%02d", $year, $mon, $mday);
  47. }
  48. sub JournalSort { RFC822toISO($b) cmp RFC822toISO($a); }
  49. push(@MyInitVariables, sub { $Today = FreeToNormal(DateToRFC822($Now)); });
  50. });
  51. # now check all pages
  52. test_page(update_page('Summary', q{Counting down:
  53. <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)">}),
  54. "$tomorrow.*$today.*$yesterday");
  55. # check reverse order
  56. test_page(update_page('Summary', q{Counting up:
  57. <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>}),
  58. "$yesterday.*$today.*$tomorrow");
  59. # check past; use xpath because $today will also match "Last edited ... by ..."
  60. $page = update_page('Summary', q{Only past pages:
  61. <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>});
  62. xpath_test($page, "//a[text()='$yesterday']");
  63. negative_xpath_test($page, "//a[text()='$today']",
  64. "//a[text()='$tomorrow']");
  65. # check future
  66. $page = update_page('Summary', q{Only future pages:
  67. <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>});
  68. xpath_test($page, "//a[text()='$tomorrow']");
  69. negative_xpath_test($page, "//a[text()='$today']",
  70. "//a[text()='$yesterday']");