10 my $trailname=shift || qr/\w+/;
11 my $blob=readfile("t/tmp/out/$file");
12 my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m;
13 is($trailline, $expected, "expected $expected in $file");
19 my $blob=readfile("t/tmp/out/$file");
20 my ($trailline)=$blob=~/^trail=$trailname\s+(.*)$/m;
21 $trailline="" unless defined $trailline;
22 ok($trailline !~ /^trail=$trailname\s+/, "no $trailname in $file");
27 ok(! system("rm -rf t/tmp"));
28 ok(! system("mkdir t/tmp"));
30 my $installed = $ENV{INSTALLED_TESTS};
34 @command = qw(ikiwiki);
37 ok(! system("make -s ikiwiki.out"));
38 @command = qw(perl -I. ./ikiwiki.out
39 --underlaydir=underlays/basewiki
40 --set underlaydirbase=underlays
41 --templatedir=templates);
44 push @command, qw(--set usedirs=0 --plugin trail --plugin inline
45 --url=http://example.com --cgiurl=http://example.com/ikiwiki.cgi
46 --rss --atom t/tmp/in t/tmp/out --verbose);
48 # Write files with a date in the past, so that when we refresh,
49 # the update is detected.
54 writefile($name, "t/tmp/in", $content);
55 ok(utime(333333333, 333333333, "t/tmp/in/$name"));
58 # Use a rather stylized template to override the default rendering, to make
59 # it easy to search for the desired results
60 write_old_file("templates/trails.tmpl", <<EOF
62 <TMPL_IF __FIRST__><nav></TMPL_IF>
64 trail=<TMPL_VAR TRAILPAGE> n=<TMPL_VAR NEXTPAGE> p=<TMPL_VAR PREVPAGE>
68 <a href="<TMPL_VAR PREVURL>">< <TMPL_VAR PREVTITLE></a>
70 <a href="<TMPL_VAR TRAILURL>">^ <TMPL_VAR TRAILTITLE> ^</a>
72 <a href="<TMPL_VAR NEXTURL>"><TMPL_VAR NEXTTITLE> ></a>
75 <TMPL_IF __LAST__></nav></TMPL_IF>
79 write_old_file("badger.mdwn", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
80 write_old_file("mushroom.mdwn", "content of mushroom");
81 write_old_file("snake.mdwn", "content of snake");
82 write_old_file("ratty.mdwn", "content of ratty");
83 write_old_file("mr_toad.mdwn", "content of mr toad");
84 write_old_file("add.mdwn", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
85 write_old_file("add/b.mdwn", "b");
86 write_old_file("add/d.mdwn", "d");
87 write_old_file("del.mdwn", '[[!trailitems pages="del/*" sort=title]]');
88 write_old_file("del/a.mdwn", "a");
89 write_old_file("del/b.mdwn", "b");
90 write_old_file("del/c.mdwn", "c");
91 write_old_file("del/d.mdwn", "d");
92 write_old_file("del/e.mdwn", "e");
93 write_old_file("self_referential.mdwn", '[[!trailitems pagenames="self_referential" circular=yes]]');
94 write_old_file("sorting/linked.mdwn", "linked");
95 write_old_file("sorting/a/b.mdwn", "a/b");
96 write_old_file("sorting/a/c.mdwn", "a/c");
97 write_old_file("sorting/z/a.mdwn", "z/a");
98 write_old_file("sorting/beginning.mdwn", "beginning");
99 write_old_file("sorting/middle.mdwn", "middle");
100 write_old_file("sorting/end.mdwn", "end");
101 write_old_file("sorting/new.mdwn", "new");
102 write_old_file("sorting/old.mdwn", "old");
103 write_old_file("sorting/ancient.mdwn", "ancient");
104 # These three need to be in the appropriate age order
105 ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
106 ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
107 ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
108 write_old_file("sorting/linked2.mdwn", "linked2");
109 # This initially uses the default sort order: age for the inline, and path
110 # for trailitems. We change it later.
111 write_old_file("sorting.mdwn",
112 '[[!traillink linked]] ' .
113 '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
114 '[[!trailitems pagenames="sorting/beginning sorting/middle sorting/end"]] ' .
115 '[[!inline pages="sorting/old or sorting/ancient or sorting/new" trail="yes"]] ' .
116 '[[!traillink linked2]]');
118 write_old_file("meme.mdwn", <<EOF
120 * [[!traillink badger]]
121 * [[!traillink badger text="This is a link to badger, with a title"]]
122 * [[!traillink That_is_the_badger|badger]]
123 * [[!traillink badger]]
124 * [[!traillink mushroom]]
125 * [[!traillink mushroom]]
126 * [[!traillink snake]]
127 * [[!traillink snake]]
131 write_old_file("wind_in_the_willows.mdwn", <<EOF
132 [[!trailoptions circular=yes sort=title]]
133 [[!trailitems pages="ratty or badger or mr_toad"]]
138 ok(! system(@command));
139 ok(! system(@command, "--refresh"));
141 $blob = readfile("t/tmp/out/meme.html");
142 ok($blob =~ /<a href="(\.\/)?badger.html">badger<\/a>/m);
143 ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
144 ok($blob =~ /<a href="(\.\/)?badger.html">That is the badger<\/a>/m);
146 check_trail("badger.html", "n=mushroom p=", "meme");
147 check_trail("badger.html", "n=mr_toad p=ratty", "wind_in_the_willows");
149 ok(! -f "t/tmp/out/moley.html");
151 check_trail("mr_toad.html", "n=ratty p=badger", "wind_in_the_willows");
152 check_no_trail("mr_toad.html", "meme");
153 # meta title is respected for pages that have one
154 $blob = readfile("t/tmp/out/mr_toad.html");
155 ok($blob =~ /">< The Breezy Badger<\/a>/m);
156 # pagetitle for pages that don't
157 ok($blob =~ /">ratty ><\/a>/m);
159 check_no_trail("ratty.html", "meme");
160 check_trail("ratty.html", "n=badger p=mr_toad", "wind_in_the_willows");
162 check_trail("mushroom.html", "n=snake p=badger", "meme");
163 check_no_trail("mushroom.html", "wind_in_the_willows");
165 check_trail("snake.html", "n= p=mushroom", "meme");
166 check_no_trail("snake.html", "wind_in_the_willows");
168 check_trail("self_referential.html", "n= p=", "self_referential");
170 check_trail("add/b.html", "n=add/d p=", "add");
171 check_trail("add/d.html", "n= p=add/b", "add");
172 ok(! -f "t/tmp/out/add/a.html");
173 ok(! -f "t/tmp/out/add/c.html");
174 ok(! -f "t/tmp/out/add/e.html");
176 check_trail("del/a.html", "n=del/b p=");
177 check_trail("del/b.html", "n=del/c p=del/a");
178 check_trail("del/c.html", "n=del/d p=del/b");
179 check_trail("del/d.html", "n=del/e p=del/c");
180 check_trail("del/e.html", "n= p=del/d");
182 check_trail("sorting/linked.html", "n=sorting/a/b p=");
183 check_trail("sorting/a/b.html", "n=sorting/a/c p=sorting/linked");
184 check_trail("sorting/a/c.html", "n=sorting/z/a p=sorting/a/b");
185 check_trail("sorting/z/a.html", "n=sorting/beginning p=sorting/a/c");
186 check_trail("sorting/beginning.html", "n=sorting/middle p=sorting/z/a");
187 check_trail("sorting/middle.html", "n=sorting/end p=sorting/beginning");
188 check_trail("sorting/end.html", "n=sorting/new p=sorting/middle");
189 check_trail("sorting/new.html", "n=sorting/old p=sorting/end");
190 check_trail("sorting/old.html", "n=sorting/ancient p=sorting/new");
191 check_trail("sorting/ancient.html", "n=sorting/linked2 p=sorting/old");
192 check_trail("sorting/linked2.html", "n= p=sorting/ancient");
194 # Make some changes and refresh. These writefile calls don't set an
195 # old mtime, so they're strictly newer than the "old" files.
197 writefile("add/a.mdwn", "t/tmp/in", "a");
198 writefile("add/c.mdwn", "t/tmp/in", "c");
199 writefile("add/e.mdwn", "t/tmp/in", "e");
200 ok(unlink("t/tmp/in/del/a.mdwn"));
201 ok(unlink("t/tmp/in/del/c.mdwn"));
202 ok(unlink("t/tmp/in/del/e.mdwn"));
204 writefile("sorting.mdwn", "t/tmp/in",
205 readfile("t/tmp/in/sorting.mdwn") .
206 '[[!trailoptions sort="title" reverse="yes"]]');
208 ok(! system(@command, "--refresh"));
210 check_trail("add/a.html", "n=add/b p=");
211 check_trail("add/b.html", "n=add/c p=add/a");
212 check_trail("add/c.html", "n=add/d p=add/b");
213 check_trail("add/d.html", "n=add/e p=add/c");
214 check_trail("add/e.html", "n= p=add/d");
216 check_trail("del/b.html", "n=del/d p=");
217 check_trail("del/d.html", "n= p=del/b");
218 ok(! -f "t/tmp/out/del/a.html");
219 ok(! -f "t/tmp/out/del/c.html");
220 ok(! -f "t/tmp/out/del/e.html");
222 check_trail("sorting/old.html", "n=sorting/new p=");
223 check_trail("sorting/new.html", "n=sorting/middle p=sorting/old");
224 check_trail("sorting/middle.html", "n=sorting/linked2 p=sorting/new");
225 check_trail("sorting/linked2.html", "n=sorting/linked p=sorting/middle");
226 check_trail("sorting/linked.html", "n=sorting/end p=sorting/linked2");
227 check_trail("sorting/end.html", "n=sorting/a/c p=sorting/linked");
228 check_trail("sorting/a/c.html", "n=sorting/beginning p=sorting/end");
229 check_trail("sorting/beginning.html", "n=sorting/a/b p=sorting/a/c");
230 check_trail("sorting/a/b.html", "n=sorting/ancient p=sorting/beginning");
231 check_trail("sorting/ancient.html", "n=sorting/z/a p=sorting/a/b");
232 check_trail("sorting/z/a.html", "n= p=sorting/ancient");
234 ok(! system("rm -rf t/tmp"));