4 use Test::More 'no_plan';
9 ok(! system("rm -rf t/tmp"));
10 ok(! system("mkdir t/tmp"));
12 # Use a rather stylized template to override the default rendering, to make
13 # it easy to search for the desired results
14 writefile("templates/trails.tmpl", "t/tmp/in", <<EOF
16 <TMPL_IF __FIRST__><nav></TMPL_IF>
18 trail=<TMPL_VAR TRAILPAGE> n=<TMPL_VAR NEXTPAGE> p=<TMPL_VAR PREVPAGE>
22 <a href="<TMPL_VAR PREVURL>">< <TMPL_VAR PREVTITLE></a>
24 <a href="<TMPL_VAR TRAILURL>">^ <TMPL_VAR TRAILTITLE> ^</a>
26 <a href="<TMPL_VAR NEXTURL>"><TMPL_VAR NEXTTITLE> ></a>
29 <TMPL_IF __LAST__></nav></TMPL_IF>
33 writefile("badger.mdwn", "t/tmp/in", "[[!meta title=\"The Breezy Badger\"]]\ncontent of badger");
34 writefile("mushroom.mdwn", "t/tmp/in", "content of mushroom");
35 writefile("snake.mdwn", "t/tmp/in", "content of snake");
36 writefile("ratty.mdwn", "t/tmp/in", "content of ratty");
37 writefile("mr_toad.mdwn", "t/tmp/in", "content of mr toad");
38 writefile("add.mdwn", "t/tmp/in", '[[!trailitems pagenames="add/a add/b add/c add/d add/e"]]');
39 writefile("add/b.mdwn", "t/tmp/in", "b");
40 writefile("add/d.mdwn", "t/tmp/in", "d");
41 writefile("del.mdwn", "t/tmp/in", '[[!trailitems pages="del/*" sort=title]]');
42 writefile("del/a.mdwn", "t/tmp/in", "a");
43 writefile("del/b.mdwn", "t/tmp/in", "b");
44 writefile("del/c.mdwn", "t/tmp/in", "c");
45 writefile("del/d.mdwn", "t/tmp/in", "d");
46 writefile("del/e.mdwn", "t/tmp/in", "e");
47 writefile("self_referential.mdwn", "t/tmp/in", '[[!trailitems pagenames="self_referential" circular=yes]]');
48 writefile("sorting/linked.mdwn", "t/tmp/in", "linked");
49 writefile("sorting/a/b.mdwn", "t/tmp/in", "a/b");
50 writefile("sorting/a/c.mdwn", "t/tmp/in", "a/c");
51 writefile("sorting/z/a.mdwn", "t/tmp/in", "z/a");
52 writefile("sorting/beginning.mdwn", "t/tmp/in", "beginning");
53 writefile("sorting/middle.mdwn", "t/tmp/in", "middle");
54 writefile("sorting/end.mdwn", "t/tmp/in", "end");
55 writefile("sorting/new.mdwn", "t/tmp/in", "new");
56 writefile("sorting/old.mdwn", "t/tmp/in", "old");
57 writefile("sorting/ancient.mdwn", "t/tmp/in", "ancient");
58 # These three need to be in the appropriate age order
59 ok(utime(333333333, 333333333, "t/tmp/in/sorting/new.mdwn"));
60 ok(utime(222222222, 222222222, "t/tmp/in/sorting/old.mdwn"));
61 ok(utime(111111111, 111111111, "t/tmp/in/sorting/ancient.mdwn"));
62 writefile("sorting/linked2.mdwn", "t/tmp/in", "linked2");
63 # This initially uses the default sort order: age for trailinline, and path
64 # for trail. We change it later.
65 writefile("sorting.mdwn", "t/tmp/in",
66 '[[!traillink linked]] ' .
67 '[[!trailitems pages="sorting/z/a or sorting/a/b or sorting/a/c"]] ' .
68 '[[!trailitems pagenames="beginning middle end"]] ' .
69 '[[!trailinline pages="sorting/old or sorting/ancient or sorting/new"]] ' .
70 '[[!traillink linked2]]');
72 writefile("meme.mdwn", "t/tmp/in", <<EOF
74 * [[!traillink badger]]
75 * [[!traillink badger text="This is a link to badger, with a title"]]
76 * [[!traillink That_is_the_badger|badger]]
77 * [[!traillink badger]]
78 * [[!traillink mushroom]]
79 * [[!traillink mushroom]]
80 * [[!traillink snake]]
81 * [[!traillink snake]]
85 writefile("wind_in_the_willows.mdwn", "t/tmp/in", <<EOF
86 [[!trailoptions circular=yes sort=title]]
87 [[!trailitems pages="ratty or badger or mr_toad"]]
92 ok(! system("make -s ikiwiki.out"));
94 my $command = "perl -I. ./ikiwiki.out -set usedirs=0 -plugin trail -plugin inline -url=http://example.com -cgiurl=http://example.com/ikiwiki.cgi -rss -atom -underlaydir=underlays/basewiki -set underlaydirbase=underlays -templatedir=templates t/tmp/in t/tmp/out -verbose";
96 ok(! system($command));
98 ok(! system("$command -refresh"));
100 $blob = readfile("t/tmp/out/meme.html");
101 ok($blob =~ /<a href="(\.\/)?badger.html">badger<\/a>/m);
102 ok($blob =~ /<a href="(\.\/)?badger.html">This is a link to badger, with a title<\/a>/m);
103 ok($blob =~ /<a href="(\.\/)?badger.html">That is the badger<\/a>/m);
105 $blob = readfile("t/tmp/out/badger.html");
106 ok($blob =~ /^trail=meme n=mushroom p=$/m);
107 ok($blob =~ /^trail=wind_in_the_willows n=mr_toad p=ratty$/m);
109 ok(! -f "t/tmp/out/moley.html");
111 $blob = readfile("t/tmp/out/mr_toad.html");
112 ok($blob !~ /^trail=meme/m);
113 ok($blob =~ /^trail=wind_in_the_willows n=ratty p=badger$/m);
114 # meta title is respected for pages that have one
115 ok($blob =~ /">< The Breezy Badger<\/a>/m);
116 # pagetitle for pages that don't
117 ok($blob =~ /">ratty ><\/a>/m);
119 $blob = readfile("t/tmp/out/ratty.html");
120 ok($blob !~ /^trail=meme/m);
121 ok($blob =~ /^trail=wind_in_the_willows n=badger p=mr_toad$/m);
123 $blob = readfile("t/tmp/out/mushroom.html");
124 ok($blob =~ /^trail=meme n=snake p=badger$/m);
125 ok($blob !~ /^trail=wind_in_the_willows/m);
127 $blob = readfile("t/tmp/out/snake.html");
128 ok($blob =~ /^trail=meme n= p=mushroom$/m);
129 ok($blob !~ /^trail=wind_in_the_willows/m);
131 $blob = readfile("t/tmp/out/self_referential.html");
132 ok($blob =~ /^trail=self_referential n= p=$/m);
134 $blob = readfile("t/tmp/out/add/b.html");
135 ok($blob =~ /^trail=add n=add\/d p=$/m);
136 $blob = readfile("t/tmp/out/add/d.html");
137 ok($blob =~ /^trail=add n= p=add\/b$/m);
138 ok(! -f "t/tmp/out/add/a.html");
139 ok(! -f "t/tmp/out/add/c.html");
140 ok(! -f "t/tmp/out/add/e.html");
142 $blob = readfile("t/tmp/out/del/a.html");
143 ok($blob =~ /^trail=del n=del\/b p=$/m);
144 $blob = readfile("t/tmp/out/del/b.html");
145 ok($blob =~ /^trail=del n=del\/c p=del\/a$/m);
146 $blob = readfile("t/tmp/out/del/c.html");
147 ok($blob =~ /^trail=del n=del\/d p=del\/b$/m);
148 $blob = readfile("t/tmp/out/del/d.html");
149 ok($blob =~ /^trail=del n=del\/e p=del\/c$/m);
150 $blob = readfile("t/tmp/out/del/e.html");
151 ok($blob =~ /^trail=del n= p=del\/d$/m);
153 $blob = readfile("t/tmp/out/sorting/linked.html");
154 ok($blob =~ m{^trail=sorting n=sorting/a/b p=$}m);
155 $blob = readfile("t/tmp/out/sorting/a/b.html");
156 ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m);
157 $blob = readfile("t/tmp/out/sorting/a/c.html");
158 ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m);
159 $blob = readfile("t/tmp/out/sorting/z/a.html");
160 ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/a/c$}m);
161 $blob = readfile("t/tmp/out/sorting/beginning.html");
162 ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/z/a$}m);
163 $blob = readfile("t/tmp/out/sorting/middle.html");
164 ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/beginning$}m);
165 $blob = readfile("t/tmp/out/sorting/end.html");
166 ok($blob =~ m{^trail=sorting n=sorting/new p=sorting/middle$}m);
167 $blob = readfile("t/tmp/out/sorting/new.html");
168 ok($blob =~ m{^trail=sorting n=sorting/old p=sorting/end$}m);
169 $blob = readfile("t/tmp/out/sorting/old.html");
170 ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/new$}m);
171 $blob = readfile("t/tmp/out/sorting/ancient.html");
172 ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/old$}m);
173 $blob = readfile("t/tmp/out/sorting/linked2.html");
174 ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m);
176 # Make some changes and refresh
178 writefile("add/a.mdwn", "t/tmp/in", "a");
179 writefile("add/c.mdwn", "t/tmp/in", "c");
180 writefile("add/e.mdwn", "t/tmp/in", "e");
181 ok(unlink("t/tmp/in/del/a.mdwn"));
182 ok(unlink("t/tmp/in/del/c.mdwn"));
183 ok(unlink("t/tmp/in/del/e.mdwn"));
185 writefile("sorting.mdwn", "t/tmp/in",
186 readfile("t/tmp/in/sorting.mdwn") .
187 '[[!trailoptions sort="title" reverse="yes"]]');
189 ok(! system("$command -refresh"));
191 $blob = readfile("t/tmp/out/add/a.html");
192 ok($blob =~ /^trail=add n=add\/b p=$/m);
193 $blob = readfile("t/tmp/out/add/b.html");
194 ok($blob =~ /^trail=add n=add\/c p=add\/a$/m);
195 $blob = readfile("t/tmp/out/add/c.html");
196 ok($blob =~ /^trail=add n=add\/d p=add\/b$/m);
197 $blob = readfile("t/tmp/out/add/d.html");
198 ok($blob =~ /^trail=add n=add\/e p=add\/c$/m);
199 $blob = readfile("t/tmp/out/add/e.html");
200 ok($blob =~ /^trail=add n= p=add\/d$/m);
202 $blob = readfile("t/tmp/out/del/b.html");
203 ok($blob =~ /^trail=del n=del\/d p=$/m);
204 $blob = readfile("t/tmp/out/del/d.html");
205 ok($blob =~ /^trail=del n= p=del\/b$/m);
206 ok(! -f "t/tmp/out/del/a.html");
207 ok(! -f "t/tmp/out/del/c.html");
208 ok(! -f "t/tmp/out/del/e.html");
210 $blob = readfile("t/tmp/out/sorting/old.html");
211 ok($blob =~ m{^trail=sorting n=sorting/new p=$}m);
212 $blob = readfile("t/tmp/out/sorting/new.html");
213 ok($blob =~ m{^trail=sorting n=sorting/middle p=sorting/old$}m);
214 $blob = readfile("t/tmp/out/sorting/middle.html");
215 ok($blob =~ m{^trail=sorting n=sorting/linked2 p=sorting/new$}m);
216 $blob = readfile("t/tmp/out/sorting/linked2.html");
217 ok($blob =~ m{^trail=sorting n=sorting/linked p=sorting/middle$}m);
218 $blob = readfile("t/tmp/out/sorting/linked.html");
219 ok($blob =~ m{^trail=sorting n=sorting/end p=sorting/linked2$}m);
220 $blob = readfile("t/tmp/out/sorting/end.html");
221 ok($blob =~ m{^trail=sorting n=sorting/a/c p=sorting/linked$}m);
222 $blob = readfile("t/tmp/out/sorting/a/c.html");
223 ok($blob =~ m{^trail=sorting n=sorting/beginning p=sorting/end$}m);
224 $blob = readfile("t/tmp/out/sorting/beginning.html");
225 ok($blob =~ m{^trail=sorting n=sorting/a/b p=sorting/a/c$}m);
226 $blob = readfile("t/tmp/out/sorting/a/b.html");
227 ok($blob =~ m{^trail=sorting n=sorting/ancient p=sorting/beginning$}m);
228 $blob = readfile("t/tmp/out/sorting/ancient.html");
229 ok($blob =~ m{^trail=sorting n=sorting/z/a p=sorting/a/b$}m);
230 $blob = readfile("t/tmp/out/sorting/z/a.html");
231 ok($blob =~ m{^trail=sorting n= p=sorting/ancient$}m);
233 ok(! system("rm -rf t/tmp"));