]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blob - t/trail.t
aggregate: Fix aggregation of posts without a title
[git.ikiwiki.info.git] / t / trail.t
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4 use Cwd qw(getcwd);
5 use Test::More;
6 use IkiWiki;
8 sub check_trail {
9         my $file=shift;
10         my $expected=shift;
11         my $trailname=shift || qr/\w+/;
12         my $blob=readfile("t/tmp/out/$file");
13         my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m;
14         is($trailline, $expected, "expected $expected in $file");
15 }
17 sub check_no_trail {
18         my $file=shift;
19         my $trailname=shift || qr/\w+/;
20         my $blob=readfile("t/tmp/out/$file");
21         my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m;
22         $trailline="" unless defined $trailline;
23         ok($trailline !~ /^trail=$trailname\s+/, "no trail $trailname in $file");
24 }
26 my $blob;
28 ok(! system("rm -rf t/tmp"));
29 ok(! system("mkdir t/tmp"));
31 my $installed = $ENV{INSTALLED_TESTS};
33 my @command;
34 if ($installed) {
35         @command = qw(ikiwiki);
36 }
37 else {
38         ok(! system("make -s ikiwiki.out"));
39         @command = ("perl", "-I".getcwd, qw(./ikiwiki.out
40                 --underlaydir=underlays/basewiki
41                 --set underlaydirbase=underlays
42                 --templatedir=templates));
43 }
45 push @command, qw(--set usedirs=0 --plugin trail --plugin inline
46         --url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi
47         --rss --atom t/tmp/in t/tmp/out --verbose);
49 # Write files with a date in the past, so that when we refresh,
50 # the update is detected.
51 sub write_old_file {
52         my $name = shift;
53         my $content = shift;
55         writefile($name, "t/tmp/in", $content);
56         ok(utime(333333333, 333333333, "t/tmp/in/$name"));
57 }
59 # Use a rather stylized template to override the default rendering, to make
60 # it easy to search for the desired results
61 write_old_file("templates/trails.tmpl", <<EOF
62 <TMPL_LOOP TRAILLOOP>
63 <TMPL_IF __FIRST__><nav></TMPL_IF>
64 <div>
65 trail=<TMPL_VAR TRAILPAGE> n=<TMPL_VAR NEXTPAGE> p=<TMPL_VAR PREVPAGE>
66 </div>
67 <div>
68 <TMPL_IF PREVURL>
69 <a href="<TMPL_VAR PREVURL>">&lt; <TMPL_VAR PREVTITLE></a>
70 </TMPL_IF> |
71 <a href="<TMPL_VAR TRAILURL>">^ <TMPL_VAR TRAILTITLE> ^</a>
72 | <TMPL_IF NEXTURL>
73 <a href="<TMPL_VAR NEXTURL>"><TMPL_VAR NEXTTITLE> &gt;</a>
74 </TMPL_IF>
75 </div>
76 <TMPL_IF __LAST__></nav></TMPL_IF>
77 </TMPL_LOOP>
78 EOF
79 );
80 write_old_file("badger.mdwn", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
81 write_old_file("mushroom.mdwn", "content of mushroom");
82 write_old_file("snake.mdwn", "content of snake");
83 write_old_file("ratty.mdwn", "content of ratty");
84 write_old_file("mr_toad.mdwn", "content of mr toad");
85 write_old_file("add.mdwn", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
86 write_old_file("add/b.mdwn", "b");
87 write_old_file("add/d.mdwn", "d");
88 write_old_file("del.mdwn", '[[!trailitems pages="del/*" sort=title]]');
89 write_old_file("del/a.mdwn", "a");
90 write_old_file("del/b.mdwn", "b");
91 write_old_file("del/c.mdwn", "c");
92 write_old_file("del/d.mdwn", "d");
93 write_old_file("del/e.mdwn", "e");
94 write_old_file("self_referential.mdwn", '[[!trailitems pagenames="self_referential" circular=yes]]');
95 write_old_file("sorting/linked.mdwn", "linked");
96 write_old_file("sorting/a/b.mdwn", "a/b");
97 write_old_file("sorting/a/c.mdwn", "a/c");
98 write_old_file("sorting/z/a.mdwn", "z/a");
99 write_old_file("sorting/beginning.mdwn", "beginning");
100 write_old_file("sorting/middle.mdwn", "middle");
101 write_old_file("sorting/end.mdwn", "end");
102 write_old_file("sorting/new.mdwn", "new");
103 write_old_file("sorting/old.mdwn", "old");
104 write_old_file("sorting/ancient.mdwn", "ancient");
105 # These three need to be in the appropriate age order
106 ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
107 ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
108 ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
109 write_old_file("sorting/linked2.mdwn", "linked2");
110 # This initially uses the default sort order: age for the inline, and path
111 # for trailitems. We change it later.
112 write_old_file("sorting.mdwn",
113         '[[!traillink linked]] ' .
114         '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
115         '[[!trailitems pagenames="sorting/beginning sorting/middle sorting/end"]] ' .
116         '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' .
117         '[[!traillink linked2]]');
118 write_old_file("limited/a.mdwn", "a");
119 write_old_file("limited/b.mdwn", "b");
120 write_old_file("limited/c.mdwn", "c");
121 write_old_file("limited/d.mdwn", "d");
122 write_old_file("limited.mdwn",
123         '[[!inline pages="limited/*" trail="yes" show=2 sort=title]]');
124 write_old_file("untrail/a.mdwn", "a");
125 write_old_file("untrail/b.mdwn", "b");
126 write_old_file("untrail.mdwn", "[[!traillink a]] [[!traillink b]]");
127 write_old_file("retitled/a.mdwn", "a");
128 write_old_file("retitled.mdwn",
129         '[[!meta title="the old title"]][[!traillink a]]');
131 write_old_file("meme.mdwn", <<EOF
132 [[!trail]]
133 * [[!traillink badger]]
134 * [[!traillink badger text="This is a link to badger, with a title"]]
135 * [[!traillink That_is_the_badger|badger]]
136 * [[!traillink badger]]
137 * [[!traillink mushroom]]
138 * [[!traillink mushroom]]
139 * [[!traillink snake]]
140 * [[!traillink snake]]
141 EOF
142 );
144 write_old_file("wind_in_the_willows.mdwn", <<EOF
145 [[!trailoptions circular=yes sort=title]]
146 [[!trailitems pages="ratty or badger or mr_toad"]]
147 [[!trailitem moley]]
148 EOF
149 );
151 ok(! system(@command));
152 ok(! system(@command, "--refresh"));
154 $blob = readfile("t/tmp/out/meme.html");
155 ok($blob =~ /<a href="(\.\/)?badger.html">badger<\/a>/m);
156 ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
157 ok($blob =~ /<a href="(\.\/)?badger.html">That is the badger<\/a>/m);
159 check_trail("badger.html", "n=mushroom p=", "meme");
160 check_trail("badger.html", "n=mr_toad p=ratty", "wind_in_the_willows");
162 ok(! -f "t/tmp/out/moley.html");
164 check_trail("mr_toad.html", "n=ratty p=badger", "wind_in_the_willows");
165 check_no_trail("mr_toad.html", "meme");
166 # meta title is respected for pages that have one
167 $blob = readfile("t/tmp/out/mr_toad.html");
168 ok($blob =~ /">&lt; The Breezy Badger<\/a>/m);
169 # pagetitle for pages that don't
170 ok($blob =~ /">ratty &gt;<\/a>/m);
172 check_no_trail("ratty.html", "meme");
173 check_trail("ratty.html", "n=badger p=mr_toad", "wind_in_the_willows");
175 check_trail("mushroom.html", "n=snake p=badger", "meme");
176 check_no_trail("mushroom.html", "wind_in_the_willows");
178 check_trail("snake.html", "n= p=mushroom", "meme");
179 check_no_trail("snake.html", "wind_in_the_willows");
181 check_trail("self_referential.html", "n= p=", "self_referential");
183 check_trail("add/b.html", "n=add/d p=", "add");
184 check_trail("add/d.html", "n= p=add/b", "add");
185 ok(! -f "t/tmp/out/add/a.html");
186 ok(! -f "t/tmp/out/add/c.html");
187 ok(! -f "t/tmp/out/add/e.html");
189 check_trail("del/a.html", "n=del/b p=");
190 check_trail("del/b.html", "n=del/c p=del/a");
191 check_trail("del/c.html", "n=del/d p=del/b");
192 check_trail("del/d.html", "n=del/e p=del/c");
193 check_trail("del/e.html", "n= p=del/d");
195 check_trail("sorting/linked.html", "n=sorting/a/b p=");
196 check_trail("sorting/a/b.html", "n=sorting/a/c p=sorting/linked");
197 check_trail("sorting/a/c.html", "n=sorting/z/a p=sorting/a/b");
198 check_trail("sorting/z/a.html", "n=sorting/beginning p=sorting/a/c");
199 check_trail("sorting/beginning.html", "n=sorting/middle p=sorting/z/a");
200 check_trail("sorting/middle.html", "n=sorting/end p=sorting/beginning");
201 check_trail("sorting/end.html", "n=sorting/new p=sorting/middle");
202 check_trail("sorting/new.html", "n=sorting/old p=sorting/end");
203 check_trail("sorting/old.html", "n=sorting/ancient p=sorting/new");
204 check_trail("sorting/ancient.html", "n=sorting/linked2 p=sorting/old");
205 check_trail("sorting/linked2.html", "n= p=sorting/ancient");
207 # If the inline has a limited number of pages, the trail still contains
208 # everything.
209 $blob = readfile("t/tmp/out/limited.html");
210 ok($blob =~ /<a href="(\.\/)?limited\/a.html">a<\/a>/m);
211 ok($blob =~ /<a href="(\.\/)?limited\/b.html">b<\/a>/m);
212 ok($blob !~ /<a href="(\.\/)?limited\/c.html">/m);
213 ok($blob !~ /<a href="(\.\/)?limited\/d.html">/m);
214 check_trail("limited/a.html", "n=limited/b p=");
215 check_trail("limited/b.html", "n=limited/c p=limited/a");
216 check_trail("limited/c.html", "n=limited/d p=limited/b");
217 check_trail("limited/d.html", "n= p=limited/c");
219 check_trail("untrail/a.html", "n=untrail/b p=");
220 check_trail("untrail/b.html", "n= p=untrail/a");
222 $blob = readfile("t/tmp/out/retitled/a.html");
223 ok($blob =~ /\^ the old title \^/m);
225 # Make some changes and refresh. These writefile calls don't set an
226 # old mtime, so they're strictly newer than the "old" files.
228 writefile("add/a.mdwn", "t/tmp/in", "a");
229 writefile("add/c.mdwn", "t/tmp/in", "c");
230 writefile("add/e.mdwn", "t/tmp/in", "e");
231 ok(unlink("t/tmp/in/del/a.mdwn"));
232 ok(unlink("t/tmp/in/del/c.mdwn"));
233 ok(unlink("t/tmp/in/del/e.mdwn"));
235 writefile("sorting.mdwn", "t/tmp/in",
236         readfile("t/tmp/in/sorting.mdwn") .
237         '[[!trailoptions sort="title" reverse="yes"]]'); 
239 writefile("retitled.mdwn", "t/tmp/in",
240         '[[!meta title="the new title"]][[!traillink a]]');
242 # If the inline has a limited number of pages, the trail still depends on
243 # everything.
244 writefile("limited.html", "t/tmp/out", "[this gets rebuilt]");
245 writefile("limited/c.mdwn", "t/tmp/in", '[[!meta title="New C page"]]c');
247 writefile("untrail.mdwn", "t/tmp/in", "no longer a trail");
249 ok(! system(@command, "--refresh"));
251 check_trail("add/a.html", "n=add/b p=");
252 check_trail("add/b.html", "n=add/c p=add/a");
253 check_trail("add/c.html", "n=add/d p=add/b");
254 check_trail("add/d.html", "n=add/e p=add/c");
255 check_trail("add/e.html", "n= p=add/d");
257 check_trail("del/b.html", "n=del/d p=");
258 check_trail("del/d.html", "n= p=del/b");
259 ok(! -f "t/tmp/out/del/a.html");
260 ok(! -f "t/tmp/out/del/c.html");
261 ok(! -f "t/tmp/out/del/e.html");
263 check_trail("sorting/old.html", "n=sorting/new p=");
264 check_trail("sorting/new.html", "n=sorting/middle p=sorting/old");
265 check_trail("sorting/middle.html", "n=sorting/linked2 p=sorting/new");
266 check_trail("sorting/linked2.html", "n=sorting/linked p=sorting/middle");
267 check_trail("sorting/linked.html", "n=sorting/end p=sorting/linked2");
268 check_trail("sorting/end.html", "n=sorting/a/c p=sorting/linked");
269 check_trail("sorting/a/c.html", "n=sorting/beginning p=sorting/end");
270 check_trail("sorting/beginning.html", "n=sorting/a/b p=sorting/a/c");
271 check_trail("sorting/a/b.html", "n=sorting/ancient p=sorting/beginning");
272 check_trail("sorting/ancient.html", "n=sorting/z/a p=sorting/a/b");
273 check_trail("sorting/z/a.html", "n= p=sorting/ancient");
275 # If the inline has a limited number of pages, the trail still depends on
276 # everything, so it gets rebuilt even though it doesn't strictly need it.
277 # This means we could use it as a way to recompute the order of members
278 # and the contents of their trail navbars, allowing us to fix the regression
279 # described in [[bugs/trail excess dependencies]] without a full content
280 # dependency.
281 $blob = readfile("t/tmp/out/limited.html");
282 ok($blob =~ /<a href="(\.\/)?limited\/a.html">a<\/a>/m);
283 ok($blob =~ /<a href="(\.\/)?limited\/b.html">b<\/a>/m);
284 ok($blob !~ /<a href="(\.\/)?limited\/c.html">/m);
285 ok($blob !~ /<a href="(\.\/)?limited\/d.html">/m);
286 check_trail("limited/a.html", "n=limited/b p=");
287 check_trail("limited/b.html", "n=limited/c p=limited/a");
288 check_trail("limited/c.html", "n=limited/d p=limited/b");
289 check_trail("limited/d.html", "n= p=limited/c");
290 # Also, b and d should pick up the change to c. This regressed with the
291 # change to using a presence dependency.
292 $blob = readfile("t/tmp/out/limited/b.html");
293 ok($blob =~ /New C page &gt;/m);
294 $blob = readfile("t/tmp/out/limited/d.html");
295 ok($blob =~ /&lt; New C page/m);
297 # Members of a retitled trail should pick up that change.
298 # This regressed with the change to using a presence dependency.
299 $blob = readfile("t/tmp/out/retitled/a.html");
300 ok($blob =~ /\^ the new title \^/m);
302 # untrail is no longer a trail, so these are no longer in it.
303 check_no_trail("untrail/a.html");
304 check_no_trail("untrail/b.html");
306 ok(! system("rm -rf t/tmp"));
308 done_testing();