wiki.pl: Port some fixes from upstream
[Orgmuse.git] / t / journal2.t
blobaa8a388bc5d383f71951e00c4884a2715b7090d6
1 # Copyright (C) 2006  Alex Schroeder <alex@emacswiki.org>
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.
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.
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
19 require 't/test.pl';
20 package OddMuse;
21 use Test::More tests => 8;
23 clear_pages();
25 # Now let us test a more elaborate setup: Use TimeToRFC822 for pages.
26 # Change JournalSort and Today accordingly, and test the past and
27 # future stuff.
29 sub DateToRFC822 {
30   my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
31   return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
32                  qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
35 $today = DateToRFC822($Now);
36 $tomorrow = DateToRFC822($Now + 24*60*60);
37 $yesterday = DateToRFC822($Now - 24*60*60);
39 update_page($yesterday, "Freitag");
40 update_page($today, "Samstag");
41 update_page($tomorrow, "Sonntag");
43 AppendStringToFile($ConfigFile, q{
44 sub DateToRFC822 {
45   my ($sec, $min, $hour, $mday, $mon, $year, $wday) = gmtime(shift); # Sat, 07 Sep 2002 00:00:01 GMT
46   return sprintf("%s, %02d %s %04d", qw(Sun Mon Tue Wed Thu Fri Sat)[$wday], $mday,
47                  qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)[$mon], $year+1900);
50 sub RFC822toISO {
51   $_ = NormalToFree(shift);
52   ($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)$/;
53   %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);
54   $mon = $month{$mon};
55   return sprintf("%04d-%02d-%02d", $year, $mon, $mday);
58 sub JournalSort { RFC822toISO($b) cmp RFC822toISO($a); }
60 push(@MyInitVariables, sub { $Today = FreeToNormal(DateToRFC822($Now)); });
61 });
63 # now check all pages
64 test_page(update_page('Summary', q{Counting down:
65 <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)">}),
66           "$tomorrow.*$today.*$yesterday");
68 # check reverse order
69 test_page(update_page('Summary', q{Counting up:
70 <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>}),
71           "$yesterday.*$today.*$tomorrow");
73 # check past; use xpath because $today will also match "Last edited ... by ..."
74 $page = update_page('Summary', q{Only past pages:
75 <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>});
76 xpath_test($page, "//a[text()='$yesterday']");
77 negative_xpath_test($page, "//a[text()='$today']",
78                     "//a[text()='$tomorrow']");
80 # check future
81 $page = update_page('Summary', q{Only future pages:
82 <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>});
83 xpath_test($page, "//a[text()='$tomorrow']");
84 negative_xpath_test($page, "//a[text()='$today']",
85                     "//a[text()='$yesterday']");