wiki.pl: Port some fixes from upstream
[Orgmuse.git] / t / journal-rss.t
blobbe562b8646bd6322278a9f1094fcacf9219c6643
1 # Copyright (C) 2008, 2009  Alex Schroeder <alex@gnu.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 3 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, see <http://www.gnu.org/licenses/>.
16 require 't/test.pl';
17 package OddMuse;
18 use Test::More tests => 48;
19 clear_pages();
21 add_module('journal-rss.pl');
23 # summaries eq page content since no summaries are provided
24 update_page('2008-09-21', 'first page');
25 update_page('2008-09-22', 'second page'); # major
26 sleep(1);
27 update_page('2008-09-22', 'third edit', 'third edit', 1); # minor
28 update_page('unrelated', 'wrong page');
30 my $page = get_page('action=journal');
31 test_page($page,
32           '2008-09-21', 'first page',
33           # ignore minor edits are ignored: show last major edit
34           # instead
35           '2008-09-22', 'second page',
36           # reverse sort is the default
37           '2008-09-22(.*\n)+.*2008-09-21');
39 # make sure unrelated pages and minor edits don't show up
40 test_page_negative($page, 'unrelated', 'wrong page',
41                    'third edit');
43 # verify the order of pages
44 test_page(get_page('action=journal'),
45           '2008-09-22(.*\n)+.*2008-09-21');
47 # reverse the order
48 test_page(get_page('action=journal reverse=1'),
49           '2008-09-21(.*\n)+.*2008-09-22');
51 # match parameter
52 $page = get_page('action=journal match=21');
53 test_page($page, '2008-09-21', 'first page');
54 test_page_negative($page, '2008-09-22', 'second page');
56 # search parameter
57 $page = get_page('action=journal search=second');
59 # no pages found, since this is for an old revision!
60 test_page_negative($page,
61                    '2008-09-21', 'first page',
62                    '2008-09-22', 'second page',
63                    'third edit');
65 # strange but true: search returns a page based on the minor edit but
66 # shows the latest major revision that doesn't actually match.
67 $page = get_page('action=journal search=third');
68 test_page($page, '2008-09-22', 'second page');
69 test_page_negative($page, '2008-09-21', 'first page', 'third edit');
71 # testing the limit default
72 update_page('2008-09-05', 'page');
73 update_page('2008-09-06', 'page');
74 update_page('2008-09-07', 'page');
75 update_page('2008-09-08', 'page');
76 update_page('2008-09-09', 'page');
77 update_page('2008-09-10', 'page');
78 update_page('2008-09-11', 'page');
79 update_page('2008-09-12', 'page');
80 update_page('2008-09-13', 'page');
81 update_page('2008-09-14', 'page');
82 update_page('2008-09-15', 'page');
83 update_page('2008-09-16', 'page');
84 update_page('2008-09-17', 'page');
85 update_page('2008-09-18', 'page');
86 update_page('2008-09-19', 'page');
87 update_page('2008-09-20', 'page');
89 $page = get_page('action=journal');
90 test_page($page, '2008-09-22', '2008-09-21', '2008-09-20', '2008-09-19',
91           '2008-09-18', '2008-09-17', '2008-09-16', '2008-09-15',
92           '2008-09-14', '2008-09-13');
93 test_page_negative($page, '2008-09-12', '2008-09-11', '2008-09-10',
94                    '2008-09-09', '2008-09-08', '2008-09-07',
95                    '2008-09-06', '2008-09-05');
97 # testing the rss limit parameter
98 $page = get_page('action=journal rsslimit=1');
99 test_page($page, '2008-09-22');
100 test_page_negative($page, '2008-09-21');
102 $page = get_page('action=journal rsslimit=all');
103 test_page($page, '2008-09-22', '2008-09-05');
105 # Now let's show that we're using the timestamp of the last major
106 # change if possible.
108 my @dates = get_page('action=rss showedit=1 all=1 match=2008-09-22')
109   =~ m!<pubDate>(.*?)</pubDate>!g;
110 # $dates[0] is the channel pubDate
111 my $date2 = $dates[1]; # revision 2 comes first
112 my $date1 = $dates[2]; # revision 1 comes second
113 my ($item) = $page =~ m!(<item>\n<title>2008-09-22</title>\n(.*\n)+?</item>\n)!;
114 test_page($item, "<pubDate>$date1</pubDate>");
115 test_page_negative($item, "<pubDate>$date2</pubDate>");